mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-30 16:30:45 +00:00
Update DangerZone/Sudo middleware
This commit is contained in:
parent
88534f2deb
commit
6a16559132
2 changed files with 19 additions and 1 deletions
|
@ -270,7 +270,6 @@ class AccountController extends Controller
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function unblock(Request $request)
|
public function unblock(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
@ -362,6 +361,13 @@ class AccountController extends Controller
|
||||||
|
|
||||||
public function sudoMode(Request $request)
|
public function sudoMode(Request $request)
|
||||||
{
|
{
|
||||||
|
if($request->session()->has('sudoModeAttempts') && $request->session()->get('sudoModeAttempts') >= 3) {
|
||||||
|
$request->session()->pull('2fa.session.active');
|
||||||
|
$request->session()->pull('redirectNext');
|
||||||
|
$request->session()->pull('sudoModeAttempts');
|
||||||
|
Auth::logout();
|
||||||
|
return redirect(route('login'));
|
||||||
|
}
|
||||||
return view('auth.sudo');
|
return view('auth.sudo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +379,12 @@ class AccountController extends Controller
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$password = $request->input('password');
|
$password = $request->input('password');
|
||||||
$next = $request->session()->get('redirectNext', '/');
|
$next = $request->session()->get('redirectNext', '/');
|
||||||
|
if($request->session()->has('sudoModeAttempts')) {
|
||||||
|
$count = (int) $request->session()->get('sudoModeAttempts');
|
||||||
|
$request->session()->put('sudoModeAttempts', $count + 1);
|
||||||
|
} else {
|
||||||
|
$request->session()->put('sudoModeAttempts', 1);
|
||||||
|
}
|
||||||
if(password_verify($password, $user->password) === true) {
|
if(password_verify($password, $user->password) === true) {
|
||||||
$request->session()->put('sudoMode', time());
|
$request->session()->put('sudoMode', time());
|
||||||
return redirect($next);
|
return redirect($next);
|
||||||
|
|
|
@ -16,6 +16,12 @@ class DangerZone
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
|
if( $request->session()->get('sudoModeAttempts') > 3) {
|
||||||
|
$request->session()->pull('redirectNext');
|
||||||
|
$request->session()->pull('sudoModeAttempts');
|
||||||
|
Auth::logout();
|
||||||
|
return redirect(route('login'));
|
||||||
|
}
|
||||||
if(!Auth::check()) {
|
if(!Auth::check()) {
|
||||||
return redirect(route('login'));
|
return redirect(route('login'));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue