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

27 lines
729 B
Ruby
Raw Normal View History

2011-03-06 18:28:00 +00:00
class SessionsController < Devise::SessionsController
skip_before_filter :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?
render(:json => resource)
2011-03-07 02:40:29 +00:00
else
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?
render(:json => {:success => signed_in})
2011-03-06 18:28:00 +00:00
end
end