Customer page and contacts/billing units (phase 1, item 2): - New customer page (customers.show) with details, contacts and billing units; add and edit on their own pages, delete after confirmation. Creating or editing a customer now leads to this page. - Contacts: name, title, phone, email, note. Billing units: name, billing address, e-invoice address (12-35 letters/digits), operator (required with an e-invoice address) and reference. - Use cases check that the row belongs to the customer, so ids in the URL can't reach another customer's rows. - EmailAddress moves from Users to Shared so both modules can use it. - <x-confirm-dialog> (native <dialog>) replaces <x-modal>, whose title, close button and focus handling are not accessible; solid red buttons use red-700 via published NormalButtonColors for 4.5:1 contrast. Personal identity code (henkilötunnus) for consumers who are invoiced: - Validated (date, century sign, check character), stored encrypted with an HMAC blind index for duplicate checks; never in CustomerSummary, search, logs or Livewire state. - Admins and management see it in full and may remove it; others enter it and see only the masked form. The form never shows the stored code. Spec, architecture doc and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Users\Infrastructure\Auth;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
|
|
use App\Modules\Users\Application\Contracts\PasswordLinkSender;
|
|
use App\Modules\Users\Application\DTOs\IssuedSetupLink;
|
|
use Illuminate\Contracts\Auth\PasswordBroker;
|
|
use Illuminate\Support\Facades\Password;
|
|
use LogicException;
|
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
|
|
|
/**
|
|
* Uses Laravel's password reset tokens. Forgot-password links use the
|
|
* default broker (60 minutes); links made by an admin use the admin_links
|
|
* broker, which has its own table and a longer expiry.
|
|
*/
|
|
class LaravelPasswordLinkSender implements PasswordLinkSender
|
|
{
|
|
public const string ADMIN_BROKER = 'admin_links';
|
|
|
|
public function __construct(private PasswordBroker $passwords) {}
|
|
|
|
public static function adminLinkHours(): int
|
|
{
|
|
return intdiv((int) config('auth.passwords.'.self::ADMIN_BROKER.'.expire'), 60);
|
|
}
|
|
|
|
public function sendSetupLink(EmailAddress $email): bool
|
|
{
|
|
try {
|
|
return $this->passwords->sendResetLink(['email' => $email->value]) === PasswordBroker::RESET_LINK_SENT;
|
|
} catch (TransportExceptionInterface $exception) {
|
|
// The mail server is down or refused the message: log it and let
|
|
// the caller offer a resend instead of failing the whole action.
|
|
report($exception);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function issueSetupLink(EmailAddress $email): IssuedSetupLink
|
|
{
|
|
$user = User::query()->where('email', $email->value)->first()
|
|
?? throw new LogicException('A set-password link was asked for an unknown user.');
|
|
|
|
// The new link replaces every earlier link of the user.
|
|
Password::broker()->deleteToken($user);
|
|
$token = Password::broker(self::ADMIN_BROKER)->createToken($user);
|
|
|
|
$url = route('password.reset', [
|
|
'token' => $token,
|
|
'email' => $user->getEmailForPasswordReset(),
|
|
]);
|
|
|
|
try {
|
|
$user->notify(new PasswordSetupLinkNotification($token));
|
|
$emailSent = true;
|
|
} catch (TransportExceptionInterface $exception) {
|
|
// The admin still gets the link to hand over another way.
|
|
report($exception);
|
|
$emailSent = false;
|
|
}
|
|
|
|
return new IssuedSetupLink($url, $emailSent);
|
|
}
|
|
}
|