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


PHP AuthService::addUser方法代码示例

本文整理汇总了PHP中AuthService::addUser方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthService::addUser方法的具体用法?PHP AuthService::addUser怎么用?PHP AuthService::addUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AuthService的用法示例。


在下文中一共展示了AuthService::addUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: function

})->setName('login');
$app->map(['GET', 'POST'], '/users/register', function ($request, $response, $args) {
    $field_errors = [];
    $user = [];
    $flash_messages = $this->flash->getMessages();
    if ($request->isPost()) {
        $user['user_name'] = filter_var($_POST['user_name'], FILTER_SANITIZE_STRING);
        $user['password'] = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
        $user['full_name'] = filter_var($_POST['full_name'], FILTER_SANITIZE_STRING);
        $user['email'] = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
        $user_form = validateRegisterForm($user);
        if ($user_form['is_valid']) {
            $userService = new AuthService();
            $errors = $userService->validateUser($user);
            if (empty($errors)) {
                $userService->addUser($user);
                $this->flash->addMessage('success', 'New user added');
                $this->flash->addMessage('success', 'Please login with your credentials');
                return $response->withRedirect($this->router->pathFor('login'));
            } else {
                $flash_messages['danger'] = $errors;
            }
        } else {
            $field_errors = $user_form['has_errors'];
        }
    }
    return $this->view->render($response, 'forms/users_register.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('register');
$app->map(['GET', 'POST'], '/users/edit', function ($request, $response, $args) {
    $field_errors = [];
    $flash_messages = $this->flash->getMessages();
开发者ID:BenHicksy,项目名称:dietddocs,代码行数:31,代码来源:userRoutes.php


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