2

我试图在用户无法登录时显示一个闪光警报。但是,将有两种不同的情况:

  1. 用户输入的邮箱存在,但密码错误。我希望显示此消息:The email address or password you entered is incorrect.

  2. 用户输入的电子邮件不存在。我希望显示此消息:The email address and password you entered do not match our records. (You provided <span class='black'>#{params[:email]}</span>)<br/><br/> <a href='/accounts/forgot_password' class='decorate'>Having trouble accessing your account?</a>

是否有类似于after_sign_in_path我可以根据这些条件修改闪光灯的钩子?

更新

所以我找到了这个。但是我如何只传递 email 变量not_found_in_database呢?

en:
  devise:
    failure:
      already_authenticated: "You are already signed in."
      invalid: "The email address or password you entered is incorrect."
      not_found_in_database: "The email address and password you entered do not match our records. (You provided <span class='black'>%{email}</span>)<br/><br/><a href='/accounts/forgot_password' class='decorate'>Having trouble accessing your account?</a>."
4

2 回答 2

3

我最终使用了这个: http: //guides.rubyonrails.org/i18n.html#passing-variables-to-translations

和这个:

                <% if !flash[:alert].blank? %>
                    <% if flash[:alert][/The email address and password you entered do not match our records/] %>
                        <div class="flashNotice col last">
                            <%= t('devise.failure.not_found_in_database', resource_name: "#{params[:user][:email]}").html_safe %>
                        </div>
                    <% else %>
                    <!-- Style for any warning message -->
                        <div class="flashNotice col last"><%= flash[:alert]%></div>
                    <% end %>
                <% end %>
于 2013-06-26T18:47:55.977 回答
2

我不建议您区分这两种情况。如果您提供此信息,则可以从您的页面中挖掘电子邮件地址。他们只需要用随机地址和虚拟密码轰炸你的系统,他们最终会找到一些有效的电子邮件。如果它是一个小页面,它并不重要,但最好避免这个问题。

于 2013-06-26T18:35:19.367 回答