class AdminUser < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable, :lockable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me # new function to set the password without knowing the current password used in our confirmation controller. def attempt_set_password(params) p = {} p[:password] = params[:password] p[:password_confirmation] = params[:password_confirmation] update_attributes(p) end # new function to return whether a password has been set def has_no_password? self.encrypted_password.blank? end # new function to provide access to protected method unless_confirmed def only_if_unconfirmed unless_confirmed {yield} end def password_required? # Password is required if it is being set, but not for new records if !persisted? false else !password.nil? || !password_confirmation.nil? end end end