This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'totp_code' => 'The Code is invalid or has expired.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'totp_code' => 'Kod geçersiz veya süresi dolmuş.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace DarkGhostHunter\Laraguard\Rules; | ||
|
||
use DarkGhostHunter\Laraguard\Contracts\TwoFactorAuthenticatable; | ||
use Illuminate\Contracts\Validation\Rule; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class TotpCode implements Rule | ||
{ | ||
/** | ||
* The name of the rule. | ||
* | ||
* @var string | ||
*/ | ||
protected $rule = 'totp_code'; | ||
|
||
/** | ||
* The auth user. | ||
* | ||
* @var \Illuminate\Foundation\Auth\User | ||
*/ | ||
protected $user; | ||
|
||
/** | ||
* Create a new "totp code" rule instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->user = Auth::user(); | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) : bool | ||
{ | ||
if ($this->user instanceof TwoFactorAuthenticatable) { | ||
return is_string($value) && $this->user->twoFactorAuth->validateCode($value); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() : string | ||
{ | ||
return __('laraguard::messages.totp_code'); | ||
} | ||
|
||
/** | ||
* Convert the rule to a validation string. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() : string | ||
{ | ||
return "{$this->rule}"; | ||
} | ||
} |