[refs #782] restore login&pass authentication

This commit is contained in:
Alexander Machehin 2012-12-14 19:20:46 +06:00
parent 2bb5d517a2
commit 2f1a21cbdf
2 changed files with 4 additions and 2 deletions

View File

@ -86,10 +86,12 @@ 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.access_locked? and (user.authentication_token == login or user.valid_password?(p))
return user if !user.access_locked? and (user.authentication_token == login or user.valid_password?(pass))
nil
end

View File

@ -12,7 +12,7 @@ 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) and
user = User.find_for_database_authentication({:login => u, :pass => 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