API de comptabilité horaire.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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