authlogic icon indicating copy to clipboard operation
authlogic copied to clipboard

#<AccountSession: no credentials provided> adds errors to the form on :new action

Open gavinhughes opened this issue 17 years ago • 11 comments

Creating a new instance automatically loads errors into @base and populates those errors on my sign in form:

(rdb:1) @account_session = AccountSession.new

<AccountSession: no credentials provided>

(rdb:1) @account_session.errors

<Authlogic::Session::Validation::Errors:0x213cc78 @errors={}, @base=#<AccountSession: no credentials provided>>

Is this correct behavior or am I missing something?

Gavin

gavinhughes avatar Sep 04 '09 07:09 gavinhughes

You should do something like that: @account_session = AccountSession.new(:username => 'my_username', :password => 'password')

NebJ avatar Sep 05 '09 23:09 NebJ

Doing that on the :new action will populate the form with (incorrect) data, which is not what we want on :new. We want the form to be blank. Calling AccountSession.new(:username => ' ', :password => ' ') gives the same "no credentials..." error. I'm sure the solution is simple, but I don't see it.

gavinhughes avatar Sep 06 '09 01:09 gavinhughes

Did you ever figure this out? I'm having a very similar problem.

translunar avatar Jan 10 '10 22:01 translunar

I agree that I am experiencing the same issue. I am currently running rails 3 beta 3 and authlogic 2.1.4.


# user_sessions_controller.rb
class UserSessionsController < ApplicationController
  def new
    # offending line
    @user_session = UserSession.new
  end
end

# error message
ActionView::Template::Error (undefined method `to_key' for #) on line #2 of /Users/leonard/Sites/media_six/single_sign_on/app/views/user_sessions/new.html.erb:
1: 
2: <%= form_for @user_session do |f| %>
3:  <%= render "shared/error_messages", :target => @user_session %>
4:  
5:  <%= field_set_tag 'login' do %>

coop avatar May 25 '10 12:05 coop

coop: me too, on my r3b3 test project.

wsc avatar Jun 03 '10 06:06 wsc

same here

plukevdh avatar Jun 16 '10 13:06 plukevdh

I had problems when I tried to do it without a user id / login field. I wanted multiple email addresses associated with a single account/password, and authlogic does not support that. Make sure you have some sort of login field.

ghost avatar Jun 16 '10 17:06 ghost

is any one find the solution? i am facing the same...

globesofttech avatar Aug 07 '10 15:08 globesofttech

I managed to get mine working by changing form_for tag to this:

<% form_for :user_session, @user_session, :url => { :action => "create" } do |f| %>

Hope this helps.

plusjade avatar Aug 11 '10 05:08 plusjade

@plusjade

Thanks, that is what is needed to display default form errors on the login template.

To keep the form from repopulating the login field. I added the following to UserSessionsController::create @user_session.login = nil render :action => :new

evan2m avatar Sep 01 '10 00:09 evan2m

Closing after six years with no activity. If this is still a problem in the latest version (currently 3.5.0), please let us know and we'll be happy to re-open the issue.

jaredbeck avatar Dec 02 '16 17:12 jaredbeck