Skip to content

Commit

Permalink
Merge pull request #1833 from area17/backport-user-login-disable
Browse files Browse the repository at this point in the history
[2.x] login disable fix
  • Loading branch information
haringsrob authored Sep 30, 2022
2 parents 55f2380 + dc1e934 commit 31b01e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Http/Controllers/Admin/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,15 @@ public function linkProvider(Request $request)
return $this->sendFailedLoginResponse($request);
}
}

/**
* @param Request $request
* @return array
*
* This method checks to make sure the user is published.
*/
protected function credentials($request)
{
return array_merge($request->only($this->username(), 'password'), ['published' => 1]);
}
}
29 changes: 29 additions & 0 deletions src/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,38 @@
namespace A17\Twill\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;

class Authenticate extends Middleware
{

/**
* @param $request
* @param \Closure $next
* @param ...$guards
* @return mixed
*/
public function handle($request, $next, ...$guards)
{
$this->authenticate($request, $guards);

if (
(
!$request->user() ||
!$request->user()->published
) && $request->route()->getName() !== 'admin.login.form'
) {
Auth::logout();
return $request->expectsJson()
? abort(403, 'Your account is not verified.')
: Redirect::guest(URL::route('admin.login.form'));
}

return $next($request);
}

/**
* Get the path the user should be redirected to when they are not authenticated.
*
Expand Down

0 comments on commit 31b01e4

Please sign in to comment.