refactor: ⚡ Username and slug unique indexes, before actions for set link and user
confirm_password_validation around action, unnecessary helpers removed, rubocop-rails suggestions applied Add username index and unique slug index migrations
This commit is contained in:
@@ -1,22 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UsersController < ApplicationController
|
||||
def create
|
||||
if user_params[:password] != params[:user][:confirm_password]
|
||||
return render json: { password: ['Password not match with Confirm Password'] }, status: :bad_request
|
||||
end
|
||||
around_action :confirm_password_validation, only: %i[create]
|
||||
|
||||
def create
|
||||
@user = User.create(user_params)
|
||||
if @user.errors.any?
|
||||
render json: @user.errors, status: :unprocessable_entity
|
||||
else
|
||||
session[:user_id] = @user.id
|
||||
session[:username] = @user.username
|
||||
render json: nil, status: :ok
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def confirm_password_validation
|
||||
if user_params[:password] == params[:user][:confirm_password]
|
||||
yield
|
||||
else
|
||||
render json: { password: ['Password not match with Confirm Password'] }, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:username, :password)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user