Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AuthoredModel
Defined in:
app/models/account.rb

Overview

class to manage user accounts on CMS. Note that this class is different than the Person class, because not all people responsible for compliance will have an account.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) password

Returns the value of attribute password



6
7
8
# File 'app/models/account.rb', line 6

def password
  @password
end

- (Object) password_confirmation

Returns the value of attribute password_confirmation



6
7
8
# File 'app/models/account.rb', line 6

def password_confirmation
  @password_confirmation
end

Class Method Details

+ (Object) authenticate(email, password)

This method is for authentication purpose



34
35
36
37
# File 'app/models/account.rb', line 34

def self.authenticate(email, password)
   = self.where(:email => email).first if email.present?
   && .has_password?(password) ?  : nil
end

+ (Object) find_by_id(id)

This method is used by AuthenticationHelper



42
43
44
# File 'app/models/account.rb', line 42

def self.find_by_id(id)
  find(id) rescue nil
end

+ (Object) find_by_persistence_token(value)



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

def self.find_by_persistence_token(value)
  where(:persistence_token => value).first
end

+ (Object) find_by_smart_case_login_field(value)

Breaks .create() def self.primary_key :id end



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

def self.(value)
  self.where(:email => value).first
end

+ (Object) forget_all!



112
113
114
115
116
117
118
119
120
# File 'app/models/account.rb', line 112

def self.forget_all!
  records = nil
  i = 0
  begin
    records = self.limit(50).offset(i)
    records.each { |r| r.reset_persistence_token! }
    i += 50
  end while !records.blank?
end

+ (Object) login_field

Other authlogic configuration



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

def self.
  :email
end

Instance Method Details

- (Object) display_name

These methods are for ActiveRecord compatibility to make the authlogic gem work



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

def display_name
  email
end

- (Object) has_role!(role_name, obj = nil)



98
99
100
101
# File 'app/models/account.rb', line 98

def has_role!(role_name, obj=nil)
  self.role = role_name
  save!
end

- (Boolean) has_role?(role_name, obj = nil)

For acl9 authorization

Returns:

  • (Boolean)


94
95
96
# File 'app/models/account.rb', line 94

def has_role?(role_name, obj=nil)
  self.role == role_name.to_s
end

- (Object) reset_persistence_token



103
104
105
# File 'app/models/account.rb', line 103

def reset_persistence_token
  self.persistence_token = Authlogic::Random.hex_token
end

- (Object) reset_persistence_token!



107
108
109
110
# File 'app/models/account.rb', line 107

def reset_persistence_token!
  reset_persistence_token
  save!
end

- (Boolean) valid_password?(password)

Returns:

  • (Boolean)


46
47
48
# File 'app/models/account.rb', line 46

def valid_password?(password)
  ::BCrypt::Password.new(crypted_password) == password
end