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 current user.
- #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
50 51 52 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 50 def admin? role == 'admin' end |
#assign_site(site) ⇒ Object
assign a new site for current user
64 65 66 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 64 def assign_site(site) update_column(:site_id, site.id) end |
#client? ⇒ Boolean
54 55 56 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 54 def client? role == 'client' end |
#created ⇒ Object
76 77 78 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 76 def created created_at.strftime('%d/%m/%Y %H:%M') end |
#fullname ⇒ Object
46 47 48 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 46 def fullname "#{first_name} #{last_name}".titleize end |
#generate_token(column) ⇒ Object
auth
85 86 87 88 89 90 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 85 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
59 60 61 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 59 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
42 43 44 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 42 def posts(site) site.posts.where(user_id: id) end |
#send_confirm_email ⇒ Object
98 99 100 101 102 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 98 def send_confirm_email generate_token(:confirm_email_token) self.confirm_email_sent_at = Time.zone.now save! end |
#send_password_reset ⇒ Object
92 93 94 95 96 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 92 def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! end |
#sites ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 68 def sites if PluginRoutes.system_info['users_share_sites'] CamaleonCms::Site.all else CamaleonCms::Site.where(id: site_id) end end |
#updated ⇒ Object
80 81 82 |
# File 'app/models/concerns/camaleon_cms/user_methods.rb', line 80 def updated updated_at.strftime('%d/%m/%Y %H:%M') end |