align backend auth patterns
This commit is contained in:
parent
b3266b38c8
commit
299efe0839
23 changed files with 249 additions and 142 deletions
|
|
@ -8,6 +8,6 @@ final readonly class CreateUserDto
|
|||
{
|
||||
public function __construct(
|
||||
public EmailAddress $email,
|
||||
public string $password,
|
||||
public string $passwordHash,
|
||||
) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\User;
|
||||
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class EloquentUserRepository implements UserRepository
|
||||
{
|
||||
|
|
@ -11,7 +10,7 @@ class EloquentUserRepository implements UserRepository
|
|||
{
|
||||
$model = UserModel::create([
|
||||
'email' => $dto->email->value(),
|
||||
'password' => Hash::make($dto->password),
|
||||
'passwordHash' => $dto->passwordHash,
|
||||
]);
|
||||
|
||||
return $this->toDomain($model);
|
||||
|
|
@ -27,18 +26,12 @@ class EloquentUserRepository implements UserRepository
|
|||
return $this->toDomain($model);
|
||||
}
|
||||
|
||||
public function findByCredentials(
|
||||
EmailAddress $email,
|
||||
string $password,
|
||||
): ?User
|
||||
public function findByEmail(EmailAddress $email): ?User
|
||||
{
|
||||
$model = UserModel::query()
|
||||
->where('email', $email->value())
|
||||
->first();
|
||||
if (
|
||||
$model === null
|
||||
|| ! Hash::check($password, $model->password)
|
||||
) {
|
||||
if ($model === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +43,7 @@ class EloquentUserRepository implements UserRepository
|
|||
return new User(
|
||||
id: $model->id,
|
||||
email: new EmailAddress($model->email),
|
||||
passwordHash: $model->passwordHash,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ final readonly class User
|
|||
public function __construct(
|
||||
private int $id,
|
||||
private EmailAddress $email,
|
||||
private string $passwordHash,
|
||||
) {}
|
||||
|
||||
public function getId(): int
|
||||
|
|
@ -20,4 +21,9 @@ final readonly class User
|
|||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getPasswordHash(): string
|
||||
{
|
||||
return $this->passwordHash;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
/**
|
||||
* @property int $id
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $passwordHash
|
||||
*
|
||||
* @method static Builder<static>|UserModel newModelQuery()
|
||||
* @method static Builder<static>|UserModel newQuery()
|
||||
|
|
@ -17,7 +17,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
#[Fillable(['email', 'password'])]
|
||||
#[Fillable(['email', 'passwordHash'])]
|
||||
class UserModel extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
|
|
|
|||
|
|
@ -10,8 +10,5 @@ interface UserRepository
|
|||
|
||||
public function find(int $id): ?User;
|
||||
|
||||
public function findByCredentials(
|
||||
EmailAddress $email,
|
||||
string $password,
|
||||
): ?User;
|
||||
public function findByEmail(EmailAddress $email): ?User;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue