简体   繁体   English

设计 - Rails 4 - 无法登录

[英]Devise - Rails 4 - Not able to login

I just started using Rails 4. I got devise<\/code> setup with custom fields.我刚开始使用 Rails 4。我得到了带有自定义字段的devise<\/code>设置。 I'm able to login after I register, but I'm not able to login from the login page.我注册后可以登录,但我无法从登录页面登录。 The user registration goes in fine, and I have username<\/code> , password<\/code> etc in the database table.用户注册顺利,我在数据库表中username<\/code> 、 password<\/code>等。

Can somebody tell me what I'm missing?有人可以告诉我我错过了什么吗? My User model is very basic.我的用户模型非常基本。 Here is how it looks like -这是它的样子 -

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :username, :uniqueness => true, :presence => {:message => '- Username cannot be blank'}
  validates :first_name, :presence => { :message => " - Firstname cannot be blank!"}    

  private
    def user_params
        params.require().permit(:first_name, :last_name, :username, :email, :password, :password_confirmation)
    end
end

In your application controller you have permitted params for sign_up, but not for sign_in. 在您的应用程序控制器中,您已经允许使用params进行sign_up,但不允许使用sign_in。 So i you change the configure_permitted_parameters method to this, it should work: 所以我将configure_permitted_parameters方法更改为this,它应该工作:

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :password, :remember_me) }
    devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username, :first_name, :last_name, :password, :password_confirmation, :email) }
  end

I was using devise confirmable.我正在使用可确认的设计。 devise.rb was setup in such a way that it wouldn't let me log in if the account's email wasn't confirmed. devise.rb 的设置方式是,如果帐户的电子邮件未得到确认,它不会让我登录。 So what worked in my case was adding the following flag in devise.rb config.allow_unconfirmed_access_for = 999.days所以在我的情况下有效的是在 devise.rb config.allow_unconfirmed_access_for = 999.days 添加以下标志

Default value is nil which means devise won't let you login until the user has confirmed their email默认值为 nil,这意味着在用户确认他们的电子邮件之前,设计不会让您登录

In my UI I show a error message bar that has a button to trigger resending of confirmation mail.在我的 UI 中,我显示了一个错误消息栏,其中包含一个触发重新发送确认邮件的按钮。 The error bar stays until the user has confirmed their mail.错误栏一直存在,直到用户确认他们的邮件。

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM