Created
November 19, 2014 10:25
-
-
Save StasKoval/8fc983bd96c26c646c14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_secure_password validations: false | |
validates_uniqueness_of :email, allow_blank: false | |
#validates :email, :email => true | |
after_validation :ensure_token | |
before_create :set_temporary_password | |
def set_temporary_password | |
self.password = SecureRandom.hex(5) | |
self.password_confirmation = self.password | |
end | |
def ensure_token | |
self.token = generate_token | |
end | |
def admin? | |
false | |
end | |
def applicant? | |
type.eql?('Applicant') | |
end | |
def employer? | |
type.eql?('Employer') | |
end | |
private | |
def generate_token | |
loop do | |
token = SecureRandom.uuid | |
break token unless User.where(token: token).first | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment