#this class handles user login and password. User has the attributes user name, email and password which he / she can choose 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 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