diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 7594953..4cb03f5 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -3,37 +3,19 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller { - /* - |-------------------------------------------------------------------------- - | Login Controller - |-------------------------------------------------------------------------- - | - | This controller handles authenticating users for the application and - | redirecting them to your home screen. The controller uses a trait - | to conveniently provide its functionality to your applications. - | - */ - - use AuthenticatesUsers; - - /** - * Where to redirect users after login. - * - * @var string - */ - protected $redirectTo = '/home'; - - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() + public function login() { - $this->middleware('guest', ['except' => 'logout']); + if (! Auth::attempt(request(['email', 'password']))) { + return redirect('/login')->withErrors([ + 'email' => ['These credentials do not match our records.'], + ]); + } + + return redirect('/backstage/concerts'); } } diff --git a/routes/web.php b/routes/web.php index 6c261db..e5eba1c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,12 +11,8 @@ | */ -Route::get('/mockups/order', function () { - return view('orders.show'); -}); - Route::get('/concerts/{id}', 'ConcertsController@show'); - Route::post('/concerts/{id}/orders', 'ConcertOrdersController@store'); - Route::get('/orders/{confirmationNumber}', 'OrdersController@show'); + +Route::post('/login', 'Auth\LoginController@login'); diff --git a/tests/features/PromoterLoginTest.php b/tests/features/PromoterLoginTest.php new file mode 100644 index 0000000..090556a --- /dev/null +++ b/tests/features/PromoterLoginTest.php @@ -0,0 +1,67 @@ +disableExceptionHandling(); + + $user = factory(User::class)->create([ + 'email' => 'jane@example.com', + 'password' => bcrypt('super-secret-password'), + ]); + + $response = $this->post('/login', [ + 'email' => 'jane@example.com', + 'password' => 'super-secret-password', + ]); + + $response->assertRedirect('/backstage/concerts'); + $this->assertTrue(Auth::check()); + $this->assertTrue(Auth::user()->is($user)); + } + + /** @test */ + function logging_in_with_invalid_credentials() + { + $this->disableExceptionHandling(); + + $user = factory(User::class)->create([ + 'email' => 'jane@example.com', + 'password' => bcrypt('super-secret-password'), + ]); + + $response = $this->post('/login', [ + 'email' => 'jane@example.com', + 'password' => 'not-the-right-password', + ]); + + $response->assertRedirect('/login'); + $response->assertSessionHasErrors('email'); + $this->assertFalse(Auth::check()); + } + + /** @test */ + function logging_in_with_an_account_that_does_not_exist() + { + $this->disableExceptionHandling(); + + $response = $this->post('/login', [ + 'email' => 'nobody@example.com', + 'password' => 'not-the-right-password', + ]); + + $response->assertRedirect('/login'); + $response->assertSessionHasErrors('email'); + $this->assertFalse(Auth::check()); + } +}