adopt-a-hydrant/app/controllers/sessions_controller.rb

27 lines
705 B
Ruby
Raw Permalink Normal View History

2011-03-06 18:28:00 +00:00
class SessionsController < Devise::SessionsController
2014-04-01 08:15:29 +00:00
skip_before_action :verify_authenticity_token, only: [:destroy]
2011-04-04 04:18:59 +00:00
def new
2012-06-18 17:49:28 +00:00
redirect_to(root_path)
2011-04-04 04:18:59 +00:00
end
2011-03-06 18:28:00 +00:00
def create
self.resource = warden.authenticate!(auth_options)
2011-03-07 02:40:29 +00:00
if resource
sign_in(resource_name, resource)
yield resource if block_given?
2014-03-25 09:47:44 +00:00
render(json: resource)
2011-03-07 02:40:29 +00:00
else
2014-04-01 08:15:29 +00:00
render(json: {errors: {password: [t('errors.password')]}}, status: 401)
2011-03-07 02:40:29 +00:00
end
2011-03-06 18:28:00 +00:00
end
def destroy
signed_in = signed_in?(resource_name)
sign_out(resource_name) if signed_in
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
yield resource if block_given?
2014-03-25 09:47:44 +00:00
render(json: {success: signed_in})
2011-03-06 18:28:00 +00:00
end
end