parent
d84006d7c7
commit
f0439782ba
13 changed files with 69 additions and 3 deletions
|
|
@ -59,7 +59,7 @@ class UserStoreBase extends Store
|
|||
|
||||
/**
|
||||
* Returns a User model by Email.
|
||||
* @param mixed $value
|
||||
* @param string $value
|
||||
* @param string $useConnection
|
||||
* @throws HttpException
|
||||
* @return \@appNamespace\Model\User|null
|
||||
|
|
@ -82,4 +82,30 @@ class UserStoreBase extends Store
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a User model by Email.
|
||||
* @param string $value
|
||||
* @param string $useConnection
|
||||
* @throws HttpException
|
||||
* @return \@appNamespace\Model\User|null
|
||||
*/
|
||||
public function getByLoginOrEmail($value, $useConnection = 'read')
|
||||
{
|
||||
if (is_null($value)) {
|
||||
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM `user` WHERE `name` = :value OR `email` = :value LIMIT 1';
|
||||
$stmt = Database::getConnection($useConnection)->prepare($query);
|
||||
$stmt->bindValue(':value', $value);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
return new User($data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue