implement profile page for change password and change name,email
This commit is contained in:
parent
ef378d450d
commit
6e8f115396
@ -6,6 +6,8 @@ use App\Models\User;
|
|||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\ChangePasswordRequest;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Password;
|
use Illuminate\Support\Facades\Password;
|
||||||
use Illuminate\Auth\Events\PasswordReset;
|
use Illuminate\Auth\Events\PasswordReset;
|
||||||
@ -54,4 +56,23 @@ class PasswordController extends Controller
|
|||||||
? redirect()->route('login')->with('status', __($status))
|
? redirect()->route('login')->with('status', __($status))
|
||||||
: back()->withErrors(['email' => [__($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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\ProfileRequest;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class ProfileController extends Controller
|
||||||
|
{
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ChangePasswordRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'password' => 'required|min:8|confirmed',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ProfileRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'email' => 'required|email|unique:users,email,' . auth()->id(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,7 +25,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
'github_token',
|
'github_token',
|
||||||
'github_refresh_token',
|
'github_refresh_token',
|
||||||
'google2fa_secret',
|
'google2fa_secret',
|
||||||
'verify2fa'
|
'verify2fa',
|
||||||
|
'email_verified_at',
|
||||||
|
'remember_token'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
@extends('layouts.aside')
|
||||||
|
|
||||||
|
@section('main')
|
||||||
|
|
||||||
|
<main class="min-h-screen w-full flex items-center justify-center bg-[#0d1b2a] overflow-auto py-5">
|
||||||
|
<div class="bg-[#1b263b] p-8 rounded-xl shadow-2xl max-w-[800px] w-full transition-all duration-300">
|
||||||
|
|
||||||
|
<h1 class="text-3xl font-semibold text-center text-[#e0e1dd] mb-10">Change Password</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('change.password') }}" method="POST" class="space-y-6">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="current_password" class="block text-[#e0e1dd] mb-2">Current Password</label>
|
||||||
|
<input type="password" id="current_password" name="current_password" value="{{$user->password}}"
|
||||||
|
class="w-full px-4 py-3 rounded-lg bg-[#415a77] text-white placeholder-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||||
|
<p class="w-full text-red-500 text-sm mt-1">@error('current_password') {{ $message }} @enderror</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="password" class="block text-[#e0e1dd] mb-2">New Password</label>
|
||||||
|
<input type="password" id="password" name="password"
|
||||||
|
class="w-full px-4 py-3 rounded-lg bg-[#415a77] text-white placeholder-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||||
|
<p class="w-full text-red-500 text-sm mt-1">@error('password') {{ $message }} @enderror</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="password_confirmation" class="block text-[#e0e1dd] mb-2">Confirm New Password</label>
|
||||||
|
<input type="password" id="password_confirmation" name="password_confirmation"
|
||||||
|
class="w-full px-4 py-3 rounded-lg bg-[#415a77] text-white placeholder-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="submit"
|
||||||
|
class="inline-block cursor-pointer px-6 py-3 border border-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 transition ease-in-out duration-300">
|
||||||
|
Update Password
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
|
@endsection
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
@extends('layouts.aside')
|
||||||
|
|
||||||
|
@section('main')
|
||||||
|
<main class="min-h-screen w-full flex items-center justify-center bg-[#0d1b2a] overflow-auto py-5">
|
||||||
|
<div class="bg-[#1b263b] p-8 rounded-xl shadow-2xl max-w-[800px] w-full transition-all duration-300">
|
||||||
|
|
||||||
|
<h1 class="text-3xl font-semibold text-center text-[#e0e1dd] mb-10">Edit Profile</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('profile.update') }}" method="POST" class="space-y-6">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="name" class="block text-[#e0e1dd] mb-2">Name</label>
|
||||||
|
<input type="text" id="name" name="name" value="{{ $user->name }}"
|
||||||
|
class="w-full px-4 py-3 rounded-lg bg-[#415a77] text-white placeholder-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||||
|
<p class="w-full text-red-500">@error('name') {{ $message }} @enderror</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="email" class="block text-[#e0e1dd] mb-2">Email</label>
|
||||||
|
<input type="email" id="email" name="email" value="{{ $user->email }}"
|
||||||
|
class="w-full px-4 py-3 rounded-lg bg-[#415a77] text-white placeholder-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500" />
|
||||||
|
<p class="w-full text-red-500">@error('email') {{ $message }} @enderror</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<button type="submit"
|
||||||
|
class="inline-block cursor-pointer px-6 py-3 border border-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 transition ease-in-out duration-300">
|
||||||
|
Save Changes
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
@ -1,44 +1,6 @@
|
|||||||
@extends('layouts.app')
|
@extends('layouts.aside')
|
||||||
|
|
||||||
@section('content')
|
|
||||||
<div class="bg-[#0d1b2a] min-h-screen flex justify-center items-center space-x-4">
|
|
||||||
<aside class="bg-[#1b263b] h-screen w-[300px] rounded-xl flex flex-col justify-between p-5 text-white shadow-lg">
|
|
||||||
<div class="mt-5">
|
|
||||||
<div class="text-center mb-6">
|
|
||||||
<h1 class="font-bold text-3xl">{{$user->name}} Panel</h1>
|
|
||||||
<p class="text-gray-300 mt-1">You are logged in!</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<nav class="space-y-2">
|
|
||||||
<a href="{{ route('dashboard') }}" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
|
||||||
📊 Dashboard
|
|
||||||
</a>
|
|
||||||
<a href="#" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">👤
|
|
||||||
Profile</a>
|
|
||||||
<a href="#" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
|
||||||
🔐 Change Password
|
|
||||||
</a>
|
|
||||||
<a href="#" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
|
||||||
🖥️ Browse Session
|
|
||||||
</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-6 space-y-4">
|
|
||||||
<form action="{{route('logout')}}" method="POST">
|
|
||||||
@csrf
|
|
||||||
<button type="submit"
|
|
||||||
class="block text-center w-full border border-red-500 text-red-500 hover:bg-red-500 hover:text-white transition-all duration-300 rounded-lg py-2 cursor-pointer">Logout</button>
|
|
||||||
</form>
|
|
||||||
<form action="{{route('delete.account')}}" method="POST">
|
|
||||||
@csrf
|
|
||||||
<button type="submit"
|
|
||||||
class="block text-center w-full border border-red-500 text-red-500 hover:bg-red-500 hover:text-white transition-all duration-300 rounded-lg py-2 cursor-pointer">Delete
|
|
||||||
Account</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
|
@section('main')
|
||||||
<main class="min-h-screen w-full flex items-center justify-center bg-[#0d1b2a] overflow-auto py-5">
|
<main class="min-h-screen w-full flex items-center justify-center bg-[#0d1b2a] overflow-auto py-5">
|
||||||
<div class="bg-[#1b263b] p-8 rounded-xl shadow-2xl max-w-[800px] w-full transition-all duration-300">
|
<div class="bg-[#1b263b] p-8 rounded-xl shadow-2xl max-w-[800px] w-full transition-all duration-300">
|
||||||
<h1 class="text-3xl font-semibold text-center text-[#e0e1dd] mb-5">
|
<h1 class="text-3xl font-semibold text-center text-[#e0e1dd] mb-5">
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="bg-[#0d1b2a] min-h-screen flex justify-center items-center space-x-4">
|
||||||
|
<aside class="bg-[#1b263b] h-screen w-[300px] rounded-xl flex flex-col justify-between p-5 text-white shadow-lg">
|
||||||
|
<div class="mt-5">
|
||||||
|
<div class="text-center mb-6">
|
||||||
|
<h1 class="font-bold text-3xl">{{$user->name}} Panel</h1>
|
||||||
|
<p class="text-gray-300 mt-1">You are logged in!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav class="space-y-2">
|
||||||
|
<a href="{{ route('dashboard') }}" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
||||||
|
📊 Dashboard
|
||||||
|
</a>
|
||||||
|
<a href="{{route('profile.show')}}" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">👤
|
||||||
|
Profile</a>
|
||||||
|
<a href="{{route('change.password.show')}}"
|
||||||
|
class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
||||||
|
🔐 Change Password
|
||||||
|
</a>
|
||||||
|
<a href="#" class="block px-4 py-2 rounded-lg hover:bg-[#415a77] transition">
|
||||||
|
🖥️ Browse Session
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-6 space-y-4">
|
||||||
|
<form action="{{route('logout')}}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<button type="submit"
|
||||||
|
class="block text-center w-full border border-red-500 text-red-500 hover:bg-red-500 hover:text-white transition-all duration-300 rounded-lg py-2 cursor-pointer">Logout</button>
|
||||||
|
</form>
|
||||||
|
<form action="{{route('delete.account')}}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<button type="submit"
|
||||||
|
class="block text-center w-full border border-red-500 text-red-500 hover:bg-red-500 hover:text-white transition-all duration-300 rounded-lg py-2 cursor-pointer">Delete
|
||||||
|
Account</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
@yield('main')
|
||||||
|
@endsection
|
||||||
@ -8,6 +8,7 @@ use App\Http\Controllers\DashboardController;
|
|||||||
use App\Http\Controllers\Auth\LoginController;
|
use App\Http\Controllers\Auth\LoginController;
|
||||||
use App\Http\Controllers\Auth\LogoutController;
|
use App\Http\Controllers\Auth\LogoutController;
|
||||||
use App\Http\Controllers\Auth\PasswordController;
|
use App\Http\Controllers\Auth\PasswordController;
|
||||||
|
use App\Http\Controllers\Auth\ProfileController;
|
||||||
use App\Http\Controllers\Auth\RegisterController;
|
use App\Http\Controllers\Auth\RegisterController;
|
||||||
use App\Http\Controllers\Auth\TwoFactorAuthenticationController;
|
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::post('disable-2fa', [TwoFactorAuthenticationController::class, 'disable2FA'])->name('disable.2fa');
|
||||||
Route::get('secret-code-show', [TwoFactorAuthenticationController::class, 'secretCodeShow'])->name('secret.code.show');
|
Route::get('secret-code-show', [TwoFactorAuthenticationController::class, 'secretCodeShow'])->name('secret.code.show');
|
||||||
Route::post('secret-code', [TwoFactorAuthenticationController::class, 'secretCode'])->name('secret.code');
|
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user