Class: Api::V1::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/jwt_api/templates/api/v1/users_controller.rb

Overview

User controller

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 7

def create
  unless user_params[:password] == user_params[:password_confirmation]
    return render json: { message: "passwords don't match" }, status: :unprocessable_entity
  end

  user = User.new(user_params)
  user.jti = SecureRandom.uuid
  if user.save
    render partial: 'users/user', locals: { user: user }, status: :created
  else
    render json: user.errors, status: :unprocessable_entity
  end
end

#destroyObject



31
32
33
34
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 31

def destroy
  @current_user.destroy
  head :no_content
end

#meObject

‘/api/v1/me’



22
23
24
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 22

def me
  render partial: 'users/user', locals: { user: @current_user }
end

#updateObject



26
27
28
29
# File 'lib/generators/jwt_api/templates/api/v1/users_controller.rb', line 26

def update
  @current_user.update(user_params.except(:password_confirmation, :reset_password_token))
  render partial: 'users/user', locals: { user: @current_user }
end