本文整理汇总了PHP中UserMapper::verifyUser方法的典型用法代码示例。如果您正苦于以下问题:PHP UserMapper::verifyUser方法的具体用法?PHP UserMapper::verifyUser怎么用?PHP UserMapper::verifyUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserMapper
的用法示例。
在下文中一共展示了UserMapper::verifyUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postAction
public function postAction($request, $db)
{
// check element 3, there's no user associated with the not-logged-in collections
if (isset($request->url_elements[3])) {
switch ($request->url_elements[3]) {
case 'verifications':
$user_mapper = new UserMapper($db, $request);
$token = filter_var($request->getParameter("token"), FILTER_SANITIZE_STRING);
if (empty($token)) {
throw new Exception("Verification token must be supplied", 400);
} else {
$success = $user_mapper->verifyUser($token);
if ($success) {
header("Content-Length: 0", null, 204);
exit;
// no more content
} else {
throw new Exception("Verification failed", 400);
}
}
break;
default:
throw new InvalidArgumentException('Unknown Subrequest', 404);
break;
}
} else {
$user = array();
$errors = array();
$user_mapper = new UserMapper($db, $request);
// Required Fields
$user['username'] = filter_var(trim($request->getParameter("username")), FILTER_SANITIZE_STRING);
if (empty($user['username'])) {
$errors[] = "'username' is a required field";
} else {
// does anyone else have this username?
$existing_user = $user_mapper->getUserByUsername($user['username']);
if ($existing_user['users']) {
$errors[] = "That username is already in use. Choose another";
}
}
$user['full_name'] = filter_var(trim($request->getParameter("full_name")), FILTER_SANITIZE_STRING);
if (empty($user['full_name'])) {
$errors[] = "'full_name' is a required field";
}
$user['email'] = filter_var(trim($request->getParameter("email")), FILTER_VALIDATE_EMAIL);
if (empty($user['email'])) {
$errors[] = "A valid entry for 'email' is required";
} else {
// does anyone else have this email?
$existing_user = $user_mapper->getUserByEmail($user['email']);
if ($existing_user['users']) {
$errors[] = "That email is already associated with another account";
}
}
$password = $request->getParameter("password");
if (empty($password)) {
$errors[] = "'password' is a required field";
} else {
// check it's sane
$validity = $user_mapper->checkPasswordValidity($password);
if (true === $validity) {
// OK good, go ahead
$user['password'] = $password;
} else {
// the password wasn't acceptable, tell the user why
$errors = array_merge($errors, $validity);
}
}
// Optional Fields
$user['twitter_username'] = filter_var(trim($request->getParameter("twitter_username")), FILTER_SANITIZE_STRING);
// How does it look? With no errors, we can proceed
if ($errors) {
throw new Exception(implode(". ", $errors), 400);
} else {
$user_id = $user_mapper->createUser($user);
header("Location: " . $request->base . $request->path_info . '/' . $user_id, null, 201);
// autoverify for test platforms
if (isset($this->config['features']['allow_auto_verify_users']) && $this->config['features']['allow_auto_verify_users']) {
if ($request->getParameter("auto_verify_user") == "true") {
// the test suite sends this extra field, if we got
// this far then this platform supports this
$user_mapper->verifyThisTestUser($user_id);
}
}
// Generate a verification token and email it to the user
$token = $user_mapper->generateEmailVerificationTokenForUserId($user_id);
$recipients = array($user['email']);
$emailService = new UserRegistrationEmailService($this->config, $recipients, $token);
$emailService->sendEmail();
exit;
}
}
}