0
@@ -9,7 +9,7 @@ module Mhs
0
# These methods are added to ActiveRecord::Base
0
# Sets up this model as a login model. The following thigs are done:
0
# * validates_presence_of :email_address
0
# * validates_uniqueness_of :email_address
0
# * sets up validation to check that password and password_confirmation
0
@@ -21,7 +21,7 @@ module Mhs
0
# * Adds methods from Mhs::AuthenticationSystem::Model::SingletonMethods
0
- # - :
group_validation - Error message used when the group_id is blank.
0
+ # - :
role_validation - Error message used when the role_id is blank.
0
# If this check is not desired, set this to false.
0
# Default: "can't be blank"
0
# - :password_validation - Error message used when the passwords do not match.
0
@@ -38,13 +38,13 @@ module Mhs
0
include Mhs::AuthenticationSystem::Model::InstanceMethods
0
self.mhs_authentication_system_options = {
0
- :
group_validation => {},
0
+ :
role_validation => {},
0
:email_address_validation => {},
0
:email_address_unique_validation => {},
0
:password_validation => "must match"
0
- }.merge(options.except(:
group_validation, :email_address_validation, :email_address_unique_validation))
0
+ }.merge(options.except(:
role_validation, :email_address_validation, :email_address_unique_validation))
0
- options.slice(:
group_validation, :email_address_validation, :email_address_unique_validation).each do |key, value|
0
+ options.slice(:
role_validation, :email_address_validation, :email_address_unique_validation).each do |key, value|
0
self.mhs_authentication_system_options[key].merge(:message => value)
0
elsif value.is_a?(Hash)
0
@@ -61,10 +61,10 @@ module Mhs
0
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
0
- if options = mhs_authentication_system_options[:group_validation]
0
- validates_presence_of :group_id, options
0
+ if options = mhs_authentication_system_options[:role_validation]
0
+ validates_presence_of :role_id, options
0
if options = mhs_authentication_system_options[:email_address_validation]
0
@@ -103,7 +103,7 @@ module Mhs
0
# Attempts to find a user by the passed in attributes. The param :password will
0
# be removed and will be checked against the password of the user found (if any).
0
- if not params.blank? and user = self.find_by_email_address(params[:email_address], :include => {:
group => :privileges})
0
+ if not params.blank? and user = self.find_by_email_address(params[:email_address], :include => {:
role => :privileges})
0
self.hash_password(params[:password], user.salt) == user.password_hash ? user : nil
0
@@ -159,9 +159,9 @@ module Mhs
0
# - :match_all - If set to true, returns true if this user has ALL of the
0
# passed in privileges. Default: false
0
def has_privilege?(*requested_privileges)
0
- return false unless
group0
+ return false unless
role0
options = requested_privileges.last.is_a?(Hash) ? requested_privileges.pop : {}
0
- matched_privileges = requested_privileges.map(&:to_s) &
group.privileges.map(&:name)
0
+ matched_privileges = requested_privileges.map(&:to_s) &
role.privileges.map(&:name)
0
options[:match_all] ? matched_privileges.size == requested_privileges.size : !matched_privileges.empty?
Comments
No one has commented yet.