add password login
This commit is contained in:
parent
93f5f022e4
commit
ebfe147ca4
12 changed files with 192 additions and 6 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\User;
|
||||
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class EloquentUserRepository implements UserRepository
|
||||
{
|
||||
|
|
@ -10,6 +11,7 @@ class EloquentUserRepository implements UserRepository
|
|||
{
|
||||
$model = UserModel::create([
|
||||
'email' => $dto->email->value(),
|
||||
'password' => Hash::make($dto->password),
|
||||
]);
|
||||
|
||||
return $this->toDomain($model);
|
||||
|
|
@ -25,6 +27,24 @@ class EloquentUserRepository implements UserRepository
|
|||
return $this->toDomain($model);
|
||||
}
|
||||
|
||||
public function findByCredentials(
|
||||
EmailAddress $email,
|
||||
string $password,
|
||||
): ?User
|
||||
{
|
||||
$model = UserModel::query()
|
||||
->where('email', $email->value())
|
||||
->first();
|
||||
if (
|
||||
$model === null
|
||||
|| ! Hash::check($password, $model->password)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->toDomain($model);
|
||||
}
|
||||
|
||||
private function toDomain(UserModel $model): User
|
||||
{
|
||||
return new User(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue