Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/frame/omniauth/templates/app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loginObject

Returns the value of attribute login.



11
12
13
# File 'lib/generators/frame/omniauth/templates/app/models/user.rb', line 11

def 
  @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
   = conditions.delete(:login)
  where(conditions).where(["lower(username) = :value OR lower(email) = :value", {:value => .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_usernameObject



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

Returns:

  • (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