Skip to content

Instantly share code, notes, and snippets.

@StasKoval
Created November 19, 2014 10:25
Show Gist options
  • Save StasKoval/8fc983bd96c26c646c14 to your computer and use it in GitHub Desktop.
Save StasKoval/8fc983bd96c26c646c14 to your computer and use it in GitHub Desktop.
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