I just started using Rails 4. I got devise<\/code> setup with custom fields.
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.
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. So i you change the configure_permitted_parameters
method to this, it should work:
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. So what worked in my case was adding the following flag in devise.rb config.allow_unconfirmed_access_for = 999.days
The error bar stays until the user has confirmed their mail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.