Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
- 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)
-
- (Object) password
Returns the value of attribute password.
-
- (Object) password_confirmation
Returns the value of attribute password_confirmation.
Class Method Summary (collapse)
-
+ (Object) authenticate(email, password)
This method is for authentication purpose.
-
+ (Object) find_by_id(id)
This method is used by AuthenticationHelper.
- + (Object) find_by_persistence_token(value)
-
+ (Object) find_by_smart_case_login_field(value)
Breaks .create() def self.primary_key.
- + (Object) forget_all!
-
+ (Object) login_field
Other authlogic configuration.
Instance Method Summary (collapse)
-
- (Object) display_name
These methods are for ActiveRecord compatibility to make the authlogic gem work.
- - (Object) has_role!(role_name, obj = nil)
-
- (Boolean) has_role?(role_name, obj = nil)
For acl9 authorization.
- - (Object) reset_persistence_token
- - (Object) reset_persistence_token!
- - (Boolean) valid_password?(password)
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) account = self.where(:email => email).first if email.present? account && account.has_password?(password) ? account : 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.find_by_smart_case_login_field(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.login_field :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
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)
46 47 48 |
# File 'app/models/account.rb', line 46 def valid_password?(password) ::BCrypt::Password.new(crypted_password) == password end |