API de comptabilité horaire.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tokens_controller.rb 514B

123456789101112131415161718192021
  1. class Api::V1::TokensController < ApplicationController
  2. def create
  3. @user = User.find_by_email(user_params[:email])
  4. if @user&.authenticate(user_params[:password])
  5. render json: {
  6. token: JsonWebToken.encode(user_id: @user.id),
  7. email: @user.email,
  8. username: @user.username
  9. }
  10. else
  11. head :unauthorized
  12. end
  13. end
  14. private
  15. # Only allow a trusted parameter "white list" through.
  16. def user_params
  17. params.require(:user).permit(:email, :password)
  18. end
  19. end