Warden authentication recalls 401 Unauthorized

2019-06-28 03:08发布

问题:

i tried setting up devise with a brand new rails app, i have devise installed correctly using the gemfile and bundle install

following that installed devise using rails generate devise:install

created a new model using rails generate devise user

rake db:migrate to create the user table

added devise_for :users do get 'users/sign_out', :to => 'devise/sessions#destroy' end for signing out with my browser

run rails server

go to localhost:3000/users/sign_up to create a new user

go to localhost:3000/users/sign_out to log him out

go to localhost:3000/users/sign_in and try to log him in again and fails with the following and sending me back to the login screen without being logged in

Started POST "/users/sign_in" for 127.0.0.1 at 2012-07-13 16:55:28 +0800
  Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"cbFEP0FJ/e2XYHfub3ZeI7nEX0nCheXzCDs2ner3Zw8=", "newuser"=>{"email"=>"henghong.lee@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 1ms
  Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"cbFEP0FJ/e2XYHfub3ZeI7nEX0nCheXzCDs2ner3Zw8=", "newuser"=>{"email"=>"henghong.lee@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered /Users/Kinnovate/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/app/views/devise/shared/_links.erb (1.0ms)
Rendered /Users/Kinnovate/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/app/views/devise/sessions/new.html.erb within layouts/application (4.9ms)
Completed 200 OK in 175ms (Views: 16.5ms | ActiveRecord: 1.3ms)

how do i fix Completed 401 Unauthorized ?

回答1:

attr_accessor :password 

seemed to be the cause of the problem, because of that devise does not seem to create an encrypted password for the model