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.
27 lines
630 B
27 lines
630 B
7 years ago
|
<?php
|
||
|
|
||
|
namespace core\services\auth;
|
||
|
|
||
|
use core\entities\user\User;
|
||
|
use core\forms\auth\LoginForm;
|
||
|
use core\repositories\user\UserRepository;
|
||
|
use Yii;
|
||
|
|
||
|
class AuthService
|
||
|
{
|
||
|
private $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('auth', 'Undefined user or password.'));
|
||
|
}
|
||
|
return $user;
|
||
|
}
|
||
|
}
|