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

22 lines
500 B
Ruby
Raw Normal View History

2011-03-06 18:28:00 +00:00
class SessionsController < Devise::SessionsController
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 11:37:18 +00:00
resource = warden.authenticate(scope: resource_name)
2011-03-07 02:40:29 +00:00
if resource
sign_in(resource_name, resource)
2012-06-18 17:49:28 +00:00
render(json: resource)
2011-03-07 02:40:29 +00:00
else
2012-06-18 17:49:28 +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
2012-06-18 17:49:28 +00:00
render(json: {success: signed_in})
2011-03-06 18:28:00 +00:00
end
end