views:

286

answers:

1

Hi, I have 2 questions about authlogic:

1 - how to get cause of unsuccessful session creation (for example - not confirmed, blocked, wrong pass etc) to use it in app logic (route to another page for confimation, or re-enter pass etc)?

2 - question about integration formtastic and authlogic. How to show error messages on session creation , when login and pass is NOT provided. Everytime i submitting empty form - there are no any error message(but form.error_messages shows that you must enter login and pass), but if one of fields (login OR pass) provided - all works good.

+2  A: 

1:

If you follow the suggested pattern for the login url:

  def create
    @user_session = UserSession.new(params[:user_session])
    if @user_session.save
      redirect_to your_url
    else
      render :action => 'new'
    end
  end

The @user_session var will be available to your new template. You can access any login errors with @user_session.error_messages. I believe that returns formatted HTML, not an array.

UPDATE

According to the docs, Authlogic errors behave exactly like active record, so, in order to map your controller logic, you would do something like

if @user_session.save
  # Normal flow
else
  if @user_session.errors.on(:password)
    # do something
  else
    # do something else
  end
end
floyd
yes, i know it. But i'd like to (for example) redirect user to different pages in dependency of confirmation/account_lock_status/validation_of_login-pass/etc .... but in your way - i can only work with error messages
Alexey Poimtsev
You mean, depending on what the error the error is, you want the controller logic to change?
floyd
absolutely correct :)
Alexey Poimtsev
I updated my answer.
floyd