Skip to content

Instantly share code, notes, and snippets.

@waaadim
Created June 27, 2014 09:39
Show Gist options
  • Save waaadim/62b9f899ecc14dd72f66 to your computer and use it in GitHub Desktop.
Save waaadim/62b9f899ecc14dd72f66 to your computer and use it in GitHub Desktop.
class SessionsController < Devise::SessionsController
# skip_before_filter :require_no_authentication
def create
# raise user_signed_in?.inspect
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_flashing_format?
resource.authentication_token = nil
resource.save!
sign_in(resource_name, resource)
yield resource if block_given?
data = { id: resource.id, nickname: resource.nickname, email: resource.email, token: resource.authentication_token }
render_response({status: 'success', data: data })
end
def destroy
# TODO: regenerate token
super
end
protected
def auth_options
{ scope: resource_name, recall: "#{controller_path}#new" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment