设计没有通过登录显示正确的错误

时间:2017-03-17 08:04:32

标签: ruby-on-rails devise

我在后端使用devisedevise-token-auth进行身份验证,在客户端使用'redux-auth`。

我正在设法发送一条正确的错误消息,以便在帐户暂时锁定时向客户展示

这是我的user.rb文件

  #  devise method to check if user is banned
  def active_for_authentication?
    super && !self.banned?
  end

  # message to send in case of ban. doesnt work yet
  def inactive_message
    self.banned? ? :locked : super
  end

  def banned?
    return self.role == 'banned'
  end

我的devise.en.yml文件

en:
  devise:
    confirmations:
      confirmed: "Your email address has been successfully confirmed."
    failure:
      locked: "Your account is locked."
  errors:
    messages:
      locked: "Your account has been banned"

当尝试使用redux-auth或CURL登录时,我似乎从设计中获得了标准的错误响应(我似乎无法在devise.en.yml文件中的任何位置找到给定的消息)

curl http://localhost:3000/auth/sign_in -d "email=foo@foo.com&password=123"

回复

{"success":false,"errors":["A confirmation email was sent to your account at 'foo@foo.com'."]}

我可以在哪里自定义消息?

1 个答案:

答案 0 :(得分:0)

消息位于devise_token_auth yaml文件中:https://github.com/lynndylanhurley/devise_token_auth/blob/123cfb730ebaf4e2acc124edd39e68816cb0b8cf/config/locales/en.yml

因此您需要通过将以下内容添加到本地yaml文件中来覆盖它:

en:
  devise_token_auth:
    sessions:
      not_confirmed: "Custom message"