/** * Processes a verify email hash. * * @param string $token verification hash * * @return UserInterface|false */ public function verifyEmailWithToken($token) { $link = UserLink::where('link', $token)->where('type', UserLink::VERIFY_EMAIL)->first(); if (!$link) { return false; } $userClass = $this->getUserClass(); $user = new $userClass($link->user_id); // enable the user and delete the verify link $user->enable(); $link->delete(); // send a welcome email $user->sendEmail('welcome'); return $user; }
/** * Creates a temporary user. Useful for creating invites. * * @param array $data user data * * @return User temporary user */ public static function createTemporary($data) { $email = trim(strtolower(array_value($data, 'email'))); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } $insertArray = array_replace($data, ['enabled' => 0]); // create the temporary user $user = new static(); $driver = self::getDriver(); $created = $driver->createModel($user, $insertArray); if (!$created) { return false; } // get the new user ID $id = []; foreach (static::getIDProperties() as $k) { $id[] = $driver->getCreatedID($user, $k); } $user = new static($id); // create the temporary link $link = new UserLink(); $link->create(['user_id' => $user->id(), 'type' => UserLink::TEMPORARY]); return $user; }
/** * Builds a reset password link. * * @param int $userId * @param string $ip * @param string $userAgent * * @return UserLink */ public function buildLink($userId, $ip, $userAgent) { $link = new UserLink(); $link->user_id = $userId; $link->type = UserLink::FORGOT_PASSWORD; try { $link->save(); } catch (\Exception $e) { throw new \Exception("Could not create reset password link for user # {$userId}: " . $e->getMessage()); } // record the reset password request event $event = new AccountSecurityEvent(); $event->user_id = $userId; $event->type = AccountSecurityEvent::RESET_PASSWORD_REQUEST; $event->ip = $ip; $event->user_agent = $userAgent; $event->save(); return $link; }