Debuging Devise in simple Rails app - ruby-on-rails

I configure Devise gem for Rails and in code it seems look OK but when I'm trying to register new user I have the problem.
In register form Devise show notice:
Please review the problems below:
but that's all. Nothing specific message. Where I should looking for first? How to debug something like this?
Any suggestions?
Log from rails server:
Started POST "/auth/register" for 127.0.0.1 at 2014-09-14 17:09:13
+0200 Processing by Devise::RegistrationsController#create as HTML Parameters: {"utf8"=>"✓",
"authenticity_token"=>"iRsLU68tBckSzK1tupMoXZQlGw7xOuzMlfuiIVVs+rc=",
"user"=>{"email"=>"test#test.com", "password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.2ms) BEGIN User Exists (0.4ms) SELECT 1 AS one FROM "users"
WHERE "users"."email" = 'test#test.com' LIMIT 1 (0.2ms) ROLLBACK
Rendered devise/shared/_links.haml (0.5ms) Rendered
devise/registrations/new.html.haml within layouts/application (15.9ms)
Completed 200 OK in 121ms (Views: 24.2ms | ActiveRecord: 0.8ms)
And when I try log in:
Started POST "/auth/login" for 127.0.0.1 at 2014-09-14 17:10:23 +0200
Processing by Devise::SessionsController#create as HTML Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"iRsLU68tBckSzK1tupMoXZQlGw7xOuzMlfuiIVVs+rc=",
"user"=>{"email"=>"test#test.com", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"} User Load (0.7ms) SELECT
"users".* FROM "users" WHERE "users"."email" = 'test#test.com' ORDER
BY "users"."id" ASC LIMIT 1 Completed 401 Unauthorized in 2ms
Processing by Devise::SessionsController#new as HTML Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"iRsLU68tBckSzK1tupMoXZQlGw7xOuzMlfuiIVVs+rc=",
"user"=>{"email"=>"test#test.com", "password"=>"[FILTERED]",
"remember_me"=>"0"}, "commit"=>"Sign in"} Rendered
devise/shared/_links.haml (0.4ms) Rendered
devise/sessions/new.html.haml within layouts/application (9.8ms)
Completed 200 OK in 106ms (Views: 15.4ms | ActiveRecord: 0.0ms)

I debug these things by inspecting the object.errors
In this case, try to
raise #user.errors.inspect
Somewhere after the save in the create method

Related

devise throw me out right after sign in on production but working great on development environment

I'm using rails 3.2 and Devise 3.4.1.
On development environment all is working great but on production I'm getting this:
Started POST "/users/sign_in" for 111.111.111.11 at 2015-01-18 15:04:58 +0000
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"PGRrSKfVz8fZiv1a1qBJN2TzmFRAvUgEfYRpmdWiPWk=", "user"=>{"email"=>"email#email.com", "password"=>"[FILTERED]"}, "commit"=>"Log in"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'email#email.com' LIMIT 1
(0.2ms) BEGIN
(0.5ms) UPDATE `users` SET `last_sign_in_at` = '2015-01-18 15:04:53', `current_sign_in_at` = '2015-01-18 15:04:59', `sign_in_count` = 25, `updated_at` = '2015-01-18 15:04:59' WHERE `users`.`id` = 2
(1.2ms) COMMIT
Redirected to http://subdomain.domain.com/
Completed 302 Found in 100.0ms (ActiveRecord: 0.0ms)
Started GET "/" for 111.111.111.11 at 2015-01-18 15:04:59 +0000
Started GET "/authorized" for 111.111.111.11 at 2015-01-18 15:04:59 +0000
Processing by AuthorizedController#index as HTML
Completed 401 Unauthorized in 0.3ms
Started GET "/users/sign_in" for 111.111.111.11 at 2015-01-18 15:05:00 +0000
Processing by SessionsController#new as HTML
Rendered devise/shared/_links.html.erb (0.1ms)
Rendered devise/sessions/new.html.erb (4.0ms)
Completed 200 OK in 5.3ms (Views: 4.5ms | ActiveRecord: 0.0ms)
as you can see the user is being authorised but signing out immediately after that.
help?
well, the CDN just blocked Devise's cookie so it's solved now
thank you all!

Failed to load resource 401 unauthorized only with Safari

I'm found an interesting problem in my app.
I'm using Rails 3 with ruby 2.0. I already have a production server where my app is running and another staging server. I'm configuring a new better one but I have a problem only with Safari.
Redirected to http://ip.server/
Completed 302 Found in 201.7ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-13 08:17:18 +0200
Processing by DashboardController#index as HTML
Completed 401 Unauthorized in 1.2ms
Started GET "/user/sign_in" for my.ip at 2014-10-13 08:17:18 +0200
Processing by Devise::SessionsController#new as HTML
Rendered application/_field_errors.html.erb (0.0ms)
Rendered application/_field_errors.html.erb (0.0ms)
Rendered devise/sessions/new.html.erb within layouts/devise (2.3ms)
Completed 200 OK in 5.5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
When I check on the network tab, I can see this:
Fail to load resource: the server responded with a status of 401 (unauthorized)
At the beginning I thought my problem came from Devise but then I checked on Google and find that:
cross browser problem
I tried on Chrome and it works. I tried also without AdBlock or with the private navigation but it still not working with Safari.
Edit:
I did 2 requests, one coming from Chrome and the second one from Safari. The only difference is this line:
WARNING: Can't verify CSRF token authenticity
Edit 2:
I've commented the line protect_from_forgery on my ApplicationController.rb and finally this error (about CSRF) wasn't responsible for my problem.
Here my stacks when I try with Chrome and with Safari.
With Chrome:
Started POST "/user/sign_in" for my.ip at 2014-10-14 13:27:51 +0200
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"c86MNR4MCSbQWJiAjkGtgfgPMg5YirG1tqf/2vqdBWc=", "user"=>{"email"=>"test#example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'test#example.com' LIMIT 1
(0.1ms) BEGIN
WARNING: User#current is nil, are you including SentientController on your ApplicationController?
(0.3ms) UPDATE `users` SET `last_sign_in_at` = '2014-10-14 11:26:45', `current_sign_in_at` = '2014-10-14 11:27:51', `sign_in_count` = 52, `updated_at` = '2014-10-14 11:27:51' WHERE `users`.`type` IN ('User::Admin') AND `users`.`id` = 1
(26.1ms) COMMIT
Redirected to http://server.ip/
Completed 302 Found in 135.6ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-14 13:27:51 +0200
Processing by DashboardController#index as HTML
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
server.ip Rendered dashboard/index.html.erb within layouts/application (2.5ms)
Rendered application/_header.html.slim (57.6ms)
Rendered application/_sidebar.html.erb (48.1ms)
Rendered application/_page_header.html.slim (2.0ms)
Rendered application/_flash_messages.html.erb (0.5ms)
Rendered application/_footer.html.erb (0.8ms)
Completed 200 OK in 137.5ms (Views: 122.9ms | ActiveRecord: 5.1ms)
With Safari:
Started POST "/user/sign_in" for my.ip at 2014-10-14 13:27:58 +0200
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"TWKhSxus5q46H9sZdEvMnzD52r0zA5phw/Pv7K+NKuY=", "user"=>{"email"=>"test#example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'test#example.com' LIMIT 1
(0.1ms) BEGIN
(0.3ms) UPDATE `users` SET `last_sign_in_at` = '2014-10-14 11:27:51', `current_sign_in_at` = '2014-10-14 11:27:58', `sign_in_count` = 53, `updated_at` = '2014-10-14 11:27:58' WHERE `users`.`type` IN ('User::Admin') AND `users`.`id` = 1
(24.8ms) COMMIT
Redirected to http://server.ip/
Completed 302 Found in 138.2ms (ActiveRecord: 0.0ms)
Started GET "/" for my.ip at 2014-10-14 13:27:58 +0200
Processing by DashboardController#index as HTML
Completed 401 Unauthorized in 1.2ms
Started GET "/user/sign_in" for my.ip at 2014-10-14 13:27:58 +0200
Processing by Devise::SessionsController#new as HTML
Rendered application/_field_errors.html.erb (0.0ms)
Rendered application/_field_errors.html.erb (0.0ms)
Rendered devise/sessions/new.html.erb within layouts/devise (2.2ms)
Completed 200 OK in 5.2ms (Views: 3.7ms | ActiveRecord: 0.0ms)
Problem solved. It was not at all coming from my app but from my DNS redirection. I put an simple web redirection for tests and I forgot to add DNS redirection.
Now everything is working perfectly.
I hope this will help someone else!

401 Unauthorized using devise after adding theme

I have the error Completed 401 Unauthorized in 99.0ms after adding a template in rails 3.2 app and i was signing in from /users/sign_in URL.
Also, i did not change anything like authenticate by "name" but using the defaults authentication by email address.
Does anyone encounter this problem when signing in?
The error is:
Started POST "/users/sign_in" for 127.0.0.1 at 2014-08-05 12:04:19 +0800
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"<removed>", "user"=>{"email"=>"zaihan#clixster.net", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
ESC[1mESC[35mUser Load (1.0ms)ESC[0m SELECT `users`.* FROM `users` WHERE `users`.`email` = 'zaihan#clixster.net' LIMIT 1
Completed 401 Unauthorized in 14.0ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"<removed>", "user"=>{"email"=>"zaihan#clixster.net", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/sessions/new.html.erb within layouts/application (38.0ms)
Rendered layouts/_navigation.html.erb (1.0ms)
Rendered layouts/_footer.html.erb (1.0ms)
I have found the solution. Make sure you do not have
attr_accessor :password
or your password field for devise in database would be empty.

devise error message when wrong username/password

My problem is that I do not see any error messages when Devise sign in failed. When this happens I got redirected to Devise::SessionsController#new which is not setting any errors
Started POST "/users/sign_in" for 127.0.0.1 at 2014-08-17 06:30:59 +0300
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4ZgT4DtyyNYNGHRbwCVASolL3CQEqIeMtPlOOy7EBik=", "user"=>{"username"=>"setdddd", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Войти"}
Completed 401 Unauthorized in 3ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4ZgT4DtyyNYNGHRbwCVASolL3CQEqIeMtPlOOy7EBik=", "user"=>{"username"=>"setdddd", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Войти"}
[]
Rendered devise/shared/_links.erb (0.1ms)
Rendered devise/sessions/new.html.erb within layouts/application (40.0ms)
Rendered application/_header.erb (0.5ms)
Rendered application/_footer.erb (0.0ms)
Completed 200 OK in 50ms (Views: 47.8ms | ActiveRecord: 0.0ms)
So the question is are there any switches in devise configuration that allow me to show error message to user, not just a redirect?
Are you outputting your flash messages where appropriate? It looks like devise sets flash[:notice] and flash[:alert] depending on the situation (i.e. failed login, etc). It's up to you to ensure that you output those values to your page. See the devise README for more details.

RoR Rails 3 Devise::SessionsController fails to authenticate existing user

I'm starting the app at http://localhost:3000/users/sign_in
accept user / password; posting
device fails to authenticate my user and jumps into #new
#new render sign_in again, so I am in a loop.
here is the log:
Started POST "/users/sign_in" for 127.0.0.1 at 2011-10-30 17:49:33 -0700
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NhVu4CQwhatever+CAErP19YVIkz0lIz3qEERac=", "user"=>{"email"=>"abc#def.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Sign in"}
Then it runs the SQL to fetch the user. copy/pate to postgresql, the 'select' fetch my user record. it definitely exists**
[1m[35mUser Load (5.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."email" = 'abc#def.com' LIMIT 1
The next log entry: jumps to #new - as if the user do not exist
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NhVu4CQwhatever+CAErP19YVIkz0lIz3qEERac=", "user"=>{"email"=>"abc#def.com", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Sign in"}
Rendered devise/sessions/new.html.erb within layouts/application (4.0ms)

Resources