Changeset View
Changeset View
Standalone View
Standalone View
src/app/AuthAttempt.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | class AuthAttempt extends Model | ||||
/** | /** | ||||
* Returns true if the authentication attempt is accepted. | * Returns true if the authentication attempt is accepted. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isAccepted(): bool | public function isAccepted(): bool | ||||
{ | { | ||||
if ($this->status == self::STATUS_ACCEPTED && Carbon::now() < $this->expires_at) { | return $this->status == self::STATUS_ACCEPTED && Carbon::now() < $this->expires_at; | ||||
return true; | |||||
} | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns true if the authentication attempt is denied. | * Returns true if the authentication attempt is denied. | ||||
* | * | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function isDenied(): bool | public function isDenied(): bool | ||||
{ | { | ||||
return ($this->status == self::STATUS_DENIED); | return $this->status == self::STATUS_DENIED; | ||||
} | } | ||||
/** | /** | ||||
* Accept the authentication attempt. | * Accept the authentication attempt. | ||||
*/ | */ | ||||
public function accept($reason = AuthAttempt::REASON_NONE) | public function accept($reason = AuthAttempt::REASON_NONE) | ||||
{ | { | ||||
$this->expires_at = Carbon::now()->addHours(8); | $this->expires_at = Carbon::now()->addHours(8); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | class AuthAttempt extends Model | ||||
* | * | ||||
* @return bool Returns true if the attempt is accepted on confirmation | * @return bool Returns true if the attempt is accepted on confirmation | ||||
*/ | */ | ||||
public function waitFor2FA(): bool | public function waitFor2FA(): bool | ||||
{ | { | ||||
if ($this->isAccepted()) { | if ($this->isAccepted()) { | ||||
return true; | return true; | ||||
} | } | ||||
if ($this->isDenied()) { | if ($this->isDenied()) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!$this->notifyAndWait()) { | if (!$this->notifyAndWait()) { | ||||
return false; | return false; | ||||
} | } | ||||
return $this->isAccepted(); | return $this->isAccepted(); | ||||
} | } | ||||
} | } |