From 783565dd8fe70063df70dc919228dc6814875f2a Mon Sep 17 00:00:00 2001 From: Arief Kurniawan <78076941+arief-github@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:11:54 +0700 Subject: [PATCH] feat: add 2FA in Profile, Donatur, Donation and Campaign model and ctrl --- .../Controllers/Admin/DonationController.php | 47 +++++ .../Controllers/Admin/DonaturController.php | 20 ++ .../Controllers/Admin/ProfileController.php | 19 ++ .../Controllers/Api/CampaignController.php | 61 ++++++ app/Models/User.php | 3 +- .../views/admin/donation/index.blade.php | 99 ++++++++++ resources/views/admin/donatur/index.blade.php | 66 +++++++ resources/views/admin/profile/index.blade.php | 178 ++++++++++++++++++ .../views/auth/confirm-password.blade.php | 37 ++++ .../views/auth/two-factor-challenge.blade.php | 52 +++++ resources/views/layouts/app.blade.php | 23 ++- routes/api.php | 7 + routes/web.php | 9 + 13 files changed, 611 insertions(+), 10 deletions(-) create mode 100644 app/Http/Controllers/Admin/DonationController.php create mode 100644 app/Http/Controllers/Admin/DonaturController.php create mode 100644 app/Http/Controllers/Admin/ProfileController.php create mode 100644 app/Http/Controllers/Api/CampaignController.php create mode 100644 resources/views/admin/donation/index.blade.php create mode 100644 resources/views/admin/donatur/index.blade.php create mode 100644 resources/views/admin/profile/index.blade.php create mode 100644 resources/views/auth/confirm-password.blade.php create mode 100644 resources/views/auth/two-factor-challenge.blade.php diff --git a/app/Http/Controllers/Admin/DonationController.php b/app/Http/Controllers/Admin/DonationController.php new file mode 100644 index 0000000..b61a5ac --- /dev/null +++ b/app/Http/Controllers/Admin/DonationController.php @@ -0,0 +1,47 @@ +validate($request, [ + 'date_from' => 'required', + 'date_to' => 'required' + ]); + + $date_from = $request->date_from; + $date_to = $request->date_to; + + // get data donation by range date + $donations = Donation::where('status', 'success') + ->whereDate('created_at', '>=', $request->date_from) + ->whereDate('created_at', '<=', $request->date_to) + ->get(); + + // get total donation by range date + $total = Donation::where('status', 'success') + ->whereDate('created_at', '>=', $request->date_from) + ->whereDate('created_at', '<=', $request->date_to) + ->sum('amount'); + + return view('admin.donation.index', compact('donations', 'total')); + } +} diff --git a/app/Http/Controllers/Admin/DonaturController.php b/app/Http/Controllers/Admin/DonaturController.php new file mode 100644 index 0000000..282e027 --- /dev/null +++ b/app/Http/Controllers/Admin/DonaturController.php @@ -0,0 +1,20 @@ +when(request()->q, function($donaturs) { + $donaturs = $donaturs->where('name', 'like', '%'. request()->q . '%'); + })->paginate(10); + + return view('admin.donatur.index', compact('donaturs')); + } +} diff --git a/app/Http/Controllers/Admin/ProfileController.php b/app/Http/Controllers/Admin/ProfileController.php new file mode 100644 index 0000000..9024a74 --- /dev/null +++ b/app/Http/Controllers/Admin/ProfileController.php @@ -0,0 +1,19 @@ +with('sumDonation')->when(request()->q, function($campaigns) { + $campaigns = $campaigns->where('title', 'like', '%'.request()->q.'%'); + })->latest()->paginate(5); + + // return with response JSON + return response()->json([ + 'success' => true, + 'message' => 'List Data Campaigns', + 'data' => $campaigns, + ], 200); + } + + /** + * A description of the entire PHP function. + * + * @param datatype $slug description + * @throws Some_Exception_Class description of exception + * @return Some_Return_Value + */ + + public function show($slug) + { + // get data campaign by slug + $campaign = Campaign::with('user')->with('sumDonation')->where('slug', $slug)->first(); + + // get data donation by campaign + $donations = Donation::with('donatur')->where('campaign_id', $campaign->id)->where('status', 'success')->latest()->get(); + + if(!$campaign) { + return response()->json([ + 'success' => false, + 'message' => 'Data Campaign Tidak Ditemukan', + ], 404); + } + + return response()->json([ + 'success' => true, + 'message' => 'Detail Data Campaign : '.$campaign->title, + 'data' => $campaign, + 'donations' => $donations + ], 200); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index ac420ab..10c6d4e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Laravel\Fortify\TwoFactorAuthenticatable; class User extends Authenticatable { - use HasFactory, Notifiable; + use HasFactory, Notifiable, TwoFactorAuthenticatable; /** * The attributes that are mass assignable. diff --git a/resources/views/admin/donation/index.blade.php b/resources/views/admin/donation/index.blade.php new file mode 100644 index 0000000..4de4db1 --- /dev/null +++ b/resources/views/admin/donation/index.blade.php @@ -0,0 +1,99 @@ +@extends('layouts.app', ['title' => 'Donation - Admin']) + +@section('content') +
+
+
+
+
+ + + @error('date_from') +
+
+

{{ $message }}

+
+
+ @enderror +
+ +
+ + + @error('date_to') +
+
+

{{ $message }}

+
+
+ @enderror +
+ +
+ +
+
+
+ + @if($donations ?? '') + @if(count($donations) > 0) +
+
+ + + + + + + + + + + @forelse($donations as $donation) + + + + + + + @empty +
+ Data Belum Tersedia! +
+ @endforelse + + + + + +
+ NAMA DONATUR + + CAMPAIGN + + TANGGAL + + JUMLAH DONASI +
+ {{ $donation->donatur->name }} + + {{ $donation->campaign->title }} + + {{ $donation->created_at }} + + {{ moneyFormat($donation->amount) }} +
+ TOTAL DONASI + + {{ moneyFormat($total) }} +
+
+
+ @endif + @endif +
+
+@endsection \ No newline at end of file diff --git a/resources/views/admin/donatur/index.blade.php b/resources/views/admin/donatur/index.blade.php new file mode 100644 index 0000000..40900a6 --- /dev/null +++ b/resources/views/admin/donatur/index.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.app', ['title' => 'Donatur - Admin']) + +@section('content') +
+
+ +
+
+ + + + + +
+ +
+
+
+ +
+
+ + + + + + + + + @forelse($donaturs as $donatur) + + + + + + + + @empty +
+ Data Belum Tersedia! +
+ @endforelse + +
+ NAMA LENGKAP + + EMAIL +
+ {{ $donatur->name }} + + {{ $donatur->email }} +
+ @if ($donaturs->hasPages()) +
+ {{ $donaturs->links('vendor.pagination.tailwind') }} +
+ @endif +
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/admin/profile/index.blade.php b/resources/views/admin/profile/index.blade.php new file mode 100644 index 0000000..7ab6b3d --- /dev/null +++ b/resources/views/admin/profile/index.blade.php @@ -0,0 +1,178 @@ +@extends('layouts.app', ['title' => 'Profile - Admin']) + +@section('content') +
+
+ @if (session('status')) +
+ @if(session('status') == 'profile-information-update') + Profile has been updated! + @endif + @if(session('status') == 'password-updated') + Password has been updated! + @endif + @if(session('status') == 'two-factor-authentication-disabled') + Two factor authentication disabled + @endif + @if(session('status') == 'two-factor-authentication-enabled') + Two factor authentication enabled + @endif + @if(session('status') == 'recovery-codes-generated') + Recovery codes generated + @endif +
+ @endif +
+
+ @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::twoFactorAuthentication())) +
+

TWO-FACTOR AUTHENTICATION

+
+ +
+ @if(! auth()->user()->two_factor_secret) + {{-- Enable 2FA --}} +
+ @csrf + + +
+ @else + {{-- Disable 2FA --}} +
+ @csrf + @method('DELETE') + + +
+ + @if(session('status') == 'two-factor-authentication-enabled') + {{-- Show SVG QR Code, After Enabling 2FA --}} +
+ Otentikasi dua faktor sekarang diaktifkan. Pindai kode QR berikut menggunakan aplikasi + pengautentikasi ponsel Anda. +
+ +
+ {!! auth()->user()->twoFactorQrCodeSvg() !!} +
+ @endif + + {{-- Show 2FA Recovery Codes --}} +
+ Simpan recovery code ini dengan aman. Ini dapat digunakan untuk memulihkan akses ke akun + Anda jika perangkat otentikasi dua faktor Anda hilang. +
+ +
+ @foreach (json_decode(decrypt(auth()->user()->two_factor_recovery_codes), true) as $code) +
{{ $code }}
+ @endforeach +
+ + {{-- Regenerate 2FA Recovery Codes --}} +
+ @csrf + + +
+ @endif +
+ +
+ @endif +
+
+
+

EDIT PROFILE

+
+
+ @csrf + @method('PUT') +
+ +
+
+ +
+
+ +
+
+
+ +
+

UPDATE PASSWORD

+
+
+ @csrf + @method('PUT') +
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/auth/confirm-password.blade.php b/resources/views/auth/confirm-password.blade.php new file mode 100644 index 0000000..46e9f60 --- /dev/null +++ b/resources/views/auth/confirm-password.blade.php @@ -0,0 +1,37 @@ +@extends('layouts.auth', ['title' => 'Confirm Password - Admin']) + +@section('content') +
+
+
+ confirm password +
+ @if(session('status')) +
+ {{ session('status') }} +
+ @endif +
+ @csrf + + + +
+ +
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/auth/two-factor-challenge.blade.php b/resources/views/auth/two-factor-challenge.blade.php new file mode 100644 index 0000000..e071267 --- /dev/null +++ b/resources/views/auth/two-factor-challenge.blade.php @@ -0,0 +1,52 @@ +@extends('layouts.auth', ['title' => 'Two Factor Challenge - Admin']) + +@section('content') +
+
+
+ two factor challenge +
+ @if(session('status')) +
+ {{ session('status') }} +
+ @endif +
+ @csrf + + +

+ Atau anda dapat memasukkan salah satu recovery code +

+ + + +
+ +
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 66002b8..373fd47 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -60,21 +60,26 @@ Campaigns - - Donatur Icon + + Icon Donatur Donatur - + Icon Donation - Donations + Donasi - - Icon Profile + + Icon Kategory Profil Saya - + + {{ Request::is('admin/slider*') ? 'bg-gray-700 bg-opacity-25 text-gray-100' : 'text-gray-500' }}" href="{{ route('admin.slider.index') }}"> Icon Sliders Sliders diff --git a/routes/api.php b/routes/api.php index 2ccb551..70ee3f6 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Api\CampaignController; use App\Http\Controllers\Api\CategoryController; use App\Http\Controllers\Api\SliderController; @@ -27,6 +28,12 @@ Route::get('/category/{slug}',[CategoryController::class, 'show']); Route::get('/category-home',[CategoryController::class, 'categoryHome']); +/** + * API Donation + */ +Route::get('/campaign', [CampaignController::class, 'index']); +Route::get('/campaign/{slug}', [CampaignController::class, 'show']); + /** * API Slider */ diff --git a/routes/web.php b/routes/web.php index a1fe127..f8df971 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,6 +5,9 @@ use App\Http\Controllers\Admin\CategoryController; use App\Http\Controllers\Admin\SliderController; use App\Http\Controllers\Admin\CampaignController; +use App\Http\Controllers\Admin\DonaturController; +use App\Http\Controllers\Admin\ProfileController; +use App\Http\Controllers\Admin\DonationController; /* |-------------------------------------------------------------------------- @@ -27,6 +30,12 @@ return view('admin.dashboard.index'); }); + Route::get('/donatur', [DonaturController::class, 'index'])->name('admin.donatur.index'); + Route::get('/profile', [ProfileController::class, 'index'])->name('admin.profile.index'); + + Route::get('/donation',[DonationController::class, 'index'])->name('admin.donation.index'); + Route::get('/donation/filter', [DonationController::class, 'filter'])->name('admin.donation.filter'); + Route::resource('/category', CategoryController::class, ['as' => 'admin']); Route::resource('/slider', SliderController::class, ['except' => ['show', 'create', 'edit', 'update'], 'as' => 'admin']); Route::resource('/campaign', CampaignController::class, ['as' => 'admin']);