user = $user; $this->status = $status; $this->data = $data; if ($data) { $this->message = $data->getMessage(); $this->token = $data->getToken(); $this->view = $data->getView(); $this->failReason = $data->getFailReason(); } } /** * Create an instance for a successful login. */ public static function success(User $user): self { return new self(self::STATUS_SUCCESS, $user); } /** * Create an instance for a failed login. */ public static function fail(?string $reason = null): self { $data = $reason ? Data::createWithFailReason($reason) : Data::create(); return new self(self::STATUS_FAIL, null, $data); } /** * Create an instance for a login requiring a second step. E.g. for 2FA. */ public static function secondStepRequired(User $user, Data $data): self { return new self(self::STATUS_SECOND_STEP_REQUIRED, $user, $data); } /** * Login is successful. */ public function isSuccess(): bool { return $this->status === self::STATUS_SUCCESS; } /** * Second step is required. E.g. for 2FA. */ public function isSecondStepRequired(): bool { return $this->status === self::STATUS_SECOND_STEP_REQUIRED; } /** * Login is failed. */ public function isFail(): bool { return $this->status === self::STATUS_FAIL; } /** * Get a user. */ public function getUser(): ?User { return $this->user; } /** * @deprecated Use `getUser`. */ public function getLoggedUser(): ?User { return $this->user; } /** * A status. */ public function getStatus(): string { return $this->status; } /** * A client view to redirect to for a second step. */ public function getView(): ?string { return $this->view; } /** * A message to show to a user for a second step. */ public function getMessage(): ?string { return $this->message; } /** * A token can be returned to a client to be used instead of password in a request for a second step. */ public function getToken(): ?string { return $this->token; } /** * Additional data that can be needed for a second step. */ public function getData(): ?stdClass { return $this->data ? $this->data->getData() : null; } /** * A fail reason. */ public function getFailReason(): ?string { return $this->failReason; } }