本文整理匯總了PHP中App\Model\User::unguard方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::unguard方法的具體用法?PHP User::unguard怎麽用?PHP User::unguard使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類App\Model\User
的用法示例。
在下文中一共展示了User::unguard方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: signup
public function signup(UserSignupEvent $event)
{
$signup = [];
$fields = ['ident', 'email', 'contact_email', 'password', 'first_name', 'last_name', 'photo_url', 'tz_offset', 'ip_addr', 'http_referrer', 'http_campaign', 'verified'];
$default = function ($field) use($event) {
if ($field == 'photo_url' && ($email = $event->email)) {
$gravatar = sprintf("http://www.gravatar.com/avatar/%s?d=404", md5(strtolower($email)));
if ($headers = get_headers($gravatar, 1)) {
if (strpos($headers[0], '200')) {
return $gravatar;
}
}
} elseif ($field == 'contact_email') {
return $event->email ?? null;
} elseif ($field == 'password') {
return bin2hex(openssl_random_pseudo_bytes(4));
} elseif ($field == 'http_referrer') {
$value = $_COOKIE[Router::HTTP_REFERRER_COOKIE] ?? '/';
return $value !== '/' ? $value : null;
} elseif ($field == 'http_campaign') {
return $_COOKIE[Router::HTTP_CAMPAIGN_COOKIE] ?? null;
} elseif ($field == 'tz_offset') {
return $_COOKIE['tz_offset'] ?? 240;
} elseif ($field == 'verified') {
return 'false';
}
return null;
};
foreach ($fields as $field) {
$signup[$field] = $event->{$field} ?? $default($field);
if ($field == 'password') {
$signup[$field] = password_hash($signup[$field], PASSWORD_DEFAULT);
}
}
if (filter_var($signup['email'] ?? null, FILTER_VALIDATE_EMAIL) || !empty($signup['ident'])) {
try {
User::unguard();
$user = new User($signup);
$this->modelAutoFill->fillMissing($user);
if ($user->save()) {
$event->setUser($user);
$signupEvent = (new UserSignupEvent($signup))->setUser($user);
try {
$this->dispatcher->fire(UserSignupEvent::USER_SIGNUP_COMPLETE, $signupEvent);
} catch (\Throwable $e) {
$this->logger->warn("Plugin error during signup: " . $e->getMessage());
}
}
} catch (QueryException $e) {
$event->setError("EMAIL_IN_USE");
} catch (\Exception $e) {
$event->setError($e->getMessage());
}
} else {
$event->setError('INVALID_DATA');
}
if (!$event->getUser()) {
//for logging
$this->dispatcher->fire(UserSignupEvent::USER_SIGNUP_FAIL, $event);
}
}