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.

29 lines
666 B

7 years ago
<?php
namespace core\services\auth;
use core\entities\user\User;
use core\forms\auth\LoginForm;
use core\repositories\user\UserRepository;
3 years ago
use DomainException;
7 years ago
use Yii;
class AuthService
{
3 years ago
private UserRepository $users;
7 years ago
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)) {
3 years ago
throw new DomainException(Yii::t('user', 'Undefined user or password.'));
7 years ago
}
return $user;
}
3 years ago
}