Changeset View
Changeset View
Standalone View
Standalone View
src/app/AuthAttempt.php
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | class AuthAttempt extends Model | ||||
/** | /** | ||||
* Notify the user of this authentication attempt. | * Notify the user of this authentication attempt. | ||||
* | * | ||||
* @return bool false if there was no means to notify | * @return bool false if there was no means to notify | ||||
*/ | */ | ||||
public function notify(): bool | public function notify(): bool | ||||
{ | { | ||||
return CompanionApp::notifyUser($this->user_id, ['token' => $this->id]); | // TODO: Standardize the message type/content | ||||
return \App\Backends\Events::pushMessage($this->user, ['auth' => $this->id]); | |||||
// return CompanionApp::notifyUser($this->user_id, ['token' => $this->id]); | |||||
} | } | ||||
/** | /** | ||||
* Notify the user and wait for a confirmation. | * Notify the user and wait for a confirmation. | ||||
*/ | */ | ||||
private function notifyAndWait() | private function notifyAndWait() | ||||
{ | { | ||||
if (!$this->notify()) { | if (!$this->notify()) { | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public static function recordAuthAttempt(User $user, $clientIP) | ||||
$authAttempt->last_seen = Carbon::now(); | $authAttempt->last_seen = Carbon::now(); | ||||
$authAttempt->save(); | $authAttempt->save(); | ||||
return $authAttempt; | return $authAttempt; | ||||
} | } | ||||
/** | /** | ||||
* The authenticating user. | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |||||
*/ | |||||
public function user() | |||||
{ | |||||
return $this->belongsTo(User::class); | |||||
} | |||||
/** | |||||
* Trigger a notification if necessary and wait for confirmation. | * Trigger a notification if necessary and wait for confirmation. | ||||
* | * | ||||
* @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; | ||||
Show All 13 Lines |