views:

104

answers:

2

Hey there, im a little bit confused about handling invalid user authentication request, at login controller. So, i already have modified login view, but cant figure out where to put the exception handling block. It should work like this: you login - if its incorrect you will see warning message at /login .

Any ideas ?

A: 

What strategy have you chosen ? In my custom Strategy, I call the class method 'authenticate' on my User class:

class User
  def self.authenticate(login, password)
    u = User.first(:conditions => ['email = ?', login]) # find a user with this login
    if u && u.authenticated?
      return u
    else
      nil
    end
  end
end

Also, you might want to look at the source code of merb-auth-more/mixins/salted_user which is a module that is automatically mixed into your User class.

Ahsan Ali
A: 

you would put your exception handling action in the exceptions controller

# handle NotAuthorized exceptions (403)
def not_authorized
    render :format => :html
end

and to customise the view you would create a template in app/views/exceptions/not_authorized.html.haml

roo