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!, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_object, #get_user_field_groups, #save_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_multiple_options, #set_option

Instance Method Details

#_idObject


61
62
63
# File 'app/models/camaleon_cms/user.rb', line 61

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

#admin?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'app/models/camaleon_cms/user.rb', line 69

def admin?
  role == 'admin'
end

#assign_site(site) ⇒ Object


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

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

#client?Boolean

Returns:

  • (Boolean)

73
74
75
# File 'app/models/camaleon_cms/user.rb', line 73

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

#createdObject


95
96
97
# File 'app/models/camaleon_cms/user.rb', line 95

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

#fullnameObject


65
66
67
# File 'app/models/camaleon_cms/user.rb', line 65

def fullname
  get_meta("first_name").blank? ? self.username.titleize : "#{get_meta("first_name")} #{get_meta("last_name")}".titleize
end

#generate_token(column) ⇒ Object

auth


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

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

#get_role(site) ⇒ Object


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

def get_role(site)
  site.user_roles.where(slug: self.role).first
end

#posts(site) ⇒ Object

return all posts of this user on site


57
58
59
# File 'app/models/camaleon_cms/user.rb', line 57

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

#roleTextObject


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

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

#send_confirm_emailObject


116
117
118
119
120
# File 'app/models/camaleon_cms/user.rb', line 116

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

#send_password_resetObject


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

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

#set_meta_from_form(metas) ⇒ Object


81
82
83
84
85
# File 'app/models/camaleon_cms/user.rb', line 81

def set_meta_from_form(metas)
  metas.each do |key, value|
    self.metas.where({key: key}).update_or_create({value: value})
  end
end

#updatedObject


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

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