Allow changing email, username and password

This commit is contained in:
2026-01-08 16:14:35 +01:00
parent 2029af334c
commit 8f99718058
4 changed files with 52 additions and 9 deletions

View File

@@ -15,6 +15,20 @@ class PasswordController extends Controller
*/ */
public function update(Request $request): RedirectResponse public function update(Request $request): RedirectResponse
{ {
// If user logged in with Discord and has not yet a password, allow to set password
if ($request->user()->discord_id && is_null($request->user()->password))
{
$validated = $request->validateWithBag('updatePassword', [
'password' => ['required', Password::defaults(), 'confirmed'],
]);
$request->user()->update([
'password' => Hash::make($validated['password']),
]);
return back()->with('status', 'password-updated');
}
$validated = $request->validateWithBag('updatePassword', [ $validated = $request->validateWithBag('updatePassword', [
'current_password' => ['required', 'current_password'], 'current_password' => ['required', 'current_password'],
'password' => ['required', Password::defaults(), 'confirmed'], 'password' => ['required', Password::defaults(), 'confirmed'],

View File

@@ -7,17 +7,33 @@
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400"> <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __('Ensure your account is using a long, random password to stay secure.') }} {{ __('Ensure your account is using a long, random password to stay secure.') }}
</p> </p>
@if ($user->discord_id && is_null($user->password))
<div class="p-2 rounded-lg bg-rose-600/80 mt-4">
<p class="p-2 text-sm dark:text-gray-200 text-white">
{{ __('You currently don\'t have a password set, as you use Discord authentication. You can set a password to be able to login with email & password.') }}
</p>
</div>
@elseif ($user->discord_id && !is_null($user->password))
<div class="p-2 rounded-lg bg-green-600/80 mt-4">
<p class="p-2 text-sm dark:text-gray-200 text-white">
{{ __('Both Discord and email login are enabled.') }}
</p>
</div>
@endif
</header> </header>
<form method="post" action="{{ route('password.update') }}" class="mt-6 space-y-6"> <form method="post" action="{{ route('password.update') }}" class="mt-6 space-y-6">
@csrf @csrf
@method('put') @method('put')
@if (!(is_null($user->password) && $user->discord_id))
<div> <div>
<x-input-label for="update_password_current_password" :value="__('Current Password')" /> <x-input-label for="update_password_current_password" :value="__('Current Password')" />
<x-text-input id="update_password_current_password" name="current_password" type="password" class="mt-1 block w-full" autocomplete="current-password" /> <x-text-input id="update_password_current_password" name="current_password" type="password" class="mt-1 block w-full" autocomplete="current-password" />
<x-input-error :messages="$errors->updatePassword->get('current_password')" class="mt-2" /> <x-input-error :messages="$errors->updatePassword->get('current_password')" class="mt-2" />
</div> </div>
@endif
<div> <div>
<x-input-label for="update_password_password" :value="__('New Password')" /> <x-input-label for="update_password_password" :value="__('New Password')" />

View File

@@ -4,9 +4,19 @@
{{ __('Profile Information') }} {{ __('Profile Information') }}
</h2> </h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400"> @if ($user->discord_id)
{{ __("Update your account's profile information and email address.") }} <div class="p-2 rounded-lg bg-rose-600/80 mt-4">
</p> <p class="p-2 text-sm dark:text-gray-200 text-white">
{{ __('Changing your name or email will not affect Discord authentication, as your Discord ID has been stored.') }}
</p>
</div>
@else
<div class="p-2 rounded-lg bg-green-600/80 mt-4">
<p class="p-2 text-sm dark:text-gray-200 text-white">
{{ __('If you want to use Discord authentication, ensure the email addresses match for initial login. After login with Discord, email can be changed.') }}
</p>
</div>
@endif
</header> </header>
<form id="send-verification" method="post" action="{{ route('verification.send') }}"> <form id="send-verification" method="post" action="{{ route('verification.send') }}">
@@ -19,13 +29,13 @@
<div> <div>
<x-input-label for="name" :value="__('Name')" /> <x-input-label for="name" :value="__('Name')" />
<x-text-input id="name" name="name" type="text" class="mt-1 block w-full" :value="old('name', $user->name)" required autofocus autocomplete="name" disabled /> <x-text-input id="name" name="name" type="text" class="mt-1 block w-full" :value="old('name', $user->name)" required autofocus autocomplete="name" />
<x-input-error class="mt-2" :messages="$errors->get('name')" /> <x-input-error class="mt-2" :messages="$errors->get('name')" />
</div> </div>
<div> <div>
<x-input-label for="email" :value="__('Email')" /> <x-input-label for="email" :value="__('Email')" />
<x-text-input id="email" name="email" type="email" class="mt-1 block w-full" :value="old('email', $user->email)" required autocomplete="email" disabled /> <x-text-input id="email" name="email" type="email" class="mt-1 block w-full" :value="old('email', $user->email)" required autocomplete="email" />
<x-input-error class="mt-2" :messages="$errors->get('email')" /> <x-input-error class="mt-2" :messages="$errors->get('email')" />
@if ($user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! $user->hasVerifiedEmail()) @if ($user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! $user->hasVerifiedEmail())
@@ -47,7 +57,7 @@
@endif @endif
</div> </div>
{{-- <div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<x-primary-button>{{ __('Save') }}</x-primary-button> <x-primary-button>{{ __('Save') }}</x-primary-button>
@if (session('status') === 'profile-updated') @if (session('status') === 'profile-updated')
@@ -59,6 +69,6 @@
class="text-sm text-gray-600 dark:text-gray-400" class="text-sm text-gray-600 dark:text-gray-400"
>{{ __('Saved.') }}</p> >{{ __('Saved.') }}</p>
@endif @endif
</div> --}} </div>
</form> </form>
</section> </section>

View File

@@ -8,13 +8,16 @@
<!-- Page Content --> <!-- Page Content -->
<main> <main>
@include('user.partials.background') @include('user.partials.background')
<div class="relative max-w-[120rem] mx-auto sm:px-6 lg:px-8 space-y-6 pt-20 mt-[65px] flex flex-row"> <div class="relative max-w-[120rem] mx-auto sm:px-6 lg:px-8 space-y-6 pt-20 mt-[65px] mb-14 flex flex-row">
<div class="flex flex-col md:flex-row"> <div class="flex flex-col md:flex-row">
@include('profile.partials.sidebar') @include('profile.partials.sidebar')
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6"> <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 mt-8 md:mt-0 space-y-6">
<div class="p-4 sm:p-8 bg-white/40 dark:bg-neutral-950/40 backdrop-blur shadow sm:rounded-lg"> <div class="p-4 sm:p-8 bg-white/40 dark:bg-neutral-950/40 backdrop-blur shadow sm:rounded-lg">
@include('profile.partials.update-profile-information-form') @include('profile.partials.update-profile-information-form')
</div> </div>
<div class="p-4 sm:p-8 bg-white/40 dark:bg-neutral-950/40 backdrop-blur shadow sm:rounded-lg">
@include('profile.partials.update-password-form')
</div>
<div class="p-4 sm:p-8 bg-white/40 dark:bg-neutral-950/40 backdrop-blur shadow sm:rounded-lg"> <div class="p-4 sm:p-8 bg-white/40 dark:bg-neutral-950/40 backdrop-blur shadow sm:rounded-lg">
@include('profile.partials.update-blacklist-form') @include('profile.partials.update-blacklist-form')
</div> </div>