You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
666 B
28 lines
666 B
<?php |
|
|
|
namespace core\services\auth; |
|
|
|
use core\entities\user\User; |
|
use core\forms\auth\LoginForm; |
|
use core\repositories\user\UserRepository; |
|
use DomainException; |
|
use Yii; |
|
|
|
class AuthService |
|
{ |
|
private UserRepository $users; |
|
|
|
public function __construct(UserRepository $users) |
|
{ |
|
$this->users = $users; |
|
} |
|
|
|
public function auth(LoginForm $form): User |
|
{ |
|
$user = $this->users->findByUsernameOrEmail($form->username); |
|
if (!$user || !$user->isActive() || !$user->validatePassword($form->password)) { |
|
throw new DomainException(Yii::t('user', 'Undefined user or password.')); |
|
} |
|
return $user; |
|
} |
|
}
|
|
|