簡體   English   中英

無效的電子郵件或密碼的設計登錄錯誤在Rails中不起作用

[英]Devise login error for invalid email or password is not working in rails

我有一個設計user模型。 user輸入錯誤的password時,通過顯示無效的電子郵件或密碼將其重定向回登錄頁面,這可以正常工作。 但是,當用戶輸入錯誤的email時,我不會收到相同的錯誤。 我遇到了另一個error

I18n::MissingInterpolationArgument at /users/sign_in
missing interpolation argument :authentication_keys in "Invalid %{authentication_keys} or password." ({:resource_name=>:user} given)

在我的用戶模型中,我有一個用戶名字段(這是唯一的)。 就我而言,用戶可以使用usernameemail登錄。 這種customisation產生任何問題嗎? 這是我的devise.en.yml文件。

# Additional translations at https://github.com/plataformatec/devise/wiki/I18n

en:
  devise:
    confirmations:
      confirmed: "Your email address has been successfully confirmed."
      send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
      send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
    failure:
      already_authenticated: "You are already signed in."
      inactive: "Your account is not activated yet."
      invalid: "Invalid email or password."
      locked: "Your account is locked."
      last_attempt: "You have one more attempt before your account is locked."
      not_found_in_database: "Invalid %{authentication_keys} or password."
      timeout: "Your session expired. Please sign in again to continue."
      unauthenticated: "You need to sign in or sign up before continuing."
      unconfirmed: "You have to confirm your email address before continuing."
    mailer:
      confirmation_instructions:
    subject: "Confirmation instructions"
      reset_password_instructions:
    subject: "Reset password instructions"
      unlock_instructions:
    subject: "Unlock instructions"
      password_change:
    subject: "Password Changed"
    omniauth_callbacks:
      failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
      success: "Successfully authenticated from %{kind} account."
    passwords:
      no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
      send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
      send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
      updated: "Your password has been changed successfully. You are now signed in."
      updated_not_active: "Your password has been changed successfully."
    registrations:
      destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
      signed_up: "Welcome! You have signed up successfully."
      signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
      signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
      signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
      update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
      updated: "Your account has been updated successfully."
    sessions:
      signed_in: "Signed in successfully."
      signed_out: "Signed out successfully."
      already_signed_out: "Signed out successfully."
    unlocks:
      send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
      send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
      unlocked: "Your account has been unlocked successfully. Please sign in to continue."
  errors:
    messages:
      already_confirmed: "was already confirmed, please try signing in"
      confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
      expired: "has expired, please request a new one"
      not_found: "not found"
      not_locked: "was not locked"
      not_saved:
    one: "1 error prohibited this %{resource} from being saved:"
    other: "%{count} errors prohibited this %{resource} from being saved:"

這些是gemfile.lock文件中的gemfile.lock和rails版本。

    devise (3.2.4)
    devise-async (0.9.0)
    devise (~> 3.2)
    devise
    devise-async

    rails (4.1.5)

您需要在用戶模型中定義一個名為login的虛擬屬性,並告訴devise在authentication_keys使用此字段。

檢查此鏈接以獲取詳細信息https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

我遇到了同樣的問題,並通過更新到最新版本的devise解決了該問題(我目前正在運行4.2.0)。 您可能需要更新ruby版本才能使用最新版本的devise。( https://github.com/plataformatec/devise/blob/master/CHANGELOG.md#400rc1---2016-02-01

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM