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 480B

1234567891011121314151617181920
  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. }
  9. else
  10. head :unauthorized
  11. end
  12. end
  13. private
  14. # Only allow a trusted parameter "white list" through.
  15. def user_params
  16. params.require(:user).permit(:email, :password)
  17. end
  18. end