Skip to content

Instantly share code, notes, and snippets.

@StasKoval
Created March 1, 2015 15:44
Show Gist options
  • Save StasKoval/918f2d869595d521133f to your computer and use it in GitHub Desktop.
Save StasKoval/918f2d869595d521133f to your computer and use it in GitHub Desktop.
class Api::SessionsController < ApplicationController
before_action :current_user, except: :create
def show
render json: @user, serializer: UserSerializer
end
def create
@auth = false
if params[:password].present?
@user = User.where(email:params[:email]).first if params[:email].present?
if @user && @user.authenticate(params[:password])
@auth = true
end
else
authenticate_with_http_token do |token, options|
@user = User.where(auth_token: token).first
@user.type.constantize.find(@user.id)
@auth = true
end
end
if @auth
render json: UserTokenSerializer.new(@user)
else
render nothing: true, status: 403
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment