Permalink
Browse files

allow login to be disabled

  • Loading branch information...
laurencei committed Feb 22, 2018
1 parent d8bbff4 commit c95b0d8488d7fffec1f0ea112a7f66a80daa7416
Showing with 32 additions and 0 deletions.
  1. +8 −0 app/Http/Controllers/AuthController.php
  2. +24 −0 tests/Controllers/AuthControllerTest.php
@@ -15,6 +15,10 @@ class AuthController extends Controller
*/
public function login(Request $request)
{
if (config('eyewitness.login_disabled', false)) {
return redirect('/');
}
if ($request->session()->has('eyewitness:auth') || Eye::check($request)) {
return redirect(route('eyewitness.dashboard').'#overview');
}
@@ -29,6 +33,10 @@ public function login(Request $request)
*/
public function authenticate(Request $request)
{
if (config('eyewitness.login_disabled', false)) {
return redirect('/');
}
if (! app(Eye::class)->checkConfig()) {
return redirect()->route('eyewitness.login')->withError('Eyewitness has not been configured correctly. Login has been disabled for your security. Please run "php artisan eyewitness:debug" to determine the issue.');
}
@@ -15,6 +15,16 @@ public function test_login_page_loads()
$response->assertStatus(200);
}
public function test_login_page_redirects_if_disabled()
{
$this->app['config']->set('eyewitness.login_disabled', true);
$response = $this->get($this->home);
$response->assertRedirect('/');
$response->assertSessionMissing('eyewitness:auth');
}
public function test_login_page_redirects_to_dashboard_if_logged_in()
{
$response = $this->withSession(['eyewitness:auth' => 1])
@@ -67,6 +77,20 @@ public function test_authenticate_accepts_correct_details_and_logs_in()
$response->assertSessionHas('eyewitness:auth', 1);
}
public function test_authenticate_wont_work_if_login_disabled()
{
$this->app['config']->set('eyewitness.login_disabled', true);
$response = $this->post($this->home,
['app_token' => config('eyewitness.app_token'),
'secret_key' => config('eyewitness.secret_key')]);
$response = $this->get($this->home);
$response->assertRedirect('/');
$response->assertSessionMissing('eyewitness:auth');
}
public function test_closure_auth_succeds()
{
Eye::auth(function ($request) {

0 comments on commit c95b0d8

Please sign in to comment.