TwoFactor
TwoFactor copied to clipboard
[2.x] Expose attemptWhen method
Description
This feature branch adds and exposes the attemptWhen method to/on the TwoFactorLoginHelper and Auth2FA. This allows projects that need to pass their own callbacks for pre-login checks to integrate with this package.
This will not break backward compatibility since it merely adds a new method.
Code samples
This PR simply adds a new method matching the signature of the SessionGuard's method:
public function attemptWhen(array $credentials = [], $callbacks = null, $remember = false): bool
{
// Code same as old `attempt` method.
// Only change: merge $callbacks and the TwoFactor callback
// ...
return $guard->attemptWhen(
$credentials, array_merge(Arr::wrap($callbacks), [TwoFactor::hasCodeOrFails($this->input, $this->message)]), $remember
);
// ...
}
And changes the current attempt method to call this new method passing null as $callbacks:
public function attempt(array $credentials = [], $remember = false): bool
{
return $this->attemptWhen($credentials, null, $remember);
}
This approach seems cleaner than simply duplicating the code (which is actually what the SessionGuard does).
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
48ef0b9) to head (e502f57). Report is 1 commits behind head on 2.x.
Additional details and impacted files
@@ Coverage Diff @@
## 2.x #80 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 157 158 +1
===========================================
Files 20 20
Lines 444 446 +2
===========================================
+ Hits 444 446 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.