Currently, I am attempting to integrate the devise views utilizing JS to manage the responses. While I aim to utilize the default devise error messages, I am facing difficulty in isolating individual types of errors such as unconfirmed or locked accounts due to warden.authenticate. As a workaround, I have implemented a 'caught' mechanism to prevent the occurrence of a 406 or similar Error.
My primary issue lies in determining the corresponding symbol for a 'locked' state. Despite knowing that "caught[:message] == :unconfirmed" can provide the 'unconfirmed' state of the user, I am unsure of the appropriate symbol for 'locked'. The ":locked" symbol does not offer the desired outcome, and I am unable to locate relevant documentation.
My Sessions_controller is structured as follows:
def create
caught = catch(:warden) do
self.resource = warden.authenticate :scope => resource_name
end
if resource
# User is confirmed
sign_in(resource_name, resource)
puts "LOGGED IN!!!"
respond_to js{
set_flash_message(:success, :signed_in)
render :template => "remote_content/flashes.js.erb"
flash.discard
}
elsif caught and caught[:message] == :unconfirmed
# User is unconfirmed
puts "UNCONFIRMED ACCOUNT!!!"
# send the email or display the flash with a link to send an email
respond_to js{
set_flash_message(:error, :problem)
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
else
# User is not signed in, potentially due to error in credentials or a locked account
puts "ERROR IN CREDENTIALS!!!"
respond_to js{
set_flash_message(:error, :invalid)
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
end
end
Fortunately, the flashes.js.erb/form_flashes.js.erb function effectively without any issues. Here is a snippet of their functionality:
$('.modal').modal('hide');
// append flash messages to the body
$('.body').append("<%= escape_javascript raw(flash_normal) %>");
What are your thoughts on my approach? Would it be more suitable to implement a CustomFailure instead? I am unable to locate any examples of a CustomFailure or the original Devise method to integrate with my JS files.