Module: CamaleonCms::UserMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- app/models/concerns/camaleon_cms/user_methods.rb
Instance Method Summary collapse
- #admin? ⇒ Boolean
-
#assign_site(site) ⇒ Object
Assign a new site for the current user.
-
#cama_reset_auth_token! ⇒ Object
Rotate the auth token and persist it (audit 2026-08-11 M3): called on logout so a cookie copied before logout can no longer authenticate.
- #client? ⇒ Boolean
- #created ⇒ Object
- #fullname ⇒ Object
-
#generate_token(column) ⇒ Object
auth.
-
#get_role(site) ⇒ Object
return the UserRole Object of this user in Site.
-
#posts(site) ⇒ Object
return all posts of this user on site.
- #send_confirm_email ⇒ Object
- #send_password_reset ⇒ Object
- #sites ⇒ Object
- #updated ⇒ Object
Instance Method Details
#admin? ⇒ Boolean
66 67 68 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 66 def admin? role == 'admin' end |
#assign_site(site) ⇒ Object
Assign a new site for the current user
80 81 82 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 80 def assign_site(site) update_column(:site_id, site.id) # rubocop:disable Rails/SkipsModelValidations end |
#cama_reset_auth_token! ⇒ Object
Rotate the auth token and persist it (audit 2026-08-11 M3): called on logout so a cookie copied before logout can no longer authenticate. Skips validations/callbacks -- it only replaces the token column and must work even for a record that would not otherwise pass validation.
111 112 113 114 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 111 def cama_reset_auth_token! generate_token(:auth_token) update_column(:auth_token, auth_token) # rubocop:disable Rails/SkipsModelValidations end |
#client? ⇒ Boolean
70 71 72 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 70 def client? role == 'client' end |
#created ⇒ Object
92 93 94 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 92 def created created_at.strftime('%d/%m/%Y %H:%M') end |
#fullname ⇒ Object
62 63 64 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 62 def fullname "#{first_name} #{last_name}".titleize end |
#generate_token(column) ⇒ Object
auth
101 102 103 104 105 106 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 101 def generate_token(column) loop do self[column] = SecureRandom.urlsafe_base64 break unless CamaleonCms::User.unscoped.exists?(column => self[column]) end end |
#get_role(site) ⇒ Object
return the UserRole Object of this user in Site
75 76 77 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 75 def get_role(site) @_user_role ||= site.user_roles.where(slug: role).first end |
#posts(site) ⇒ Object
return all posts of this user on site
58 59 60 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 58 def posts(site) site.posts.where(user_id: id) end |
#send_confirm_email ⇒ Object
122 123 124 125 126 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 122 def send_confirm_email generate_token(:confirm_email_token) self.confirm_email_sent_at = Time.zone.now save! end |
#send_password_reset ⇒ Object
116 117 118 119 120 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 116 def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! end |
#sites ⇒ Object
84 85 86 87 88 89 90 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 84 def sites if PluginRoutes.system_info['users_share_sites'] CamaleonCms::Site.all else CamaleonCms::Site.where(id: site_id) end end |
#updated ⇒ Object
96 97 98 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 96 def updated updated_at.strftime('%d/%m/%Y %H:%M') end |