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
|
2014-04-14 10:40:17 +00:00
|
|
|
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
|