[refs #782] fix error with base auth

This commit is contained in:
Alexander Machehin 2012-12-17 20:18:18 +06:00
parent f9d680857d
commit 12b8b4c612
2 changed files with 4 additions and 7 deletions

View File

@ -86,13 +86,8 @@ class User < Avatar
class << self
def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
pass = conditions.delete(:pass)
user = User.where(conditions).where(:authentication_token => login).first ||
User.where(conditions).where(["lower(uname) = :value OR lower(email) = :value", { :value => login.downcase}]).first
return user if user and !user.access_locked? and (user.authentication_token == login or user.valid_password?(pass))
nil
where(conditions).where(["lower(uname) = :value OR lower(email) = :value", { :value => login.downcase }]).first
end
def new_with_session(params, session)

View File

@ -12,7 +12,9 @@ module Grack
return render_not_found if project.blank?
return ::Rack::Auth::Basic.new(@app) do |u, p|
user = User.find_for_database_authentication({:login => u, :pass => p}) and
user = (User.where(:authentication_token => u).first ||
User.find_for_database_authentication(:login => u)) and
!user.access_locked? and (user.authentication_token == u or user.valid_password?(p)) and
ability = ::Ability.new(user) and ability.can?(action, project) # project.members.include?(user)
end.call(env) unless project.public? and read? # need auth
end