本文整理汇总了PHP中AuthService::authenticateUser方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthService::authenticateUser方法的具体用法?PHP AuthService::authenticateUser怎么用?PHP AuthService::authenticateUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthService
的用法示例。
在下文中一共展示了AuthService::authenticateUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
<?php
$app->map(['GET', 'POST'], '/users/login', function ($request, $response, $args) {
$field_errors = [];
$flash_messages = $this->flash->getMessages();
$user = [];
if ($request->isPost()) {
$userService = new AuthService();
$user['user_name'] = filter_var($_POST['user_name'], FILTER_SANITIZE_STRING);
$user['password'] = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
$user_form = validateLoginForm($user);
if ($user_form['is_valid']) {
$valid_user = $userService->authenticateUser($user['user_name'], $user['password']);
if ($valid_user) {
$_SESSION['user_id'] = $valid_user['user_id'];
$this->flash->addMessage('success', 'Login successful');
return $response->withRedirect($this->router->pathFor('docs-home'));
} else {
$flash_messages['danger'][] = "Incorrect combination of username/email AND password - Please try again";
}
} else {
$field_errors = $user_form['has_errors'];
}
}
return $this->view->render($response, 'forms/login.twig', ['user' => $user, 'flash_messages' => $flash_messages, 'errors' => $field_errors, 'userLogged' => isset($_SESSION['user_id']), 'csrf' => ['name' => $request->getAttribute('csrf_name'), 'value' => $request->getAttribute('csrf_value')]]);
})->setName('login');
$app->map(['GET', 'POST'], '/users/register', function ($request, $response, $args) {
$field_errors = [];
$user = [];
$flash_messages = $this->flash->getMessages();
if ($request->isPost()) {