mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
31 lines
1008 B
Ruby
31 lines
1008 B
Ruby
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
|
|
|
|
# new function to set the password without knowing the current password used in our confirmation controller.
|
|
def attempt_set_password(params)
|
|
update_attributes(params.slice(:password, :password_confirmation))
|
|
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
|