Class: Concen::User

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/concen/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_passwordObject (readonly)

Returns the value of attribute current_password.



21
22
23
# File 'app/models/concen/user.rb', line 21

def current_password
  @current_password
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'app/models/concen/user.rb', line 21

def password
  @password
end

Class Method Details

.send_invitation(email) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/concen/user.rb', line 61

def self.send_invitation(email)
  password = SecureRandom.hex(4)
  username = "user#{SecureRandom.hex(4)}"
  new_user = self.new(
    :full_name => username,
    :username => username,
    :email => email,
    :password => password,
    :password_confirmation => password
  )
  new_user.generate_token(:invitation_token)
  new_user.invitation_sent_at = Time.now
  new_user.save
  # Send email here.
end

Instance Method Details

#authenticate(unencrypted_password) ⇒ Object



38
39
40
41
42
43
44
# File 'app/models/concen/user.rb', line 38

def authenticate(unencrypted_password)
  if BCrypt::Password.new(self.password_digest) == unencrypted_password
    self
  else
    false
  end
end

#generate_token(field) ⇒ Object



77
78
79
# File 'app/models/concen/user.rb', line 77

def generate_token(field)
  self.write_attribute(field.to_sym, SecureRandom.urlsafe_base64)
end

#nulify_unused_tokenObject



81
82
83
84
85
86
# File 'app/models/concen/user.rb', line 81

def nulify_unused_token
  self.password_reset_token = nil
  self.password_reset_sent_at = nil
  self.invitation_token = nil
  self.invitation_sent_at = nil
end

#send_password_resetObject



53
54
55
56
57
58
59
# File 'app/models/concen/user.rb', line 53

def send_password_reset
  generate_token(:password_reset_token)
  self.password_reset_sent_at = Time.now
  save
  Rails.logger.info "--called"
  # Send email here.
end