Class: CamaleonCms::User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CustomFieldsRead, Metas
Defined in:
app/models/camaleon_cms/user.rb

Constant Summary collapse

STATUS =

vars

{0 => 'Active', 1=>'Not Active'}
ROLE =
{ 'admin'=>'Administrator', 'client' => 'Client'}

Instance Method Summary collapse

Methods included from CustomFieldsRead

#add_custom_field_group, #add_custom_field_to_default_group, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_grouped, #get_fields_object, #get_user_field_groups, #save_field_value, #set_field_value, #set_field_values, #update_field_value

Methods included from Metas

#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_multiple_options, #set_option

Instance Method Details

#_idObject



59
60
61
# File 'app/models/camaleon_cms/user.rb', line 59

def _id
  "#{self.role.upcase}-#{self.id}"
end

#admin?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/camaleon_cms/user.rb', line 67

def admin?
  role == 'admin'
end

#assign_site(site) ⇒ Object



80
81
82
# File 'app/models/camaleon_cms/user.rb', line 80

def assign_site(site)
  self.user_relationships.where(term_taxonomy_id: site.id).first_or_create
end

#client?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/camaleon_cms/user.rb', line 71

def client?
  self.role == 'client'
end

#createdObject



88
89
90
# File 'app/models/camaleon_cms/user.rb', line 88

def created
  self.created_at.strftime('%d/%m/%Y %H:%M')
end

#fullnameObject



63
64
65
# File 'app/models/camaleon_cms/user.rb', line 63

def fullname
  "#{self.first_name} #{self.last_name}".titleize
end

#generate_token(column) ⇒ Object

auth



97
98
99
100
101
# File 'app/models/camaleon_cms/user.rb', line 97

def generate_token(column)
  begin
    self[column] = SecureRandom.urlsafe_base64
  end while CamaleonCms::User.exists?(column => self[column])
end

#get_role(site) ⇒ Object

return the UserRole Object of this user in Site



76
77
78
# File 'app/models/camaleon_cms/user.rb', line 76

def get_role(site)
  @_user_role ||= site.user_roles.where(slug: self.role).first
end

#posts(site) ⇒ Object

return all posts of this user on site



55
56
57
# File 'app/models/camaleon_cms/user.rb', line 55

def posts(site)
  site.posts.where(user_id: self.id)
end

#roleTextObject



84
85
86
# File 'app/models/camaleon_cms/user.rb', line 84

def roleText
  User::ROLE[self.role]
end

#send_confirm_emailObject



109
110
111
112
113
# File 'app/models/camaleon_cms/user.rb', line 109

def send_confirm_email
  generate_token(:confirm_email_token)
  self.confirm_email_sent_at = Time.zone.now
  save!
end

#send_password_resetObject



103
104
105
106
107
# File 'app/models/camaleon_cms/user.rb', line 103

def send_password_reset
  generate_token(:password_reset_token)
  self.password_reset_sent_at = Time.zone.now
  save!
end

#updatedObject



92
93
94
# File 'app/models/camaleon_cms/user.rb', line 92

def updated
  self.updated_at.strftime('%d/%m/%Y %H:%M')
end