2017-01-17 08:46:43 +00:00
|
|
|
<?php
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity\Repository;
|
2017-01-17 08:46:43 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Entity;
|
2017-01-17 08:46:43 +00:00
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
class UserRepository extends BaseRepository
|
2017-01-17 08:46:43 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param $username
|
|
|
|
* @param $password
|
|
|
|
* @return bool|null|object
|
|
|
|
*/
|
|
|
|
public function authenticate($username, $password)
|
|
|
|
{
|
|
|
|
$login_info = $this->findOneBy(['email' => $username]);
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
if (!($login_info instanceof Entity\User)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-17 08:46:43 +00:00
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
if ($login_info->verifyPassword($password)) {
|
2017-01-17 08:46:43 +00:00
|
|
|
return $login_info;
|
2017-01-24 00:35:16 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-17 08:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates or returns an existing user with the specified e-mail address.
|
|
|
|
*
|
|
|
|
* @param $email
|
|
|
|
* @return Entity\User
|
|
|
|
*/
|
|
|
|
public function getOrCreate($email)
|
|
|
|
{
|
|
|
|
$user = $this->findOneBy(['email' => $email]);
|
|
|
|
|
2017-01-24 00:35:16 +00:00
|
|
|
if (!($user instanceof Entity\User)) {
|
2017-01-17 08:46:43 +00:00
|
|
|
$user = new Entity\User;
|
2017-08-17 18:28:48 +00:00
|
|
|
$user->setEmail($email);
|
|
|
|
$user->setName($email);
|
2017-01-17 08:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|