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