Class: EdgeAuth::Identity

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::EdgeStateMachine, Mongoid::Timestamps
Defined in:
app/models/edge_auth/identity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



22
23
24
# File 'app/models/edge_auth/identity.rb', line 22

def password
  @password
end

#updating_passwordObject

Returns the value of attribute updating_password.



22
23
24
# File 'app/models/edge_auth/identity.rb', line 22

def updating_password
  @updating_password
end

Class Method Details

.authenticate(email, submitted_password) ⇒ Object



56
57
58
59
60
# File 'app/models/edge_auth/identity.rb', line 56

def self.authenticate(email, )
  user = Identity.first(conditions: {email: email})
  return nil  if user.nil? or user.state == "blocked"
  return user if user.has_password?()
end

.authenticate_with_salt(id, cookie_salt) ⇒ Object



62
63
64
65
66
# File 'app/models/edge_auth/identity.rb', line 62

def self.authenticate_with_salt(id, cookie_salt)
  return nil if id.nil?
  user = Identity.first(conditions: {_id: id})
  (user && user.salt == cookie_salt) ? user : nil
end

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'app/models/edge_auth/identity.rb', line 68

def activated?
  if self.activated_at == nil
    return false
  end
  return true
end

#do_activateObject



87
88
89
90
# File 'app/models/edge_auth/identity.rb', line 87

def do_activate
  self.activated_at = Time.now.utc
  self.save!
end

#has_password?(submitted_password) ⇒ Boolean

Return true if the user’s password matches the submitted password.

Returns:

  • (Boolean)


52
53
54
# File 'app/models/edge_auth/identity.rb', line 52

def has_password?()
  encrypted_password == encrypt()
end

#reset_passwordObject



79
80
81
82
83
84
85
# File 'app/models/edge_auth/identity.rb', line 79

def reset_password
  self.password_reset_code = generate_token
  self.reset_password_mail_sent_at = Time.now.utc
  self.save!(validate: false)
  # we send the reset password mail
  #UserMailer.reset_password(self).deliver
end

#reset_password_expired?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/edge_auth/identity.rb', line 75

def reset_password_expired?
  return self.reset_password_mail_sent_at < 1.day.ago
end