mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Extract login logics into a separate component. Not quite clean result but enough for upcoming tasks
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use common\models\Account;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class AccountBannedException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(
|
||||
public readonly Account $account,
|
||||
?Throwable $previous = null,
|
||||
) {
|
||||
parent::__construct('The account has been banned', previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use common\models\Account;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class AccountNotActivatedException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(
|
||||
public readonly Account $account,
|
||||
?Throwable $previous = null,
|
||||
) {
|
||||
parent::__construct('The account has not been activated yet', previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface AuthenticationException extends Throwable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class InvalidPasswordException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(?Throwable $previous = null) {
|
||||
parent::__construct("The entered password doesn't match the account's password", previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class InvalidTotpException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(?Throwable $previous = null) {
|
||||
parent::__construct('Incorrect TOTP value', previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class TotpRequiredException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(?Throwable $previous = null) {
|
||||
parent::__construct('Two-factor authentication is enabled for the account and you need to pass the TOTP', previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\Authentication\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
final class UnknownLoginException extends Exception implements AuthenticationException {
|
||||
|
||||
public function __construct(?Throwable $previous = null) {
|
||||
parent::__construct('The account with the specified login does not exist', previous: $previous);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user