【发布时间】:2013-10-31 22:39:55
【问题描述】:
当用户点击忘记密码时,它会将他们带到忘记密码页面,其中有一个字段供他们输入他们的电子邮件地址。如果他们的电子邮件地址在数据库中,则一切正常,但如果该电子邮件地址在数据库中不存在,它只会重定向到同一页面,但不会显示错误消息。
如何让错误消息出现?
/view/devise/passwords/new.html.erb
...
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<h1>Reset Password</h1>
<div class="login-fields">
<p>Instructions on resetting your password will be emailed to you.</p>
<%= render :partial => '/shared/messages' %>
<div class="field">
<%= f.label :email %>
<%= f.email_field :email, :placeholder => 'Email', :class => 'login username-field' %>
</div> <!-- /field -->
</div> <!-- /login-fields -->
<div class="login-actions">
<%= content_tag(:button, :type=>:submit, :class => "button btn btn-secondary btn-large") do %>
Send me reset password instructions
<% end %>
</div> <!-- .actions -->
<div class="login-social">
<%= render "devise/shared/links" %>
</div>
<% end %>
...
/views/shared/_messages.html.erb
<% if alert || flash[:alert] || flash[:error] %>
<div class="alert alert-error">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Error!</h4>
<%= alert %>
<%= flash[:error] %>
</div>
<% end %>
<% if flash[:success] || notice || flash[:notice]%>
<div class="alert alert-success">
<a class="close" data-dismiss="alert" href="#">x</a>
<h4 class="alert-heading">Success!</h4>
<%= flash[:success] %>
<%= notice %>
</div>
<% end %>
【问题讨论】:
-
是否有任何 HTML 正在呈现? IE。它是否显示“错误!”标题但不是实际信息?还是什么都不显示?
-
请注意,这会将信息暴露给潜在的攻击者。试图猜测您系统中有效电子邮件地址的人将能够根据他们是否收到错误消息来判断某人是否拥有帐户。这类似于your login form says whether the username or password was incorrect 所显示的信息。您需要平衡特定应用程序的安全性和可用性。
标签: ruby-on-rails ruby ruby-on-rails-3 devise