Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Handle session validation errors when user model has :active attribute, :default => false #25

Open
badnaam opened this issue Jul 12, 2010 · 9 comments
Labels

Comments

@badnaam
Copy link

badnaam commented Jul 12, 2010

I implemented the instructions in the sample app and docs. It seems when I try to login (using a gmail account) I get the following error while trying to save the @user_session, in UserSessionsController => create action. I know that the login information is correct and in fact the @rpx_data object contains some legit profile info, the rpx pop up seems to think it worked, but I get a failure. Also, in my janrain dashboard I see the login counts getting recorded.

Here is teh link to the key source file

http://pastie.org/1040188

In addition to this, the other thing I see is that @attempted_record is nil in the create action as well.

<Authlogic::Session::Validation::Errors:0x7f0aa1315c60 @errors=#<OrderedHash {"base"=>[#<ActiveRecord::Error:0x7f0aa12f8458 @options={}, @Attribute=:base, @message="We did not find any accounts with that login. Enter your details and create an account.", @base=#<UserSession: no credentials provided>, @type="We did not find any accounts with that login. Enter your details and create an account.">]}>, @base=#<UserSession: no credentials provided>>

@tardate
Copy link
Owner

tardate commented Jul 14, 2010

Hi @badnaam, I believe you are hitting the error because automatic registration is disabled, and you are attempting to login with an account that has not been registered yet.

Did you intend to have auto-registration disabled? What does your UserSession class definition look like? The basic setup should be like the following, but you may also have "auto_register false" specified.

class UserSession < Authlogic::Session::Base
    rpx_key RPX_API_KEY
end

With autoregistration enabled, the account login should proceed correctly (still does for me in the sample). However, if you have auto-registration disabled, you must provide the necessary registration logic to setup the account in the first place.

Is that any help?

@badnaam
Copy link
Author

badnaam commented Jul 24, 2010

Tardate, thanks. I do have rpx_key ENV['RPX_KEY']
auto_register true
. The problem I am running into is that in my UserSessionsController.create the current_user is always nil. I don't know why, I tried to follow your sample app closely. Here are the files, if you are interested in taking a look. I see that in your sample after the registration is complete you redirect to edit_user_path(:current), in my case that doesn't really work. I use friendly_id, for the user model, not sure if that has anything to do with it.

Here are my files if you wanna take a look. Thanks for your help!

http://pastie.org/1058447

@badnaam
Copy link
Author

badnaam commented Jul 24, 2010

Oh, I did verify that by the time the session is created and saved the user is registered and there is a slug generated for the user, so the user record should be there, unless UserSession does not know how to work with slugs. Just a hypothesis the slugs may not have anything to do with it. This usually happens only in the create method in UserSession i,e. when the session is created, but if I ignore the error and continue with the session it seems there is in fact a current_user in subsequent pages.

@tardate
Copy link
Owner

tardate commented Sep 11, 2010

Hi badnaam,
I had a look through the pastie and don't see anything particularly out of place, with the exception of the users controller create action. Is there a particular reason why you are doing user.save_without_session_maintenance?

@ql
Copy link

ql commented Sep 25, 2010

Same here. Trying to introduce authlogic_rpx to an existing project, getting "UserSession: no credentials provided" after all redirects :(

@ql
Copy link

ql commented Sep 27, 2010

I've found how to reproduce error: rails-authlogic-rpx-sample, add field ':active, :boolean, :default => true' to User model.

@tardate
Copy link
Owner

tardate commented Sep 28, 2010

hi @ql, tried to reproduce the error but haven't been able to yet. I added users.active to the rails 2.3.5 version of the sample at http://github.com/tardate/rails-authlogic-rpx-sample/tree/gh25_session_error_investigation and I haven't hit the UserSession: no credentials provided error. I tried also with rails3, see http://github.com/tardate/rails-authlogic-rpx-sample/tree/gh25_session_error_investigation_rails3 and also no immediate problem.

Could you take a look and see if there's anything else that's required to cause the error? Do you have a validation on :active or something else like that

@ql
Copy link

ql commented Sep 28, 2010

Hi!
Actually I've mistaken, it was ":active, :boolean, :default => false', not :default => true. Authlogic uses some magic states if it sees fields active/confirmed/approved in model. I fixed this by adding
self.attempted_record.active= true
in map_rpx_data().

Only reason why I call this thing "a bug" is that error message was "Authentication failed. Please try again.", not informing inactive user. Could take time for finding out the problem's source

@tardate
Copy link
Owner

tardate commented Sep 28, 2010

ahah, thanks for figuring that out! agree, should provide some smarter handling of this situation. I'll make that a 'todo'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants