Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
show all
- Includes:
- ActiveUUID::UUID
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#fix_uuid_strings, included
Instance Attribute Details
#account_alias ⇒ Object
Returns the value of attribute account_alias.
25
26
27
|
# File 'app/models/user.rb', line 25
def account_alias
@account_alias
end
|
#account_name ⇒ Object
Returns the value of attribute account_name.
25
26
27
|
# File 'app/models/user.rb', line 25
def account_name
@account_name
end
|
#currency ⇒ Object
Returns the value of attribute currency.
25
26
27
|
# File 'app/models/user.rb', line 25
def currency
@currency
end
|
#plan_identifier ⇒ Object
Returns the value of attribute plan_identifier.
25
26
27
|
# File 'app/models/user.rb', line 25
def plan_identifier
@plan_identifier
end
|
#user_invitation ⇒ Object
Returns the value of attribute user_invitation.
25
26
27
|
# File 'app/models/user.rb', line 25
def user_invitation
@user_invitation
end
|
Class Method Details
.create_guest(locale = "en") ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/models/user.rb', line 76
def self.create_guest(locale = "en")
user = User.new({
:guest => true,
:name => "Guest",
:locale => locale
})
user.skip_confirmation!
user.save(:validate => false)
Delayed::Job.enqueue DestroyUserJob.new(user.id.to_s), :queue => "guest_#{user.id}_destroy", :run_at => DateTime.now + IuguSDK::destroy_guest_in
user
end
|
.find_or_create_by_social(auth) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/models/user.rb', line 90
def self.find_or_create_by_social(auth)
social_account = SocialAccount.where("provider = ? AND social_id = ?", auth["provider"], auth["uid"]).first
unless user = social_account.try(:user)
user = User.new
if auth["extra"]["raw_info"]["email"]
return false if !User.where(:email => auth["extra"]["raw_info"]["email"]).empty?
user.email = auth["extra"]["raw_info"]["email"]
end
user.birthdate = Date.strptime(auth["extra"]["raw_info"]["birthday"], '%m/%d/%Y') if auth["extra"]["raw_info"]["birthday"]
user.locale = AvailableLanguage.best_locale_for(auth["extra"]["raw_info"]["locale"]) if auth["extra"]["raw_info"]["locale"]
user.locale = AvailableLanguage.best_locale_for(auth["extra"]["raw_info"]["lang"]) if auth["extra"]["raw_info"]["lang"]
user.skip_confirmation!
user.save(:validate => false)
social_account = user.create_social(auth)
end
social_account.update_attribute( 'token' , auth['credentials']['token'] )
user
end
|
Instance Method Details
#_destroy ⇒ Object
14
|
# File 'app/models/user.rb', line 14
alias :_destroy :destroy
|
#accountable? ⇒ Boolean
122
123
124
|
# File 'app/models/user.rb', line 122
def accountable?
!!!@skip_account_creation
end
|
#as_json(options = nil) ⇒ Object
153
154
155
156
157
158
159
160
|
# File 'app/models/user.rb', line 153
def as_json(options = nil)
{
id: id,
email: email,
locale: locale,
access_token: token.token
}
end
|
#become_user(data) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'app/models/user.rb', line 135
def become_user(data)
if self.guest
self.guest = false
self.email = data[:email]
self.password = data[:password]
self.password_confirmation = data[:password_confirmation]
if self.save
Delayed::Job.find_by_queue("guest_#{id}_destroy").destroy
self
else
self.guest = true
false
end
else
false
end
end
|
#cancel_destruction ⇒ Object
60
61
62
|
# File 'app/models/user.rb', line 60
def cancel_destruction
destruction_job.try(:destroy) unless destruction_job.try(:locked_at)
end
|
#create_social(auth) ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'app/models/user.rb', line 109
def create_social(auth)
social_accounts.create! do |social_account|
social_account.provider = auth["provider"]
social_account.social_id = auth["uid"]
social_account.token = auth["credentials"]["token"]
social_account.user_id = self.id
end
end
|
#default_account(account_id = nil) ⇒ Object
130
131
132
133
|
# File 'app/models/user.rb', line 130
def default_account( account_id=nil )
account_id = account_id.id if account_id.is_a? Account
self.accounts.where( [ "accounts.id = ?", account_id.try(:to_uuid)] ).first || self.accounts.first
end
|
#destroy ⇒ Object
15
16
17
|
# File 'app/models/user.rb', line 15
def destroy
Delayed::Job.enqueue DestroyUserJob.new(id.to_s), :queue => "user_#{id}_destroy", :run_at => DateTime.now + IuguSDK::delay_user_exclusion
end
|
#destroying? ⇒ Boolean
56
57
58
|
# File 'app/models/user.rb', line 56
def destroying?
!!destruction_job
end
|
#destruction_job ⇒ Object
52
53
54
|
# File 'app/models/user.rb', line 52
def destruction_job
Delayed::Job.find_by_queue("user_#{id}_destroy")
end
|
#devise_mailer ⇒ Object
118
119
120
|
# File 'app/models/user.rb', line 118
def devise_mailer
IuguMailer
end
|
#find_or_create_social(auth) ⇒ Object
72
73
74
|
# File 'app/models/user.rb', line 72
def find_or_create_social(auth)
social_accounts.where("provider = ? AND social_id = ?", auth["provider"], auth["uid"]).first || create_social(auth)
end
|
#has_social? ⇒ Boolean
68
69
70
|
# File 'app/models/user.rb', line 68
def has_social?
!social_accounts.empty?
end
|
#is?(role, account) ⇒ Boolean
64
65
66
|
# File 'app/models/user.rb', line 64
def is?(role, account)
account.account_users.find_by_user_id(self.id).is?(role.to_s)
end
|
#skip_create_account! ⇒ Object
126
127
128
|
# File 'app/models/user.rb', line 126
def skip_create_account!
@skip_account_creation = true
end
|