Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Created March 7, 2014 15:52
Show Gist options
  • Save jamonholmgren/9414073 to your computer and use it in GitHub Desktop.
Save jamonholmgren/9414073 to your computer and use it in GitHub Desktop.
class FailureApp < Devise::FailureApp
def respond
# We override Devise's handling to throw our own custom errors on AJAX auth failures,
# because Devise provides no easy way to deal with them:
if request.xhr? && (warden_message == :unconfirmed || warden_message == :invalid)
if warden_message == :unconfirmed
flash.now[:alert] = "You need to confirm your account before continuing."
elsif warden_message == :invalid
user = Store::User.where(email: params[:user][:email].to_s).first
if user
if user.encrypted_password.present?
flash.now[:alert] = "Invalid email or password"
else
flash.now[:alert] = "You need to reset your password before you can sign in."
end
else
flash.now[:alert] = "Invalid email or password"
end
end
self.response = Store::SessionsController.action(:unconfirmed_error).call(env)
return self.response
end
# Original code:
if http_auth?
http_auth
elsif warden_options[:recall]
recall
else
redirect
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment