-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from aryehraber/feat/support-login
Support Login event
- Loading branch information
Showing
4 changed files
with
42 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
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,37 @@ | ||
<?php | ||
|
||
namespace AryehRaber\Captcha\Listeners; | ||
|
||
use AryehRaber\Captcha\Captcha; | ||
use Illuminate\Auth\Events\Login; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
class ValidateUserLogin | ||
{ | ||
protected $captcha; | ||
|
||
public function __construct(Captcha $captcha) | ||
{ | ||
$this->captcha = $captcha; | ||
} | ||
|
||
public function handle(Login $event) | ||
{ | ||
$user = $event->user; | ||
|
||
if (! $this->shouldVerify()) { | ||
return $user; | ||
} | ||
|
||
if ($this->captcha->verify()->invalidResponse()) { | ||
throw ValidationException::withMessages(['captcha' => config('captcha.error_message')]); | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
protected function shouldVerify() | ||
{ | ||
return config('captcha.user_login', false); | ||
} | ||
} |