Commit 271f536c by Siti Aisah

Merge branch 'master' of http://git.unesa.ac.id/aisah/sipeka

parents 76637fcc c0b63a66
......@@ -70,6 +70,8 @@ public function update(Request $request, $id){
DB::beginTransaction();
try{
$id = decrypt($id);
$kategori = [
'kode_kategori' => strip_tags($request->kodekategori),
'nama_kategori' => strip_tags($request->namakategori),
......@@ -94,6 +96,8 @@ public function update(Request $request, $id){
}
public function destroy($id) {
$id = decrypt($id);
DB::beginTransaction();
try{
......@@ -102,14 +106,14 @@ public function destroy($id) {
DB::commit();
return Redirect::route('kategori.index')
->with('success', 'Data kategori berhasil diupdate');
->with('success', 'Data kategori berhasil dihapus');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return Redirect::route('kategori.index')
->with('error', 'Data kategori gagal diupdate');
->with('error', 'Data kategori gagal dihapus');
}
}
}
......@@ -3,9 +3,128 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Support\ValidationRule;
use App\Models\Admin\User;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
class UserController extends Controller
{
//
public function index(){
$user = User::query()->get();
$data = [
'user' => $user
];
return view('Admin.User.index', $data);
}
public function store(Request $request){
$rule = [
'name' => 'required|string',
'email' => 'required|email:rfc,dns',
'password' => 'required|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/|min:8',
];
$request->validate($rule, ValidationRule::getErrorMessage($rule));
DB::beginTransaction();
try{
$user = [
'name' => strip_tags($request->name),
'email' => strip_tags($request->email),
'password' => strip_tags($request->password),
];
User::query()->create($user);
DB::commit();
return Redirect::route('user.index')
->with('success', 'User berhasil ditambahkan');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return Redirect::route('user.index')
->with('error', 'User gagal ditambahkan');
}
}
public function update(Request $request, $id){
$rule = [
'name' => 'required|string',
'email' => 'required|email:rfc,dns',
'passwordbaru' => 'required|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/|min:8',
'passwordlama' => 'required|string'
];
$request->validate($rule, ValidationRule::getErrorMessage($rule));
DB::beginTransaction();
try{
$id = decrypt($id);
$passwordbaru = Hash::make(strip_tags($request->passwordbaru));
$passwordlama = strip_tags($request->passwordlama);
$oldpassword = User::where('id', $id)->first();
// if (Hash::check($passwordlama, $oldpassword->password)) {
// // Passwords match
$user = [
'name' => strip_tags($request->name),
'email' => strip_tags($request->email),
'password' => $passwordbaru
];
User::where('id', $id)->update($user);
DB::commit();
return Redirect::route('user.index')
->with('success', 'User berhasil diupdate');
// } else {
// // Passwords do not match
// return Redirect::route('user.index')
// ->with('error', 'Password lama tidak valid');
// }
}
catch(Exception $e){
dd($e);
Log::error($e);
DB::rollBack();
return Redirect::route('user.index')
->with('error', 'User gagal diupdate');
}
}
public function destroy($id) {
$id = decrypt($id);
DB::beginTransaction();
try{
User::where('id', $id)->delete();
DB::commit();
return Redirect::route('user.index')
->with('success', 'User berhasil dihapus');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return Redirect::route('user.index')
->with('error', 'User gagal dihapus');
}
}
}
......@@ -7,6 +7,10 @@ class ValidationRule{
'required' => 'can not be empty',
'numeric' => 'must be a number',
'string' => 'must be a string',
'unique' => 'must be unique',
'required' => 'must be filled',
'numeric' => 'must be numeric',
'regex' => 'must be a combination of uppercase letters, lowercase letters, numbers and characters',
'max' => 'must be maximum',
'min' => 'must be minimum',
'email' => 'is invalid',
......
......@@ -8,4 +8,16 @@
class User extends Model
{
use HasFactory;
public $incrementing = false;
protected $table = 'users';
protected $keyType = 'string';
protected $fillable = [
'id',
'name',
'email',
'password',
];
}
......@@ -55,7 +55,7 @@
<div class="modal fade" id="editKategoriModal{{$kat->id}}" tabindex="-1" aria-labelledby="tambahAntrian" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form method="POST" action="{{ route('kategori.update', ['kategori' => $kat->id]) }}" enctype="multipart/form-data" id="registrasi">
<form method="POST" action="{{ route('kategori.update', ['kategori' => encrypt($kat->id)]) }}" enctype="multipart/form-data" id="registrasi">
@method('PUT')
@csrf
<div class="modal-header">
......@@ -108,7 +108,7 @@
<div class="modal fade" id="deleteKategoriModal{{$kat->id}}" tabindex="-1" aria-labelledby="tambahAntrian" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form method="POST" action="{{ route('kategori.destroy', ['kategori' => $kat->id ]) }}" enctype="multipart/form-data">
<form method="POST" action="{{ route('kategori.destroy', ['kategori' => encrypt($kat->id) ]) }}" enctype="multipart/form-data">
@csrf
@method("DELETE")
<div class="modal-header">
......@@ -120,7 +120,7 @@
</div>
<div class="form-group" style="text-align: center">
<button type="submit" class="btn btn-primary ml-1">Delete</button>
<button type="button" class="btn btn-light-secondary" data-dismiss="modal">Cancel</button>
<button type="reset" class="btn btn-outline-secondary" data-bs-dismiss="modal" aria-label="Close">Cancel</button>
</div>
</div>
</form>
......
......@@ -5,7 +5,7 @@
<ul class="dropdown-menu" data-bs-popper="none">
<li data-menu="" class="{{ (request()->getRequestUri() == "/kategori") ? 'active' : '' }}"><a href="{{route('kategori.index')}}" class="dropdown-item d-flex align-items-center" data-bs-toggle="" data-i18n="Email" ><i data-feather="grid"></i><span data-i18n="Email">Master Kategori</span></a>
</li>
<li data-menu="" class="{{ (request()->is('admin/dokter')) ? 'active' : '' }}"><a href="#" class="dropdown-item d-flex align-items-center" data-bs-toggle="" data-i18n="Email" ><i data-feather='user'></i><span data-i18n="Email">Master User</span></a>
<li data-menu="" class="{{ (request()->getRequestUri() == "/user") ? 'active' : '' }}"><a href="{{route('user.index')}}" class="dropdown-item d-flex align-items-center" data-bs-toggle="" data-i18n="Email" ><i data-feather='user'></i><span data-i18n="Email">Master User</span></a>
</li>
</ul>
</li>
......
......@@ -4,6 +4,7 @@
use App\Http\Controllers\Admin\KategoriController;
use App\Http\Controllers\Admin\TransaksiController;
use App\Http\Controllers\Admin\SakuController;
use App\Http\Controllers\Admin\UserController;
use Illuminate\Support\Facades\Route;
/*
......@@ -30,5 +31,6 @@
Route::resource('kategori', KategoriController::class);
Route::resource('transaksi', TransaksiController::class);
Route::resource('saku', SakuController::class);
Route::resource('user', UserController::class);
Route::get('/logout', [LoginController::class, 'logout'])->name('admin.logout');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment