Auth Db: use helper methods to retrieve data instead of FPDO raw methods
This commit is contained in:
parent
dbf5b0a54c
commit
20461e3e47
1 changed files with 11 additions and 15 deletions
|
@ -86,13 +86,11 @@ class Db extends Backend {
|
||||||
public static function get_user($username) {
|
public static function get_user($username) {
|
||||||
self :: connect();
|
self :: connect();
|
||||||
try {
|
try {
|
||||||
$query = self :: $class :: $fpdo -> from(self :: $users_table)
|
$info = self :: $class :: get_one(
|
||||||
-> select(null)
|
self :: $users_table,
|
||||||
-> select(self :: $exposed_fields)
|
[self :: $username_field => $username],
|
||||||
-> where(self :: $username_field, $username);
|
self :: $exposed_fields
|
||||||
|
);
|
||||||
$result = $query -> execute();
|
|
||||||
$info = $result -> fetch();
|
|
||||||
if ($info === false)
|
if ($info === false)
|
||||||
return null;
|
return null;
|
||||||
return new User($username, '\\EesyPHP\\Auth\\Db', $info);
|
return new User($username, '\\EesyPHP\\Auth\\Db', $info);
|
||||||
|
@ -112,16 +110,14 @@ class Db extends Backend {
|
||||||
public static function check_password($user, $password) {
|
public static function check_password($user, $password) {
|
||||||
self :: connect();
|
self :: connect();
|
||||||
try {
|
try {
|
||||||
$query = self :: $class :: $fpdo -> from(self :: $users_table)
|
$info = self :: $class :: get_one(
|
||||||
-> select(null)
|
self :: $users_table,
|
||||||
-> select(self :: $password_field)
|
[self :: $username_field => $user->username],
|
||||||
-> where(self :: $username_field, $user->username);
|
[self :: $password_field]
|
||||||
|
);
|
||||||
$result = $query -> execute();
|
|
||||||
$info = $result -> fetch();
|
|
||||||
if ($info === false)
|
if ($info === false)
|
||||||
return false;
|
return false;
|
||||||
return password_verify($password, $info['password']);
|
return password_verify($password, $info[self :: $password_field]);
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Log :: error("Error retrieving user %s password from database: %s", $user, $e->getMessage());
|
Log :: error("Error retrieving user %s password from database: %s", $user, $e->getMessage());
|
||||||
|
|
Loading…
Reference in a new issue