mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 14:58:07 -05:00
55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Settings::UsersController < ApplicationController
|
|
before_action :authenticate_self_hosted!
|
|
before_action :authenticate_admin!
|
|
|
|
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
|
|
|
|
def create
|
|
@user = User.new(
|
|
email: user_params[:email],
|
|
password: user_params[:password],
|
|
password_confirmation: user_params[:password]
|
|
)
|
|
|
|
if @user.save
|
|
redirect_to settings_users_url, notice: 'User was successfully created'
|
|
else
|
|
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
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def user_params
|
|
params.require(:user).permit(:email, :password)
|
|
end
|
|
end
|