diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 890e9c880992..7ffca0c73d06 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -94,7 +94,7 @@ class Handler extends ExceptionHandler switch ($guard) { case 'contact': - $login = 'contact.login'; + $login = 'client.login'; break; case 'user': $login = 'login'; diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index d11b40bf309d..90a3d4bd4341 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -11,15 +11,18 @@ namespace App\Http\Controllers\Auth; -use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Auth; +use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Http\Request; use Route; class ContactLoginController extends Controller { - protected $redirectTo = '/contact'; + use AuthenticatesUsers; + + protected $redirectTo = '/client/dashboard'; public function __construct() { @@ -33,25 +36,34 @@ class ContactLoginController extends Controller public function login(Request $request) { - // Validate the form data - $this->validate($request, [ - 'email' => 'required|email', - 'password' => 'required|min:6' - ]); - - // Attempt to log the user in - if (Auth::guard('contact')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) { - // if successful, then redirect to their intended location - return redirect()->intended(route('contact.dashboard')); - } - // if unsuccessful, then redirect back to the login with the form data - return redirect()->back()->withInput($request->only('email', 'remember')); + Auth::shouldUse('contact'); + + $this->validateLogin($request); + + if ($this->hasTooManyLoginAttempts($request)) { + $this->fireLockoutEvent($request); + + return response()->json(['message' => 'Too many login attempts, you are being throttled']); + } + + if ($this->attemptLogin($request)) + return redirect()->intended(route('client.dashboard')); + else { + + $this->incrementLoginAttempts($request); + + return redirect()->back()->withInput($request->only('email', 'remember')); + } + + } public function logout() { + Auth::guard('contact')->logout(); - return redirect('/contact/login'); + + return redirect('/client/login'); } } \ No newline at end of file diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d6da8ebe21e7..5ca9eb1dc96c 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -59,6 +59,17 @@ class Kernel extends HttpKernel 'bindings', 'query_logging', ], + 'client' => [ + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, + \Illuminate\Session\Middleware\StartSession::class, + // \Illuminate\Session\Middleware\AuthenticateSession::class, + \Illuminate\View\Middleware\ShareErrorsFromSession::class, + \App\Http\Middleware\VerifyCsrfToken::class, + \Illuminate\Routing\Middleware\SubstituteBindings::class, + \App\Http\Middleware\StartupCheck::class, + \App\Http\Middleware\QueryLogging::class, + ], 'db' => [ \App\Http\Middleware\SetDb::class, ], diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 4a242458b401..e08c408453f9 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -29,7 +29,7 @@ class RedirectIfAuthenticated switch ($guard) { case 'contact': if (Auth::guard($guard)->check()) { - return redirect()->route('contact.dashboard'); + return redirect()->route('client.dashboard'); } break; case 'user': diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 8030b8190b70..94efcb339181 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -137,6 +137,8 @@ class RouteServiceProvider extends ServiceProvider $this->mapWebRoutes(); $this->mapContactApiRoutes(); + + $this->mapClientApiRoutes(); } /** @@ -182,5 +184,20 @@ class RouteServiceProvider extends ServiceProvider ->namespace($this->namespace) ->group(base_path('routes/contact.php')); } + + /** + * Define the "client" routes for the application. + * + * These routes are typically stateless. + * + * @return void + */ + protected function mapClientApiRoutes() + { + Route::prefix('') + ->middleware('client') + ->namespace($this->namespace) + ->group(base_path('routes/client.php')); + } } diff --git a/resources/views/auth/contact_login.blade.php b/resources/views/auth/contact_login.blade.php index 45bac0964530..8509b2f4711c 100644 --- a/resources/views/auth/contact_login.blade.php +++ b/resources/views/auth/contact_login.blade.php @@ -8,7 +8,12 @@
{{ __('Login') }}
-
+ @if (Session::has('error')) +
+
  • {!! Session::get('error') !!}
  • +
    + @endif + @csrf
    diff --git a/routes/client.php b/routes/client.php new file mode 100644 index 000000000000..0ffe9d6ad3f3 --- /dev/null +++ b/routes/client.php @@ -0,0 +1,14 @@ +name('client.login'); +Route::post('client/login', 'Auth\ContactLoginController@login')->name('client.login.submit'); + +//todo implement domain DB +//Route::group(['middleware' => ['auth:contact', 'domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () { +Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'client.'], function () { + + Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit + + Route::get('logout', 'Auth\ContactLoginController@logout')->name('logout'); + +}); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index f962598f14f8..611774f48c90 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,9 +15,6 @@ Route::redirect('/', '/login', 301); Route::get('signup', 'AccountController@index')->name('signup'); Route::post('signup', 'AccountController@store')->name('signup.submit'); -Route::get('contact/login', 'Auth\ContactLoginController@showLoginForm')->name('contact.login'); -Route::post('contact/login', 'Auth\ContactLoginController@login')->name('contact.login.submit'); - /* * Password Reset Routes... */ @@ -94,17 +91,7 @@ Route::group(['middleware' => ['url_db']], function () { }); -/* -Authenticated Contact Routes - */ -Route::group(['prefix' => 'contact', 'middleware' => 'auth:contact'], function () { - - Route::get('/', 'ClientPortal\DashboardController@index')->name('contact.dashboard'); - - Route::get('logout', 'Auth\ContactLoginController@logout')->name('contact.logout'); - -}); /* * Injects users translation strings in json format for frontend consumption.