Class: V1::AuthorizationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- V1::AuthorizationsController
- Defined in:
- app/controllers/v1/authorizations_controller.rb
Overview
User authorization, get access token.
Instance Method Summary collapse
-
#create ⇒ User
Create a access token POST /v1/authorizations.
Instance Method Details
#create ⇒ User
Create a access token
POST /v1/
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/v1/authorizations_controller.rb', line 17 def create # Blank Email/Password if params[:user].blank? || params[:user][:email].blank? || params[:user][:password].blank? render json: { error: 'Blank Email/Password!' }, status: :bad_request return end @user = User.find_by(email: params[:user][:email]) # Invalid Email/Password if !@user || !@user.valid_password?(params[:user][:password]) render json: { error: "Invalid Email/Password!" }, status: :unauthorized return end render json: access_token, status: :created end |