Rails 中可能出现 HTTP 基本自定义错误吗?
我正在使用 Ruby 1.8.7 在 Rails 2.3.14 中构建一个应用程序。
我的客户请求在网络研讨会页面上进行非常简单的身份验证。 我认为使用 http_auth 非常合适,因为它只需要一个非常基本的用户名和密码。
现在,她要求如果他们点击取消或使用错误的信息,他们会被重定向到一个页面,该页面基本上显示“如果您忘记登录信息,请联系我们”。
我该如何做到这一点,以便当我们收到“HTTP Basic:访问被拒绝”时。错误,我可以重定向到页面吗?或者,只需使用我们的自定义样式/内容自定义此页面?
提前致谢。
这是我的网络研讨会控制器的代码:
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
I am building an application in Rails 2.3.14 using Ruby 1.8.7.
My client has requested a very simple authentication on a webinars page.
I thought using http_auth would be very fitting, as it just needs a very basic username and password.
Now, she has requested that if they hit cancel or use the wrong information, they get redirected to a page that basically says "if you forget login information, contact us."
How do I make it so that when we get the "HTTP Basic: Access denied." error, I can instead redirect to a page? Or, instead, just customize this page with our custom styles/content?
Thanks in advance.
Here is the code from my webinars controller:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看
authenticate_or_request_with_http_basic
源,您会看到以下内容:因此您的
login_procedure
块只要返回 true 就可以执行几乎任何操作成功登录。特别是,它可以调用redirect_to
:If you look at the
authenticate_or_request_with_http_basic
source, you'll see this:So your
login_procedure
block can do pretty much anything it wants as long as it returns true for a successful login. In particular, it can callredirect_to
: