Created
April 8, 2014 10:14
-
-
Save qoobaa/10106882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class V1::Client::SessionsController < V1::Client::ApplicationController | |
skip_before_action :authenticate, only: %i[create] | |
def create | |
@session = ::Client::Session.new(session_params) | |
@session.save | |
respond_with @session, location: nil | |
end | |
private | |
def session_params | |
params.require(:session).permit(:email, :password) | |
end | |
end | |
class Client::Session < ActiveModel::Session | |
def email=(email) | |
@email = email | |
@user = Client.find_by(email: email) | |
end | |
def save | |
valid? and user.generate_authentication_token! | |
end | |
def as_json(*) | |
{authentication_token: user.try(:authentication_token)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment