diff --git a/laravel/app/Http/Controllers/ProfileController.php b/laravel/app/Http/Controllers/ProfileController.php new file mode 100644 index 0000000..4e7514b --- /dev/null +++ b/laravel/app/Http/Controllers/ProfileController.php @@ -0,0 +1,46 @@ +validate([ + 'name' => [ + 'required', + 'string', + 'max:28', + Rule::unique('users')->ignore($user->id), // Ignore current user + ], + 'email' => [ + 'required', + 'string', + 'email', + Rule::unique('users')->ignore($user->id), // Ignore current user + ], + ]); + } catch (ValidationException $e) { + return redirect()->back()->withInput($request->input())->withErrors($e->errors()); + } + $user->name = $request->input('name'); + $user->email = $request->input('email'); + $user->save(); + return redirect('profile')->with('success', 'Profile updated successfully'); + } + + public function updatePassword(Request $request) { + $user = Auth::user(); + $request->validate([ + 'password' => 'required|string|min:8|confirmed' + ]); + $user->password = bcrypt($request->input('password')); + $user->save(); + return redirect('profile')->with('success', 'Password updated successfully'); + } +} \ No newline at end of file diff --git a/laravel/public/css/default.css b/laravel/public/css/default.css index 9920325..07b3965 100644 --- a/laravel/public/css/default.css +++ b/laravel/public/css/default.css @@ -93,6 +93,16 @@ header nav a { box-shadow: 3px 3px 10px 0 #0008; } +#profile-container { + margin: 5vh auto; +} + +.button-row { + display: flex; + flex-direction: row; + justify-content: space-around; +} + .form-container form { display: flex; flex-direction: column; @@ -108,6 +118,12 @@ header nav a { margin-bottom: 20px; } +.form-container form input.unmodifiable { + color: #aaa; + border: none; + pointer-events: none; +} + .form-container form label { color: #666; font-size: 0.8em; @@ -139,6 +155,16 @@ header nav a { background: #ff000028; border-radius: 5px; padding: 10px; + margin-bottom: 0; +} + +.form-container .success { + width: 280px; + color: #00bb00; + background: #00ff0028; + border-radius: 5px; + padding: 10px; + margin-bottom: 0; } #banner-container { @@ -367,6 +393,11 @@ header nav a { #destination { max-width: 850px; + word-break: break-all; + height: 1.2em; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; } button { diff --git a/laravel/resources/views/details.blade.php b/laravel/resources/views/details.blade.php index 92b89f3..3ea6e48 100644 --- a/laravel/resources/views/details.blade.php +++ b/laravel/resources/views/details.blade.php @@ -19,9 +19,9 @@ @csrf
- {{ $shortlink->destination }} + {{ $shortlink->destination }} - {{ url()->to($shortlink->shortid) }} + {{ url()->to($shortlink->shortid) }} @@ -87,12 +87,28 @@ Country Clicks + @php + $total = 0; + $rows = []; + @endphp @foreach ($countrylist as $country) - - {{ $country['emoji'] }} - {{ $country['country'] ?? 'Unknown' }} - {{ $country['total'] }} - + @php + $total += $country['total']; + $row = " + " . $country['emoji'] . " + " . ($country['country'] ?? 'Unknown') . " + " . $country['total'] . " + "; + array_push($rows, $row); + @endphp + @endforeach + + 🌎 + Total + {{ $total }} + + @foreach ($rows as $row) + {!! $row !!} @endforeach
diff --git a/laravel/resources/views/login.blade.php b/laravel/resources/views/login.blade.php index db815a9..1bc52d0 100644 --- a/laravel/resources/views/login.blade.php +++ b/laravel/resources/views/login.blade.php @@ -10,7 +10,7 @@
@csrf - + diff --git a/laravel/resources/views/profile-change-password.blade.php b/laravel/resources/views/profile-change-password.blade.php new file mode 100644 index 0000000..eedc064 --- /dev/null +++ b/laravel/resources/views/profile-change-password.blade.php @@ -0,0 +1,24 @@ +@extends('default') + +@section('title') + Change Password +@endsection + +@section('content') +
+

Change Password

+ + @csrf + + + + + + + + + @if ($errors->any()) +

{{ $errors->first() }}

+ @endif +
+@endsection \ No newline at end of file diff --git a/laravel/resources/views/profile.blade.php b/laravel/resources/views/profile.blade.php index 262aeda..1197363 100644 --- a/laravel/resources/views/profile.blade.php +++ b/laravel/resources/views/profile.blade.php @@ -5,13 +5,27 @@ @endsection @section('content') -
+

Profile

-
-
-

Username: {{ Auth::user()->name }}

-

Email: {{ Auth::user()->email }}

-

Created at: {{ Auth::user()->created_at }}

+
+ @csrf + + + + + + created_at)[0] }}" required readonly> +
+ + +
+ @if ($errors->any()) +

{{ $errors->first() }}

+ @endif + @if (session('success')) +

{{ session('success') }}

+ @endif +

My Short URLs

diff --git a/laravel/routes/web.php b/laravel/routes/web.php index 07803b0..6937b73 100644 --- a/laravel/routes/web.php +++ b/laravel/routes/web.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\RegisterController; use App\Http\Controllers\LoginController; use App\Http\Controllers\ShortlinkController; +use App\Http\Controllers\ProfileController; Route::get('/', function () { return redirect('/home'); @@ -35,6 +36,17 @@ Route::get('/logout', function () { Route::get('/profile', [ShortlinkController::class, 'getLinksByUser']); +Route::get('/profile/change-password', function () { + if (!auth()->check()) { + return redirect('login'); + } + return view('profile-change-password'); +}); + +Route::post('/profile/update', [ProfileController::class, 'update']); + +Route::post('/profile/change-password/update', [ProfileController::class, 'updatePassword']); + Route::get('/home', function () { if (!auth()->check()) { return view('home');