2024-06-30 06:31:21 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Settings::UsersController < ApplicationController
|
2024-11-08 15:28:45 -05:00
|
|
|
before_action :authenticate_user!
|
2024-07-16 16:26:16 -04:00
|
|
|
before_action :authenticate_admin!
|
2024-06-30 06:31:21 -04:00
|
|
|
|
2024-11-08 11:56:14 -05:00
|
|
|
def index
|
|
|
|
|
@users = User.order(created_at: :desc)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
|
|
|
|
|
if @user.update(user_params)
|
|
|
|
|
redirect_to settings_users_url, notice: 'User was successfully updated.'
|
|
|
|
|
else
|
|
|
|
|
redirect_to settings_users_url, notice: 'User could not be updated.', status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-06-30 06:31:21 -04:00
|
|
|
def create
|
|
|
|
|
@user = User.new(
|
|
|
|
|
email: user_params[:email],
|
|
|
|
|
password: 'password',
|
|
|
|
|
password_confirmation: 'password'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if @user.save
|
2024-11-08 11:56:14 -05:00
|
|
|
redirect_to settings_users_url,
|
2024-07-16 16:26:16 -04:00
|
|
|
notice: "User was successfully created, email is #{@user.email}, password is \"password\"."
|
2024-06-30 06:31:21 -04:00
|
|
|
else
|
2024-11-08 11:56:14 -05:00
|
|
|
redirect_to settings_users_url, notice: 'User could not be created.', status: :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
|
|
|
|
|
|
if @user.destroy
|
|
|
|
|
redirect_to settings_url, notice: 'User was successfully deleted.'
|
|
|
|
|
else
|
|
|
|
|
redirect_to settings_url, notice: 'User could not be deleted.', status: :unprocessable_entity
|
2024-06-30 06:31:21 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def user_params
|
|
|
|
|
params.require(:user).permit(:email)
|
|
|
|
|
end
|
|
|
|
|
end
|