Advertisement
mfirmanakbar

login_api_controller.rb

May 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.31 KB | None | 0 0
  1.  
  2. class LoginApiController < ApplicationController
  3.  
  4.   def auth
  5.     user = User.find_by(username: params[:username])
  6.     if user && user.authenticate(params[:password])
  7.       render json: user
  8.     else
  9.       render json: { errors: ["wrong username or password"] }, status: :unauthorized
  10.     end
  11.   end
  12.  
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement