我在后端使用devise和devise-token-auth作为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或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'."]}我在哪里可以自定义消息?
发布于 2017-03-17 10:04:51
消息位于devise_token_auth yaml文件:auth/blob/123cfb730ebaf4e2acc124edd39e68816cb0b8cf/config/locales/en.yml中。
因此,您需要通过将以下内容添加到您的本地yaml文件中来覆盖它:
en:
devise_token_auth:
sessions:
not_confirmed: "Custom message"https://stackoverflow.com/questions/42852244
复制相似问题