Database Reference
In-Depth Information
Listing 8-20. The Login Route
// login
$app->post('/login', function() use ($app){
$params = $app->request()->post();
// make sure the user name was passed.
$username = trim($params['username']);
if (!empty($username)) {
// lower case the username.
$username=strtolower($username);
$app->log->debug($username);
$checkuser = User::getByUsername($username);
// match
if(!is_null($checkuser)){
$_SESSION['username'] = $username;
$app->redirect('/intent');
}else{
$app->view()->setData(array('msg' => 'The username you entered was not found.'));
$app->render('home/message.mustache');
}
}
else{
$app->view()->setData(array('msg' => 'Please enter a username.'));
$app->render('home/message.mustache');
}
})->name('login');
If the user is found during the login attempt, a cookie is added to the response and the request is redirected via
redirect to the social home page, shown in Figure 8-7 . Otherwise, the route will specify the HTML page to return as
well as add the error messages that need to be displayed back to the view.
 
Search WWH ::




Custom Search