Class: ProxES::Identity

Inherits:
Base
  • Object
show all
Includes:
OmniAuth::Identity::Model
Defined in:
lib/proxes/models/identity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



12
13
14
# File 'lib/proxes/models/identity.rb', line 12

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



12
13
14
# File 'lib/proxes/models/identity.rb', line 12

def password_confirmation
  @password_confirmation
end

Class Method Details

.locate(conditions) ⇒ Object



17
18
19
# File 'lib/proxes/models/identity.rb', line 17

def self.locate(conditions)
  where(conditions).first
end

Instance Method Details

#authenticate(unencrypted) ⇒ Object



21
22
23
# File 'lib/proxes/models/identity.rb', line 21

def authenticate(unencrypted)
  self if ::BCrypt::Password.new(crypted_password) == unencrypted
end

#before_saveObject

Callbacks



54
55
56
# File 'lib/proxes/models/identity.rb', line 54

def before_save
  encrypt_password unless password == '' || password.nil?
end

#infoObject

Return whatever we want to pass to the omniauth hash here



30
31
32
33
34
# File 'lib/proxes/models/identity.rb', line 30

def info
  {
    email: username
  }
end

#persisted?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/proxes/models/identity.rb', line 25

def persisted?
  !new? && @destroyed != true
end

#validateObject

Validation



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/proxes/models/identity.rb', line 37

def validate
  validates_presence :username
  unless username.blank?
    validates_unique :username
    validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :username)
  end

  if password_required
    validates_presence :password
    validates_presence :password_confirmation
    validates_min_length 8, :password
  end

  errors.add(:password_confirmation, 'must match password') if !password.blank? && password != password_confirmation
end