Initial commit

This commit is contained in:
Ronald Huynen
2026-03-23 21:37:59 +01:00
commit 2547717edb
2193 changed files with 972171 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Jetstream;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;
/**
* Validate and create a newly registered user.
*
* @param array $input
* @return \App\Models\User
*/
public function create(array $input)
{
Validator::make($input, [
'name' => ['required', 'string','max:25', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
// 'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
])->validate();
$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
// Always move this section to the final registration.
Session([
'activeProfileType' => User::class,
'activeProfileId' => Auth::guard('web')->user()->id,
'activeProfileName'=> Auth::guard('web')->user()->name,
'activeProfilePhoto'=> Auth::guard('web')->user()->profile_photo_path,
'firstLogin' => true
]);
//TODO: Welcome and introduction with Session('firstLogin') on rest of site views
return $user;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Actions\Fortify;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
class EnableTwoFactorAuthentication
{
/**
* The two factor authentication provider.
*
* @var \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider
*/
protected $provider;
/**
* Create a new action instance.
*
* @param \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider $provider
* @return void
*/
public function __construct(TwoFactorAuthenticationProvider $provider)
{
$this->provider = $provider;
}
/**
* Enable two factor authentication for the user by generating secrets
* and storing them temporarily in the session.
*
* @param mixed $user
* @return void
*/
public function __invoke($user)
{
$secretKey = $this->provider->generateSecretKey();
$recoveryCodes = collect(range(1, 8))
->map(fn () => Str::random(10).'-'.Str::random(10))
->all();
$qrCodeSvg = $this->provider->qrCodeSvg(
config('app.name'),
$user->email,
$secretKey
);
// Store the generated data in the session
session([
'2fa_setup_secret' => $secretKey, // Unencrypted secret for display and confirmation
'2fa_setup_qr_svg' => $qrCodeSvg,
'2fa_setup_recovery_codes' => encrypt(json_encode($recoveryCodes)), // Encrypt for storage in session
]);
// IMPORTANT: This custom action does NOT save anything to the user model in the database.
// That will be handled by the custom ConfirmTwoFactorAuthentication action.
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Actions\Fortify;
use Laravel\Fortify\Rules\Password;
trait PasswordValidationRules
{
/**
* Get the validation rules used to validate passwords.
*
* @return array
*/
protected function passwordRules()
{
// Dynamically get the password validation rules from the config
return timebank_config('rules.profile_user.password', ['required', 'string', 'min:8', 'confirmed']);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Actions\Fortify;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
class ResetUserPassword implements ResetsUserPasswords
{
use PasswordValidationRules;
/**
* Validate and reset the user's forgotten password.
*
* @param mixed $user
* @param array $input
* @return void
*/
public function reset($user, array $input)
{
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();
$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Actions\Fortify;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
class UpdateUserPassword implements UpdatesUserPasswords
{
use PasswordValidationRules;
/**
* Validate and update the user's password.
*
* @param mixed $user
* @param array $input
* @return void
*/
public function update($user, array $input)
{
Validator::make($input, [
'current_password' => ['required', 'string'],
'password' => $this->passwordRules(),
])->after(function ($validator) use ($user, $input) {
if (! isset($input['current_password']) || ! Hash::check($input['current_password'], $user->password)) {
$validator->errors()->add('current_password', __('The provided password does not match your current password.'));
}
})->validateWithBag('updatePassword');
$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
activity()
->useLog('User')
->performedOn($user)
->causedBy(Auth::guard('web')->user())
->event('password_changed')
->log('Password changed for ' . $user->name);
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Actions\Fortify;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
public function update($user, array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'min:3', 'max:40', Rule::unique('users')->ignore($user->id)],
'email' => ['required', 'email', 'max:40', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'mimes:jpg,jpeg,png,svg', 'max:1024'],
])->validateWithBag('updateProfileInformation');
if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
} else {
$user->forcefill(['profile_photo_path' => timebank_config('profiles.user.profile_photo_path_default')])->save();
}
if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
'email' => $input['email'],
])->save();
// Also update session with new name and profile_photo_path
Session([
'activeProfileName' => Auth::user()->name,
'activeProfilePhoto' => Auth::user()->profile_photo_path
]);
return redirect()->route('profile.show_by_type_and_id');
}
}
/**
* Update the given verified user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
protected function updateVerifiedUser($user, array $input)
{
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'email_verified_at' => null,
])->save();
$user->sendEmailVerificationNotification();
}
}