Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/generators/frame/omniauth/templates/app/models/user.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_omniauth(omniauth) ⇒ Object
- #derive_username ⇒ Object
- #password_required? ⇒ Boolean
- #update_with_password(params = {}) ⇒ Object
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
11 12 13 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 11 def login @login end |
Class Method Details
.find_for_authentication(warden_conditions) ⇒ Object
14 15 16 17 18 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 14 def self.find_for_authentication(warden_conditions) conditions = warden_conditions.dup login = conditions.delete(:login) where(conditions).where(["lower(username) = :value OR lower(email) = :value", {:value => login.downcase}]).first end |
Instance Method Details
#apply_omniauth(omniauth) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 28 def apply_omniauth(omniauth) if (omniauth['info'] && omniauth['info']['email']) self.email = omniauth['info']['email'] if email.blank? end if (omniauth['info'] && omniauth['info']['nickname']) self.username = omniauth['info']['nickname'] if username.blank? else self.username = derive_username if username.blank? end authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid']) end |
#derive_username ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 40 def derive_username split_email = self.email.split(/@/) username_taken = User.where(:username => split_email[0]).first unless username_taken split_email[0] else nil end end |
#password_required? ⇒ Boolean
50 51 52 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 50 def password_required? (authentications.empty? || !password.blank?) && super end |
#update_with_password(params = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 20 def update_with_password(params={}) if params[:password].blank? params.delete(:password) params.delete(:password_confirmation) if params[:password_confirmation].blank? end update_attributes(params) end |