orbit4-5/app/models/user.rb

19 lines
648 B
Ruby
Raw Normal View History

2014-04-10 09:13:42 +00:00
#this class handles user login and password. User has the attributes user name, email and password which he / she can choose
2014-04-10 04:01:34 +00:00
class User
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::SecurePassword
field :user_name, type: String
field :email, type: String
field :password_digest, type: String
2014-04-10 04:01:34 +00:00
has_secure_password
VALID_EMAIL_FORMAT = /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/
validates :user_name, presence: true, uniqueness: true
validates :password, presence: true, :on => :create, length: {:in => 8..20}
validates :email, presence: true, uniqueness: true, format: { with: VALID_EMAIL_FORMAT }
end