diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php deleted file mode 100644 index 6a247fe..0000000 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ /dev/null @@ -1,32 +0,0 @@ -middleware('guest'); - } -} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 7594953..36ba950 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -36,4 +36,9 @@ class LoginController extends Controller { $this->middleware('guest', ['except' => 'logout']); } + + public function username() + { + return 'username'; + } } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php deleted file mode 100644 index cf726ee..0000000 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ /dev/null @@ -1,39 +0,0 @@ -middleware('guest'); - } -} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..a3af7dd --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,28 @@ +middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + return view('home'); + } +} diff --git a/app/User.php b/app/User.php index bfd96a6..9aca65b 100644 --- a/app/User.php +++ b/app/User.php @@ -26,4 +26,9 @@ class User extends Authenticatable protected $hidden = [ 'password', 'remember_token', ]; + + public function setPasswordAttribute($password) + { + $this->attributes['password'] = bcrypt($password); + } } diff --git a/artisan b/artisan old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json index eb080e9..eadeda1 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "type": "project", "require": { "php": ">=5.6.4", + "laravel/browser-kit-testing": "^1.0", "laravel/framework": "5.4.*", "laravel/tinker": "~1.0" }, diff --git a/composer.lock b/composer.lock index 07d394d..fe9d1cc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "96098e473b028cdb2529580554a1ae3e", + "content-hash": "84e5d69e0c52b9e0be3312d687b8482e", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -236,6 +236,53 @@ "time": "2015-04-20T18:58:01+00:00" }, { + "name": "laravel/browser-kit-testing", + "version": "v1.0.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/browser-kit-testing.git", + "reference": "0adfb725147815bff5516d157577f375a6e66ebd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/browser-kit-testing/zipball/0adfb725147815bff5516d157577f375a6e66ebd", + "reference": "0adfb725147815bff5516d157577f375a6e66ebd", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/css-selector": "~3.1", + "symfony/dom-crawler": "~3.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Laravel\\BrowserKitTesting\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Provides backwards compatibility for BrowserKit testing in Laravel 5.4.", + "keywords": [ + "laravel", + "testing" + ], + "time": "2017-02-08T22:32:37+00:00" + }, + { "name": "laravel/framework", "version": "v5.4.17", "source": { @@ -1209,6 +1256,62 @@ "time": "2017-03-28T21:38:24+00:00" }, { + "name": "symfony/dom-crawler", + "version": "v3.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/403944e294cf4ceb3b8447f54cbad88ea7b99cee", + "reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "symfony/css-selector": "~2.8|~3.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2017-02-21T09:12:04+00:00" + }, + { "name": "symfony/event-dispatcher", "version": "v3.2.7", "source": { diff --git a/config/app.php b/config/app.php index 135e977..7380f4f 100644 --- a/config/app.php +++ b/config/app.php @@ -12,7 +12,7 @@ return [ | any other location as required by the application or its packages. */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => 'Grosir Obat', /* |-------------------------------------------------------------------------- diff --git a/config/database.php b/config/database.php index a196943..0ecc5bc 100644 --- a/config/database.php +++ b/config/database.php @@ -47,8 +47,8 @@ return [ 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 7926c79..d74465d 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -13,12 +13,11 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ $factory->define(App\User::class, function (Faker\Generator $faker) { - static $password; return [ 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'password' => $password ?: $password = bcrypt('secret'), + 'username' => $faker->unique()->username, + 'password' => 'secret', 'remember_token' => str_random(10), ]; }); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 689cbee..bac8b58 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -16,7 +16,7 @@ class CreateUsersTable extends Migration Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); - $table->string('email')->unique(); + $table->string('username')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php deleted file mode 100644 index 0d5cb84..0000000 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ /dev/null @@ -1,32 +0,0 @@ -string('email')->index(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('password_resets'); - } -} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db6..2399bf1 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + $this->call(UsersTableSeeder::class); } } diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php new file mode 100644 index 0000000..1c7c7ac --- /dev/null +++ b/database/seeds/UsersTableSeeder.php @@ -0,0 +1,20 @@ +create([ + 'name' => 'Administrator', + 'username' => 'admin', + ]); + } +} diff --git a/phpunit.xml b/phpunit.xml index a2c496e..77231e9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -27,5 +27,7 @@ + + diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php new file mode 100644 index 0000000..96fd8ca --- /dev/null +++ b/resources/views/auth/login.blade.php @@ -0,0 +1,72 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Login
+
+
+ {{ csrf_field() }} + +
+ + +
+ + @if ($errors->has('username')) + + {{ $errors->first('username') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+@if (count($errors) > 0) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+@endif +@endsection diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..de73a98 --- /dev/null +++ b/resources/views/home.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Dashboard
+ +
+ You are logged in! +
+
+
+
+
+@endsection diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php new file mode 100644 index 0000000..5ec5531 --- /dev/null +++ b/resources/views/layouts/app.blade.php @@ -0,0 +1,85 @@ + + + + + + + + + + + {{ config('app.name', 'Laravel') }} + + + + + + + + +
+ + + @yield('content') +
+ + + + + diff --git a/routes/web.php b/routes/web.php index 810aa34..d8ab25e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,5 +12,9 @@ */ Route::get('/', function () { - return view('welcome'); + return redirect()->route('login'); }); + +Auth::routes(); + +Route::get('/home', 'HomeController@index')->name('home'); diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755 diff --git a/tests/BrowserKitTestCase.php b/tests/BrowserKitTestCase.php new file mode 100644 index 0000000..b940c44 --- /dev/null +++ b/tests/BrowserKitTestCase.php @@ -0,0 +1,15 @@ +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(); + } +} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 486dc27..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,23 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -}