Browse Source
Added Login and Logout with testing
Added Login and Logout with testing
Login using username Removed Forgot and reset password feature Added BrowserKitTesting package Change App Name config to "Grosir Obat" Update database config charset and collation to "utf8"pull/1/head
31 changed files with 420 additions and 136 deletions
-
32app/Http/Controllers/Auth/ForgotPasswordController.php
-
5app/Http/Controllers/Auth/LoginController.php
-
39app/Http/Controllers/Auth/ResetPasswordController.php
-
28app/Http/Controllers/HomeController.php
-
5app/User.php
-
0artisan
-
1composer.json
-
105composer.lock
-
2config/app.php
-
4config/database.php
-
5database/factories/ModelFactory.php
-
2database/migrations/2014_10_12_000000_create_users_table.php
-
32database/migrations/2014_10_12_100000_create_password_resets_table.php
-
2database/seeds/DatabaseSeeder.php
-
20database/seeds/UsersTableSeeder.php
-
2phpunit.xml
-
72resources/views/auth/login.blade.php
-
17resources/views/home.blade.php
-
85resources/views/layouts/app.blade.php
-
6routes/web.php
-
0storage/app/.gitignore
-
0storage/app/public/.gitignore
-
0storage/framework/.gitignore
-
0storage/framework/cache/.gitignore
-
0storage/framework/sessions/.gitignore
-
0storage/framework/testing/.gitignore
-
0storage/framework/views/.gitignore
-
0storage/logs/.gitignore
-
15tests/BrowserKitTestCase.php
-
54tests/Feature/Auth/UserLoginTest.php
-
23tests/Feature/ExampleTest.php
@ -1,32 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Auth; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; |
|||
|
|||
class ForgotPasswordController extends Controller |
|||
{ |
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| Password Reset Controller |
|||
|-------------------------------------------------------------------------- |
|||
| |
|||
| This controller is responsible for handling password reset emails and |
|||
| includes a trait which assists in sending these notifications from |
|||
| your application to your users. Feel free to explore this trait. |
|||
| |
|||
*/ |
|||
|
|||
use SendsPasswordResetEmails; |
|||
|
|||
/** |
|||
* Create a new controller instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->middleware('guest'); |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Auth; |
|||
|
|||
use App\Http\Controllers\Controller; |
|||
use Illuminate\Foundation\Auth\ResetsPasswords; |
|||
|
|||
class ResetPasswordController extends Controller |
|||
{ |
|||
/* |
|||
|-------------------------------------------------------------------------- |
|||
| Password Reset Controller |
|||
|-------------------------------------------------------------------------- |
|||
| |
|||
| This controller is responsible for handling password reset requests |
|||
| and uses a simple trait to include this behavior. You're free to |
|||
| explore this trait and override any methods you wish to tweak. |
|||
| |
|||
*/ |
|||
|
|||
use ResetsPasswords; |
|||
|
|||
/** |
|||
* Where to redirect users after resetting their password. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $redirectTo = '/home'; |
|||
|
|||
/** |
|||
* Create a new controller instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->middleware('guest'); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers; |
|||
|
|||
use Illuminate\Http\Request; |
|||
|
|||
class HomeController extends Controller |
|||
{ |
|||
/** |
|||
* Create a new controller instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->middleware('auth'); |
|||
} |
|||
|
|||
/** |
|||
* Show the application dashboard. |
|||
* |
|||
* @return \Illuminate\Http\Response |
|||
*/ |
|||
public function index() |
|||
{ |
|||
return view('home'); |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Support\Facades\Schema; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Database\Migrations\Migration; |
|||
|
|||
class CreatePasswordResetsTable extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function up() |
|||
{ |
|||
Schema::create('password_resets', function (Blueprint $table) { |
|||
$table->string('email')->index(); |
|||
$table->string('token'); |
|||
$table->timestamp('created_at')->nullable(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function down() |
|||
{ |
|||
Schema::dropIfExists('password_resets'); |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<?php |
|||
|
|||
use App\User; |
|||
use Illuminate\Database\Seeder; |
|||
|
|||
class UsersTableSeeder extends Seeder |
|||
{ |
|||
/** |
|||
* Run the database seeds. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function run() |
|||
{ |
|||
factory(User::class)->create([ |
|||
'name' => 'Administrator', |
|||
'username' => 'admin', |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('content') |
|||
<div class="container"> |
|||
<div class="row"> |
|||
<div class="col-md-8 col-md-offset-2"> |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading">Login</div> |
|||
<div class="panel-body"> |
|||
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}"> |
|||
{{ csrf_field() }} |
|||
|
|||
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}"> |
|||
<label for="username" class="col-md-4 control-label">Username</label> |
|||
|
|||
<div class="col-md-6"> |
|||
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus> |
|||
@if ($errors->has('username')) |
|||
<span class="help-block"> |
|||
<strong>{{ $errors->first('username') }}</strong> |
|||
</span> |
|||
@endif |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> |
|||
<label for="password" class="col-md-4 control-label">Password</label> |
|||
|
|||
<div class="col-md-6"> |
|||
<input id="password" type="password" class="form-control" name="password" required> |
|||
|
|||
@if ($errors->has('password')) |
|||
<span class="help-block"> |
|||
<strong>{{ $errors->first('password') }}</strong> |
|||
</span> |
|||
@endif |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group"> |
|||
<div class="col-md-6 col-md-offset-4"> |
|||
<div class="checkbox"> |
|||
<label> |
|||
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me |
|||
</label> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group"> |
|||
<div class="col-md-8 col-md-offset-4"> |
|||
<button type="submit" class="btn btn-primary"> |
|||
Login |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@if (count($errors) > 0) |
|||
<div class="alert alert-danger"> |
|||
<ul> |
|||
@foreach ($errors->all() as $error) |
|||
<li>{{ $error }}</li> |
|||
@endforeach |
|||
</ul> |
|||
</div> |
|||
@endif |
|||
@endsection |
|||
@ -0,0 +1,17 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('content') |
|||
<div class="container"> |
|||
<div class="row"> |
|||
<div class="col-md-8 col-md-offset-2"> |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading">Dashboard</div> |
|||
|
|||
<div class="panel-body"> |
|||
You are logged in! |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -0,0 +1,85 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="{{ config('app.locale') }}"> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|||
|
|||
<!-- CSRF Token --> |
|||
<meta name="csrf-token" content="{{ csrf_token() }}"> |
|||
|
|||
<title>{{ config('app.name', 'Laravel') }}</title> |
|||
|
|||
<!-- Styles --> |
|||
<link href="{{ asset('css/app.css') }}" rel="stylesheet"> |
|||
|
|||
<!-- Scripts --> |
|||
<script> |
|||
window.Laravel = {!! json_encode([ |
|||
'csrfToken' => csrf_token(), |
|||
]) !!}; |
|||
</script> |
|||
</head> |
|||
<body> |
|||
<div id="app"> |
|||
<nav class="navbar navbar-default navbar-static-top"> |
|||
<div class="container"> |
|||
<div class="navbar-header"> |
|||
|
|||
<!-- Collapsed Hamburger --> |
|||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse"> |
|||
<span class="sr-only">Toggle Navigation</span> |
|||
<span class="icon-bar"></span> |
|||
<span class="icon-bar"></span> |
|||
<span class="icon-bar"></span> |
|||
</button> |
|||
|
|||
<!-- Branding Image --> |
|||
<a class="navbar-brand" href="{{ url('/') }}"> |
|||
{{ config('app.name', 'Laravel') }} |
|||
</a> |
|||
</div> |
|||
|
|||
<div class="collapse navbar-collapse" id="app-navbar-collapse"> |
|||
<!-- Left Side Of Navbar --> |
|||
<ul class="nav navbar-nav"> |
|||
|
|||
</ul> |
|||
|
|||
<!-- Right Side Of Navbar --> |
|||
<ul class="nav navbar-nav navbar-right"> |
|||
<!-- Authentication Links --> |
|||
@if (Auth::check()) |
|||
<li class="dropdown"> |
|||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> |
|||
{{ Auth::user()->name }} <span class="caret"></span> |
|||
</a> |
|||
|
|||
<ul class="dropdown-menu" role="menu"> |
|||
<li> |
|||
<a href="{{ route('logout') }}" |
|||
onclick="event.preventDefault();
|
|||
document.getElementById('logout-form').submit();">
|
|||
Logout |
|||
</a> |
|||
|
|||
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;"> |
|||
{{ csrf_field() }} |
|||
<button type="submit" style="display: none;" id="logout-button" >Logout</button> |
|||
</form> |
|||
</li> |
|||
</ul> |
|||
</li> |
|||
@endif |
|||
</ul> |
|||
</div> |
|||
</div> |
|||
</nav> |
|||
|
|||
@yield('content') |
|||
</div> |
|||
|
|||
<!-- Scripts --> |
|||
<script src="{{ asset('js/app.js') }}"></script> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
namespace Tests; |
|||
|
|||
use App\Entities\Customers\Customer; |
|||
use App\Entities\Invoices\Invoice; |
|||
use App\Entities\Receipts\Receipt; |
|||
use App\Entities\Users\User; |
|||
|
|||
abstract class BrowserKitTestCase extends \Laravel\BrowserKitTesting\TestCase |
|||
{ |
|||
use CreatesApplication; |
|||
|
|||
protected $baseUrl = 'http://localhost'; |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?php |
|||
|
|||
namespace Tests\Feature\Auth; |
|||
|
|||
use App\User; |
|||
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|||
use Tests\BrowserKitTestCase; |
|||
|
|||
class UserLoginTest extends BrowserKitTestCase |
|||
{ |
|||
use DatabaseMigrations; |
|||
|
|||
/** @test */ |
|||
public function it_validates_the_login_form() |
|||
{ |
|||
$this->visit(route('login')) |
|||
->type('foobar', 'username') |
|||
->type('secret', 'password') |
|||
->press('Login') |
|||
->dontSeeIsAuthenticated() |
|||
->seePageIs(route('login')); |
|||
$this->see(trans('auth.failed')); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function user_can_login() |
|||
{ |
|||
$user = factory(User::class)->create(['password' => '123456']); |
|||
|
|||
$this->visit(route('login')); |
|||
$this->type($user->username,'username'); |
|||
$this->type('123456','password'); |
|||
$this->press('Login'); |
|||
|
|||
$this->seePageIs(route('home')); |
|||
$this->see($user->name); |
|||
|
|||
// $this->dump();
|
|||
|
|||
$this->press('logout-button'); |
|||
$this->seePageIs(route('login')); |
|||
} |
|||
|
|||
/** @test */ |
|||
public function it_can_logout_of_the_application() |
|||
{ |
|||
$user = factory(User::class)->create(['password' => '123456']); |
|||
$this->actingAs($user) |
|||
->visit(route('home')) |
|||
->press('logout-button') |
|||
->seePageis(route('login')) |
|||
->dontSeeIsAuthenticated(); |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace Tests\Feature; |
|||
|
|||
use Tests\TestCase; |
|||
use Illuminate\Foundation\Testing\WithoutMiddleware; |
|||
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|||
use Illuminate\Foundation\Testing\DatabaseTransactions; |
|||
|
|||
class ExampleTest extends TestCase |
|||
{ |
|||
/** |
|||
* A basic test example. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function testBasicTest() |
|||
{ |
|||
$response = $this->get('/'); |
|||
|
|||
$response->assertStatus(200); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue