Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- lib/generators/frame/omniauth/templates/app/models/user.rb,
lib/generators/frame/devise_omniauth/templates/app/models/user.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
Class Method Summary collapse
- .find_first_by_auth_conditions(warden_conditions) ⇒ Object
- .from_omniauth(auth) ⇒ Object
- .new_with_session(params, session) ⇒ Object
Instance Method Summary collapse
- #apply_omniauth(omniauth) ⇒ Object
- #derive_username ⇒ Object
- #password_required? ⇒ Boolean
- #update_with_password(params, *options) ⇒ Object
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
12 13 14 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 12 def login @login end |
Class Method Details
.find_first_by_auth_conditions(warden_conditions) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 15 def self.find_first_by_auth_conditions(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:login) where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first else where(conditions).first end end |
.from_omniauth(auth) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/generators/frame/devise_omniauth/templates/app/models/user.rb', line 10 def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_create do |user| user.provider = auth.provider user.uid = auth.uid user.username = auth.info.nickname end end |
.new_with_session(params, session) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/frame/devise_omniauth/templates/app/models/user.rb', line 18 def self.new_with_session(params, session) if session["devise.user_attributes"] new(session["devise.user_attributes"], without_protection: true) do |user| user.attributes = params user.valid? end else super end end |
Instance Method Details
#apply_omniauth(omniauth) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 32 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
44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 44 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
54 55 56 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 54 def password_required? (authentications.empty? || !password.blank?) && super end |
#update_with_password(params, *options) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 24 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 |