当前位置: 首页>>代码示例>>PHP>>正文


PHP AuthService::authenticateUser方法代码示例

本文整理汇总了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()) {
开发者ID:BenHicksy,项目名称:dietddocs,代码行数:31,代码来源:userRoutes.php


注:本文中的AuthService::authenticateUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。