skill-assessment-app/app/models/user.rb

25 lines
557 B
Ruby
Raw Normal View History

2016-07-26 17:00:00 -05:00
class User < ApplicationRecord
has_secure_password
has_many :candidates, foreign_key: "recruiter_id"
2016-08-18 15:35:17 -05:00
validates_presence_of :email
validates_presence_of :name
validates_presence_of :role
2016-08-24 15:02:32 -05:00
validates :reset_token, uniqueness: true, allow_nil: true
def setup_reset
gen_reset_token
save
end
private
def gen_reset_token
loop do
self[:reset_token] = SecureRandom.urlsafe_base64(10)
self[:reset_timestamp] = DateTime.now
break unless User.exists?(reset_token: self[:reset_token])
end
end
2016-07-26 17:00:00 -05:00
end