本文整理汇总了PHP中UserDB::fetchByEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP UserDB::fetchByEmail方法的具体用法?PHP UserDB::fetchByEmail怎么用?PHP UserDB::fetchByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDB
的用法示例。
在下文中一共展示了UserDB::fetchByEmail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: echoResponse
echoResponse(201, $response);
}
});
$app->post('/login', function () use($app) {
$r = json_decode($app->request->getBody());
verifyRequiredParams(array('email', 'password'), $r->user);
$response = array();
try {
$dbHost = $app->config('db_host');
$dbName = $app->config('db_name');
$dbUser = $app->config('db_user');
$dbPass = $app->config('db_password');
$db = new UserDB($dbHost, $dbName, $dbUser, $dbPass);
$password = $r->user->password;
$email = $r->user->email;
$user = $db->fetchByEmail($email);
if ($user) {
//if(PasswordHash::check($user->password, $password)){
if (password_verify($password, $user->password)) {
$response = array('status' => true, 'message' => 'Logged in successfully!', 'user' => array('id' => $user->id, 'name' => $user->name, 'email' => $user->email, 'createdAt' => $user->created));
$session = new Session();
$session->set('id', $user->id);
$session->set('email', $user->email);
$session->set('name', $user->name);
} else {
$response = array('status' => false, 'message' => 'Login failed. Incorrect credentials.');
}
} else {
$response = array('status' => false, 'message' => 'No such user is registered.');
}
} catch (PDOException $e) {