本文整理汇总了PHP中DbHandler::getUserByEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHandler::getUserByEmail方法的具体用法?PHP DbHandler::getUserByEmail怎么用?PHP DbHandler::getUserByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHandler
的用法示例。
在下文中一共展示了DbHandler::getUserByEmail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
break;
}
});
$app->post('/login', function () use($app) {
// check for required params
verifyRequiredParams(array('email', 'password'));
// reading post params
$body = json_decode($app->request->getBody(), true);
$email = $body['email'];
$password = $body['password'];
$response = array();
$db = new DbHandler();
// check for correct email and password
if ($db->checkLogin($email, $password)) {
// get the user by email
$response = $db->getUserByEmail($email);
if ($response != NULL) {
$response["error"] = false;
} else {
// unknown error occurred
$response['error'] = true;
$response['message'] = "An error occurred. Please try again";
}
} else {
// user credentials are wrong
$response['error'] = true;
$response['message'] = 'Login failed. Incorrect credentials';
}
echoResponse(200, $response);
});
/**
示例2: function
* url - /login
* method - POST
* params - email, password
*/
$app->post('/login', function () use($app) {
// check for required params
verifyRequiredParams(array('email', 'password'));
// reading post params
$email = $app->request()->post('email');
$password = $app->request()->post('password');
$response = array();
$db = new DbHandler();
// check for correct email and password
if ($db->checkLogin($email, $password)) {
// get the user by email
$user = $db->getUserByEmail($email);
if ($user != NULL) {
$response["error"] = false;
$response['name'] = $user['name'];
$response['email'] = $user['email'];
$response['apiKey'] = $user['api_key'];
$response['created_at'] = $user['created_at'];
} else {
// unknown error occurred
$response['error'] = true;
$response['message'] = "An error occurred. Please try again";
}
} else {
// user credentials are wrong
$response['error'] = true;
$response['message'] = 'Login failed. Incorrect credentials';
示例3: function
$app->render('login.php');
});
//POST login route
$app->post('/login', function () use($app) {
//create empty response array
$response = array();
//read post params
$email_username = $app->request->post('username');
$password = $app->request->post('password');
//instantiate the DbHandler class and call the checkloging method
require_once './classes/DbHandler.php';
$db = new DbHandler();
//check for correct email and password combination
if ($db->checkLogin($email_username, $password)) {
//valid user - get user details
$user = $db->getUserByEmail($email_username);
if (!empty($user)) {
// var_dump($user);
foreach ($user as $item) {
$userid = $item['user_id'];
$firstName = $item['first_name'];
$lastName = $item['last_name'];
$username = $item['user_name'];
$fullname = $firstName . ' ' . $lastName;
$admin = $item['admin'];
$expired = $item['notexpired'];
}
//store data in session
$_SESSION['user_id'] = $userid;
$_SESSION['fullname'] = $fullname;
$_SESSION['user_admin'] = $admin;