module UserAuthModel::InstanceMethods
Public Class Methods
new(args = {})
click to toggle source
Calls superclass method
# File lib/user_auth_model.rb, line 24 def initialize(args = {}) args.symbolize_keys! args[:salt] = random_string(10) if !args[:salt] && args[:password_new] args[:password] = encrypt(args[:password_new], args[:salt]) if args[:password_new] super(args) end
Public Instance Methods
change_password(password_new)
click to toggle source
# File lib/user_auth_model.rb, line 36 def change_password password_new pp self pp self.args[:salt] self.args[:password] = encrypt(password_new, self.salt) end
encrypt(password, salt = nil)
click to toggle source
# File lib/user_auth_model.rb, line 42 def encrypt(password, salt = nil) if salt Digest::SHA1.hexdigest(password+salt) else Digest::SHA1.hexdigest(password+self.salt) end end
forgot_password()
click to toggle source
# File lib/user_auth_model.rb, line 31 def forgot_password self.reset_token = random_string(30) save end
random_string(len)
click to toggle source
# File lib/user_auth_model.rb, line 50 def random_string(len) #generate a random password consisting of strings and digits chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } return newpass end