Class: Alchemy::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alchemy::User
- Includes:
- Taggable, UserMethods
- Defined in:
- app/models/alchemy/user.rb
Constant Summary collapse
- PERMITTED_ATTRIBUTES =
[ :firstname, :lastname, :login, :email, :language, :password, :password_confirmation, :send_credentials, :tag_list, :timezone ]
- ROLES =
Alchemy.config.user_roles
Instance Attribute Summary collapse
-
#send_credentials ⇒ Object
Returns the value of attribute send_credentials.
Class Method Summary collapse
- .logged_in_timeout ⇒ Object
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object (also: searchable_alchemy_resource_attributes)
- .ransortable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #add_role(role) ⇒ Object
-
#deliver_welcome_mail ⇒ Object
Delivers a welcome mail depending from user's role.
- #email_required? ⇒ Boolean
-
#fullname(options = {}) ⇒ Object
(also: #name, #alchemy_display_name)
Returns the firstname and lastname as a string.
-
#logged_in? ⇒ Boolean
Returns true if the last request not longer ago then the logged_in_time_out.
-
#logged_out? ⇒ Boolean
Opposite of logged_in?.
- #login_required? ⇒ Boolean
- #role ⇒ Object
- #role_symbols ⇒ Object
- #store_request_time! ⇒ Object
Instance Attribute Details
#send_credentials ⇒ Object
Returns the value of attribute send_credentials.
26 27 28 |
# File 'app/models/alchemy/user.rb', line 26 def send_credentials @send_credentials end |
Class Method Details
.logged_in_timeout ⇒ Object
68 69 70 |
# File 'app/models/alchemy/user.rb', line 68 def logged_in_timeout Alchemy.config.get(:auto_logout_time).minutes.to_i end |
.ransackable_associations(_auth_object = nil) ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/alchemy/user.rb', line 58 def ransackable_associations(_auth_object = nil) %w[ taggings tags ] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object Also known as: searchable_alchemy_resource_attributes
43 44 45 46 47 48 49 50 |
# File 'app/models/alchemy/user.rb', line 43 def ransackable_attributes(_auth_object = nil) %w[ email firstname lastname login ] end |
.ransortable_attributes(_auth_object = nil) ⇒ Object
52 53 54 |
# File 'app/models/alchemy/user.rb', line 52 def ransortable_attributes(_auth_object = nil) %w[last_sign_in_at] end |
Instance Method Details
#add_role(role) ⇒ Object
83 84 85 |
# File 'app/models/alchemy/user.rb', line 83 def add_role(role) self.alchemy_roles = alchemy_roles.push(role.to_s).uniq end |
#deliver_welcome_mail ⇒ Object
Delivers a welcome mail depending from user's role.
145 146 147 148 149 150 151 |
# File 'app/models/alchemy/user.rb', line 145 def deliver_welcome_mail if has_alchemy_role?("author") || has_alchemy_role?("editor") || has_alchemy_role?("admin") Notifications.alchemy_user_created(self).deliver_later else Notifications.member_created(self).deliver_later end end |
#email_required? ⇒ Boolean
117 118 119 |
# File 'app/models/alchemy/user.rb', line 117 def email_required? ::Devise.authentication_keys.include?(:email) end |
#fullname(options = {}) ⇒ Object Also known as: name, alchemy_display_name
Returns the firstname and lastname as a string
If both are blank, returns the login
104 105 106 107 108 109 110 111 112 |
# File 'app/models/alchemy/user.rb', line 104 def fullname( = {}) if lastname.blank? && firstname.blank? login else = {flipped: false}.merge() fullname = [:flipped] ? "#{lastname}, #{firstname}" : "#{firstname} #{lastname}" fullname.squeeze(" ").strip end end |
#logged_in? ⇒ Boolean
Returns true if the last request not longer ago then the logged_in_time_out
126 127 128 129 |
# File 'app/models/alchemy/user.rb', line 126 def logged_in? raise "Can not determine the records login state because there is no last_request_at column" if !respond_to?(:last_request_at) !last_request_at.nil? && last_request_at > logged_in_timeout.seconds.ago end |
#logged_out? ⇒ Boolean
Opposite of logged_in?
132 133 134 |
# File 'app/models/alchemy/user.rb', line 132 def logged_out? !logged_in? end |
#login_required? ⇒ Boolean
121 122 123 |
# File 'app/models/alchemy/user.rb', line 121 def login_required? ::Devise.authentication_keys.include?(:login) end |
#role ⇒ Object
78 79 80 |
# File 'app/models/alchemy/user.rb', line 78 def role alchemy_roles.first end |
#role_symbols ⇒ Object
73 74 75 |
# File 'app/models/alchemy/user.rb', line 73 def role_symbols alchemy_roles.map(&:to_sym) end |
#store_request_time! ⇒ Object
139 140 141 |
# File 'app/models/alchemy/user.rb', line 139 def store_request_time! update_column(:last_request_at, Time.now) end |