Skip to content

Commit

Permalink
Whitespace/parenthesis cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholstyn committed May 1, 2008
1 parent 361e917 commit 568b8c0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Mhs
module AuthenticationSystem
module Model

def self.included base #:nodoc:
def self.included(base) #:nodoc:
base.extend ClassMethods
end

Expand Down Expand Up @@ -30,7 +30,7 @@ module ClassMethods
# - :email_address_unique_validation - Error message used when the email_address is
# already in use. If this check is not desired, set to false or nil.
# Default: "has already been taken"
def acts_as_login_model options = {}
def acts_as_login_model(options = {})
extend Mhs::AuthenticationSystem::Model::SingletonMethods
include Mhs::AuthenticationSystem::Model::InstanceMethods

Expand All @@ -39,7 +39,7 @@ def acts_as_login_model options = {}
:password_validation => "must match",
:email_address_validation => "can't be blank",
:email_address_unique_validation => "has already been taken"
}.merge( options )
}.merge(options)

hash_password do |password, salt|
require 'digest/sha1'
Expand All @@ -62,9 +62,9 @@ def acts_as_login_model options = {}

if msg = self.mhs_authentication_system_options[:password_validation]
validate do |user|
if ( user.instance_variable_get( "@password" ) or user.instance_variable_get( "@password_confirmation" ) ) &&
user.instance_variable_get( "@password" ) != user.instance_variable_get( "@password_confirmation" )
user.errors.add( :password, msg )
if(user.instance_variable_get("@password") or user.instance_variable_get("@password_confirmation")) &&
user.instance_variable_get("@password") != user.instance_variable_get("@password_confirmation")
user.errors.add(:password, msg)
false
else
true
Expand All @@ -73,10 +73,10 @@ def acts_as_login_model options = {}
end

before_save do |user|
if user.instance_variable_get( "@password" )
if user.instance_variable_get("@password")
require 'digest/sha1'
user.salt ||= Digest::SHA1.hexdigest("--#{Time.now}--#{user.email_address}--")
user.password_hash = self.hash_password( user.instance_variable_get( "@password" ), user.salt )
user.password_hash = self.hash_password(user.instance_variable_get( "@password" ), user.salt)
end
end
end
Expand All @@ -87,7 +87,7 @@ module SingletonMethods

# Attempts to find a user by the passed in attributes. The param :password will
# be removed and will be checked against the password of the user found (if any).
def login params
def login(params)
if not params.blank? and user = self.find_by_email_address(params[:email_address], :include => {:group => :privileges})
self.hash_password(params[:password], user.salt) == user.password_hash ? user : nil
end
Expand All @@ -97,7 +97,7 @@ def login params
# - If given a block, that blocked is stored and used when hashing the users password.
# When the block is called, it will be given the password and the salt, if enabled.
# - Else, the stored block is called, giving passing it all arguments
def hash_password( *args, &blk )
def hash_password(*args, &blk)
if blk
self.mhs_authentication_system_options[:hash_password] = blk
else
Expand Down Expand Up @@ -128,13 +128,13 @@ def password_confirmation; end
# This value is cleared out in an after_validate callback. If there
# were not errors on the password attribute, then password_hash will be
# set to the hash of this password.
def password=( password )
def password=(password)
@password = password.blank? ? nil : password
end

# Sets the users password_confirmation. This will be itnored if the value is blank
# This value is cleared out in an after_validate callback.
def password_confirmation=( password )
def password_confirmation=(password)
@password_confirmation = password.blank? ? nil : password
end

Expand All @@ -143,7 +143,7 @@ def password_confirmation=( password )
# Valid options:
# - :match_all - If set to true, returns true if this user has ALL of the
# passed in privileges. Default: false
def has_privilege? *requested_privileges
def has_privilege?(*requested_privileges)
return false unless group
options = requested_privileges.last.is_a?(Hash) ? requested_privileges.pop : {}
matched_privileges = requested_privileges.map(&:to_s) & group.privileges.map(&:name)
Expand Down

0 comments on commit 568b8c0

Please sign in to comment.