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]
|
2013-12-02 21:47:02 +00:00
|
|
|
|
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
|
2013-12-02 12:07:18 +00:00
|
|
|
self.resource = warden.authenticate!(auth_options)
|
2011-03-07 02:40:29 +00:00
|
|
|
if resource
|
|
|
|
sign_in(resource_name, resource)
|
2013-12-02 12:07:18 +00:00
|
|
|
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
|
2013-12-02 12:07:18 +00:00
|
|
|
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
|