Class: Opensteam::UserBase::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Opensteam::UserBase::User
show all
- Includes:
- Authentication, Authentication::ByCookieToken, Authentication::ByPassword
- Defined in:
- lib/opensteam/user_base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/opensteam/user_base.rb', line 149
def method_missing(method, *args, &block)
if method.to_s =~/^is\_(.+)\?$/
return self.profile.name.classify.to_sym == $1.classify.to_sym
end
super
end
|
Class Method Details
.authenticate(email, password) ⇒ Object
116
117
118
119
|
# File 'lib/opensteam/user_base.rb', line 116
def authenticate(email, password)
u = find_by_email(email)
u && u.authenticated?(password) ? u : nil
end
|
.delete_by_profile(profile_name) ⇒ Object
111
112
113
|
# File 'lib/opensteam/user_base.rb', line 111
def delete_by_profile profile_name
delete( find(:all, :conditions => { "profiles.name" => profile_name }, :include => :profile ).collect(&:id) )
end
|
.new_or_existing_guest(attr = {}) ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/opensteam/user_base.rb', line 99
def new_or_existing_guest( attr = {} )
attr.symbolize_keys!
attr[:firstname] = attr[:lastname] = "guest"
attr[:password] = attr[:password_confirmation] = "opensteam"
returning( find_by_email( attr[:email] ) || new( attr ) ) do |guest|
guest.profile = Profile.find_or_create_by_name( :name => "Guest" )
end
end
|
Instance Method Details
#full_name ⇒ Object
Also known as:
to_s
158
|
# File 'lib/opensteam/user_base.rb', line 158
def full_name ; [ firstname, lastname ] * " " ; end
|
#old_password ⇒ Object
156
|
# File 'lib/opensteam/user_base.rb', line 156
def old_password ; nil ; end
|
#set_customer_profile ⇒ Object
136
137
138
139
140
|
# File 'lib/opensteam/user_base.rb', line 136
def set_customer_profile
unless self.profile
self.profile = Profile.find_or_create_by_name(:name => "Customer" )
end
end
|
#set_profile(p, autosave = false) ⇒ Object
143
144
145
146
|
# File 'lib/opensteam/user_base.rb', line 143
def set_profile( p, autosave = false )
self.profile = Profile.find_or_create_by_name( :name => p.to_s.classify )
self.save if autosave
end
|