本文整理汇总了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();