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.



19
20
21
# File 'app/models/edge_auth/identity.rb', line 19

def password
  @password
end

#updating_passwordObject

Returns the value of attribute updating_password.



19
20
21
# File 'app/models/edge_auth/identity.rb', line 19

def updating_password
  @updating_password
end

Class Method Details

.authenticate(email, submitted_password) ⇒ Object



53
54
55
56
57
# File 'app/models/edge_auth/identity.rb', line 53

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

.authenticate_with_salt(id, cookie_salt) ⇒ Object



59
60
61
62
63
# File 'app/models/edge_auth/identity.rb', line 59

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

Instance Method Details

#activated?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
# File 'app/models/edge_auth/identity.rb', line 65

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

#do_activateObject



84
85
86
87
# File 'app/models/edge_auth/identity.rb', line 84

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)


49
50
51
# File 'app/models/edge_auth/identity.rb', line 49

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

#reset_passwordObject



76
77
78
79
80
81
82
# File 'app/models/edge_auth/identity.rb', line 76

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)


72
73
74
# File 'app/models/edge_auth/identity.rb', line 72

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