Hinrik Örn Sigurðsson
unread,May 31, 2012, 11:56:02 AM5/31/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to plataforma...@googlegroups.com
I have a login form which pushes some JS to the user if their credentials are invalid. I do this by overriding SessionsController#create like so:
def create
if request.format == 'js' && params[:region] && params[:region] == 'inline'
resource = warden.authenticate(auth_options)
if warden.authenticated?
sign_in(resource)
current_user.remember_me!
path = after_sign_in_path_for(resource)
render :update do |page|
page.redirect_to path
end
else
render partial: 'sessions/login_failed'
end
else
super
end
end
However, when using confirmable, if an unconfirmed user enters their email and the right password, Devise handles the error itself (401 along with a message telling the user to confirm) before my #create is able to handle it. How can I modify my code so that it also handles the case when an unconfirmed user tries to log in? I'm aware of the custom failure app method, but that seems to be even more hacky. I.e. I can't call render() from there. Ideally I'd like to be able to push some JS to the user in both situations (wrong password, unconfirmed user), containing appropriate messages for each (e.g. the respective Devise flash error message).