diff --git a/Web-Application/Manually/app/Http/Controllers/Auth/PasswordController.php b/Web-Application/Manually/app/Http/Controllers/Auth/PasswordController.php index fbc8b15..9e1ecbe 100644 --- a/Web-Application/Manually/app/Http/Controllers/Auth/PasswordController.php +++ b/Web-Application/Manually/app/Http/Controllers/Auth/PasswordController.php @@ -6,6 +6,8 @@ use App\Models\User; use Illuminate\Support\Str; use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use App\Http\Requests\ChangePasswordRequest; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Password; use Illuminate\Auth\Events\PasswordReset; @@ -54,4 +56,23 @@ class PasswordController extends Controller ? redirect()->route('login')->with('status', __($status)) : back()->withErrors(['email' => [__($status)]]); } + + public function changePasswordPage() + { + $user = Auth::user(); + return view('auth.change-password', compact('user')); + } + + public function changePassword(ChangePasswordRequest $request) + { + $inputs = $request->all(); + + $user = Auth::user(); + + $user->update([ + 'password' => Hash::make($inputs['password']), + ]); + + return redirect()->route('dashboard')->with('success', 'Password updated successfully.'); + } } diff --git a/Web-Application/Manually/app/Http/Controllers/Auth/ProfileController.php b/Web-Application/Manually/app/Http/Controllers/Auth/ProfileController.php new file mode 100644 index 0000000..27152cd --- /dev/null +++ b/Web-Application/Manually/app/Http/Controllers/Auth/ProfileController.php @@ -0,0 +1,39 @@ +user = Auth::user(); + } + public function showProfile() + { + $user = $this->user; + return view("auth.profile", compact("user")); + } + + public function updateProfile(ProfileRequest $request) + { + $inputs = $request->only('name', 'email'); + $data = ['name' => $inputs['name']]; + + if ($inputs['email'] !== $this->user->email) { + $data['email'] = $inputs['email']; + $data['email_verified_at'] = null; + $data['remember_token'] = null; + } + + $this->user->update($data); + + return redirect()->route("dashboard")->with("success", "Profile updated successfully."); + } +} diff --git a/Web-Application/Manually/app/Http/Requests/ChangePasswordRequest.php b/Web-Application/Manually/app/Http/Requests/ChangePasswordRequest.php new file mode 100644 index 0000000..8a0bfb3 --- /dev/null +++ b/Web-Application/Manually/app/Http/Requests/ChangePasswordRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + 'password' => 'required|min:8|confirmed', + ]; + } +} diff --git a/Web-Application/Manually/app/Http/Requests/ProfileRequest.php b/Web-Application/Manually/app/Http/Requests/ProfileRequest.php new file mode 100644 index 0000000..5acfb6f --- /dev/null +++ b/Web-Application/Manually/app/Http/Requests/ProfileRequest.php @@ -0,0 +1,29 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'email' => 'required|email|unique:users,email,' . auth()->id(), + ]; + } +} diff --git a/Web-Application/Manually/app/Models/User.php b/Web-Application/Manually/app/Models/User.php index 3ccce93..535af62 100644 --- a/Web-Application/Manually/app/Models/User.php +++ b/Web-Application/Manually/app/Models/User.php @@ -25,7 +25,9 @@ class User extends Authenticatable implements MustVerifyEmail 'github_token', 'github_refresh_token', 'google2fa_secret', - 'verify2fa' + 'verify2fa', + 'email_verified_at', + 'remember_token' ]; /** diff --git a/Web-Application/Manually/resources/views/auth/change-password.blade.php b/Web-Application/Manually/resources/views/auth/change-password.blade.php new file mode 100644 index 0000000..ebf31ea --- /dev/null +++ b/Web-Application/Manually/resources/views/auth/change-password.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.aside') + +@section('main') + +
+
+ +

Change Password

+ +
+ @csrf + +
+ + +

@error('current_password') {{ $message }} @enderror

+
+ +
+ + +

@error('password') {{ $message }} @enderror

+
+ +
+ + +
+ +
+ +
+
+ +
+
+ + +@endsection \ No newline at end of file diff --git a/Web-Application/Manually/resources/views/auth/profile.blade.php b/Web-Application/Manually/resources/views/auth/profile.blade.php new file mode 100644 index 0000000..1fc6b5b --- /dev/null +++ b/Web-Application/Manually/resources/views/auth/profile.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.aside') + +@section('main') +
+
+ +

Edit Profile

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

@error('name') {{ $message }} @enderror

+
+ +
+ + +

@error('email') {{ $message }} @enderror

+
+ +
+ +
+
+ +
+
+ + + + + +@endsection \ No newline at end of file diff --git a/Web-Application/Manually/resources/views/dashboard.blade.php b/Web-Application/Manually/resources/views/dashboard.blade.php index 1fc82bb..9f86868 100644 --- a/Web-Application/Manually/resources/views/dashboard.blade.php +++ b/Web-Application/Manually/resources/views/dashboard.blade.php @@ -1,102 +1,64 @@ -@extends('layouts.app') +@extends('layouts.aside') -@section('content') -
- +
-
-
-

- {{ $user->email }} -

- - @if (session('success')) -
- {{ session('success') }} - -
- @endif - -
- - {{-- Email Verification --}} -
- @if (!$user->email_verified_at) -
- @csrf - -
-

Your email is not verified.

- @else -
- ✅ Your Email Is Verified -
- @endif + {{-- Email Verification --}} +
+ @if (!$user->email_verified_at) +
+ @csrf + +
+

Your email is not verified.

+ @else +
+ ✅ Your Email Is Verified
+ @endif +
- {{-- Two Factor Authentication --}} -
- @if (!$user->google2fa_secret) -
- @csrf - -
- @else -
- @csrf - -
- @endif -
+ {{-- Two Factor Authentication --}} +
+ @if (!$user->google2fa_secret) +
+ @csrf + +
+ @else +
+ @csrf + +
+ @endif
-
+
+ diff --git a/Web-Application/Manually/resources/views/layouts/aside.blade.php b/Web-Application/Manually/resources/views/layouts/aside.blade.php new file mode 100644 index 0000000..2c59536 --- /dev/null +++ b/Web-Application/Manually/resources/views/layouts/aside.blade.php @@ -0,0 +1,44 @@ +@extends('layouts.app') + +@section('content') +
+ + + @yield('main') + @endsection \ No newline at end of file diff --git a/Web-Application/Manually/routes/web.php b/Web-Application/Manually/routes/web.php index c84faf0..c250928 100644 --- a/Web-Application/Manually/routes/web.php +++ b/Web-Application/Manually/routes/web.php @@ -8,6 +8,7 @@ use App\Http\Controllers\DashboardController; use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\LogoutController; use App\Http\Controllers\Auth\PasswordController; +use App\Http\Controllers\Auth\ProfileController; use App\Http\Controllers\Auth\RegisterController; use App\Http\Controllers\Auth\TwoFactorAuthenticationController; @@ -37,6 +38,14 @@ Route::group(['middleware' => 'auth'], function () { Route::post('disable-2fa', [TwoFactorAuthenticationController::class, 'disable2FA'])->name('disable.2fa'); Route::get('secret-code-show', [TwoFactorAuthenticationController::class, 'secretCodeShow'])->name('secret.code.show'); Route::post('secret-code', [TwoFactorAuthenticationController::class, 'secretCode'])->name('secret.code'); + + //profile + Route::get('profile', [ProfileController::class, 'showProfile'])->name('profile.show'); + Route::put('profile', [ProfileController::class, 'updateProfile'])->name('profile.update'); + + //change password in profile + Route::get('change-password', [PasswordController::class, 'changePasswordPage'])->name('change.password.show'); + Route::post('change-password', [PasswordController::class, 'changePassword'])->name('change.password'); });