Flarum\Core\PasswordToken::generate PHP Méthode

generate() public static méthode

Generate a password token for the specified user.
public static generate ( integer $userId ) : static
$userId integer
Résultat static
    public static function generate($userId)
    {
        $token = new static();
        $token->id = str_random(40);
        $token->user_id = $userId;
        $token->created_at = time();
        return $token;
    }

Usage Example

 /**
  * @param RequestPasswordReset $command
  * @return \Flarum\Core\User
  * @throws ModelNotFoundException
  */
 public function handle(RequestPasswordReset $command)
 {
     $user = $this->users->findByEmail($command->email);
     if (!$user) {
         throw new ModelNotFoundException();
     }
     $token = PasswordToken::generate($user->id);
     $token->save();
     $data = ['username' => $user->username, 'url' => $this->url->toRoute('resetPassword', ['token' => $token->id]), 'forumTitle' => $this->settings->get('forum_title')];
     $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use($user) {
         $message->to($user->email);
         $message->subject('Reset Your Password');
     });
     return $user;
 }
All Usage Examples Of Flarum\Core\PasswordToken::generate
PasswordToken