Ruby on rails Rails中可能存在HTTP基本自定义错误?
我正在使用Ruby 1.8.7在Rails 2.3.14中构建一个应用程序 我的客户要求在网络研讨会页面上进行非常简单的身份验证。 我认为使用http_auth非常合适,因为它只需要一个非常基本的用户名和密码 现在,她要求,如果他们点击“取消”或使用错误的信息,他们会被重定向到一个页面,上面基本上写着“如果你忘记了登录信息,请与我们联系。” 如何使它在出现“HTTP Basic:Access denied.”错误时可以重定向到页面?或者,只是用我们的自定义样式/内容自定义此页面 提前谢谢 以下是我的网络研讨会控制器的代码:Ruby on rails Rails中可能存在HTTP基本自定义错误?,ruby-on-rails,ruby,authentication,basic-authentication,Ruby On Rails,Ruby,Authentication,Basic Authentication,我正在使用Ruby 1.8.7在Rails 2.3.14中构建一个应用程序 我的客户要求在网络研讨会页面上进行非常简单的身份验证。 我认为使用http_auth非常合适,因为它只需要一个非常基本的用户名和密码 现在,她要求,如果他们点击“取消”或使用错误的信息,他们会被重定向到一个页面,上面基本上写着“如果你忘记了登录信息,请与我们联系。” 如何使它在出现“HTTP Basic:Access denied.”错误时可以重定向到页面?或者,只是用我们的自定义样式/内容自定义此页面 提前谢谢 以下是
class WebinarsController < ApplicationController
before_filter :authenticate, :only => [:bpr]
def bpr
render :action => :bpr
end
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "abc" && password == "123"
end
end
end
class WebinarsController[:bpr]
def bpr
呈现:操作=>:bpr
结束
受保护的
def身份验证
使用_http _basicdo |用户名、密码验证_或_请求|u|
用户名==“abc”&&password==“123”
结束
结束
结束
如果您查看,您将看到:
def authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm)
end
def authenticate_with_http_basic(&login_procedure)
HttpAuthentication::Basic.authenticate(request, &login_procedure)
end
#...
def authenticate(request, &login_procedure)
unless request.authorization.blank?
login_procedure.call(*user_name_and_password(request))
end
end
因此,只要成功登录返回true,您的login\u过程
块几乎可以做任何它想做的事情。特别是,它可以调用重定向到:
def authenticate
authenticate_or_request_with_http_basic do |username, password|
if(username == "abc" && password == "123")
true
else
redirect_to '/somewhere/else/with/instructions'
end
end
end