From 2247bb5ff215346f7ddeb19b2aa0b50a5a873d94 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Mon, 26 Jun 2017 13:15:36 +0800 Subject: [PATCH] Added user auth scaffold and prepare families action forms --- app/Http/Controllers/Auth/RegisterController.php | 2 + app/Http/Controllers/HomeController.php | 28 +++++++ app/User.php | 9 +++ composer.json | 3 +- composer.lock | 96 ++++++++++++++++++++++- config/app.php | 11 ++- config/database.php | 4 +- resources/views/auth/login.blade.php | 68 ++++++++++++++++ resources/views/auth/passwords/email.blade.php | 46 +++++++++++ resources/views/auth/passwords/reset.blade.php | 76 ++++++++++++++++++ resources/views/auth/register.blade.php | 98 ++++++++++++++++++++++++ resources/views/home.blade.php | 96 +++++++++++++++++++++++ resources/views/layouts/app.blade.php | 80 +++++++++++++++++++ routes/web.php | 5 ++ storage/app/.gitignore | 0 storage/app/public/.gitignore | 0 storage/framework/.gitignore | 0 storage/framework/cache/.gitignore | 0 storage/framework/sessions/.gitignore | 0 storage/framework/testing/.gitignore | 0 storage/framework/views/.gitignore | 0 storage/logs/.gitignore | 0 tests/Feature/ManageUserFamiliesTest.php | 25 ++++++ tests/TestCase.php | 1 + 24 files changed, 641 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/HomeController.php create mode 100644 resources/views/auth/login.blade.php create mode 100644 resources/views/auth/passwords/email.blade.php create mode 100644 resources/views/auth/passwords/reset.blade.php create mode 100644 resources/views/auth/register.blade.php create mode 100644 resources/views/home.blade.php create mode 100644 resources/views/layouts/app.blade.php mode change 100644 => 100755 storage/app/.gitignore mode change 100644 => 100755 storage/app/public/.gitignore mode change 100644 => 100755 storage/framework/.gitignore mode change 100644 => 100755 storage/framework/cache/.gitignore mode change 100644 => 100755 storage/framework/sessions/.gitignore mode change 100644 => 100755 storage/framework/testing/.gitignore mode change 100644 => 100755 storage/framework/views/.gitignore mode change 100644 => 100755 storage/logs/.gitignore create mode 100644 tests/Feature/ManageUserFamiliesTest.php diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index ed8d1b7..568c23b 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -63,7 +63,9 @@ class RegisterController extends Controller protected function create(array $data) { return User::create([ + 'nickname' => $data['nickname'], 'name' => $data['name'], + 'gender_id' => $data['gender_id'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..10f3148 --- /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', ['currentUser' => auth()->user()]); + } +} diff --git a/app/User.php b/app/User.php index 040fe28..f1f4adc 100644 --- a/app/User.php +++ b/app/User.php @@ -31,6 +31,15 @@ class User extends Authenticatable 'password', 'remember_token', ]; + protected $appends = [ + 'gender', + ]; + + public function getGenderAttribute() + { + return $this->gender_id == 1 ? 'Laki-laki' : 'Perempuan'; + } + public function setFather(User $father) { if ($father->gender_id === 1) { diff --git a/composer.json b/composer.json index 3a49526..d23b2d6 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "require": { "php": ">=5.6.4", "laravel/framework": "5.4.*", - "laravel/tinker": "~1.0" + "laravel/tinker": "~1.0", + "luthfi/formfield": "^0.1.6" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index bc03f0b..0ea33cb 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": "94fcb27cd278a47e83dea7f310cfe69e", + "content-hash": "27fbe283b6f1d75a727cf51cee225967", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -428,6 +428,60 @@ "time": "2017-06-01T16:31:26+00:00" }, { + "name": "laravelcollective/html", + "version": "v5.4.8", + "source": { + "type": "git", + "url": "https://github.com/LaravelCollective/html.git", + "reference": "9b8f51e7a2368911c896f5d42757886bae0717b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/LaravelCollective/html/zipball/9b8f51e7a2368911c896f5d42757886bae0717b5", + "reference": "9b8f51e7a2368911c896f5d42757886bae0717b5", + "shasum": "" + }, + "require": { + "illuminate/http": "5.4.*", + "illuminate/routing": "5.4.*", + "illuminate/session": "5.4.*", + "illuminate/support": "5.4.*", + "illuminate/view": "5.4.*", + "php": ">=5.6.4" + }, + "require-dev": { + "illuminate/database": "5.4.*", + "mockery/mockery": "~0.9.4", + "phpunit/phpunit": "~5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Collective\\Html\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + }, + { + "name": "Adam Engebretson", + "email": "adam@laravelcollective.com" + } + ], + "description": "HTML and Form Builders for the Laravel Framework", + "homepage": "http://laravelcollective.com", + "time": "2017-05-22T06:35:07+00:00" + }, + { "name": "league/flysystem", "version": "1.0.40", "source": { @@ -511,6 +565,46 @@ "time": "2017-04-28T10:15:08+00:00" }, { + "name": "luthfi/formfield", + "version": "0.1.6", + "source": { + "type": "git", + "url": "https://github.com/nafiesl/FormField.git", + "reference": "dfbbae8f86f6d332a9f548ad6cebc77e2c66810f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nafiesl/FormField/zipball/dfbbae8f86f6d332a9f548ad6cebc77e2c66810f", + "reference": "dfbbae8f86f6d332a9f548ad6cebc77e2c66810f", + "shasum": "" + }, + "require": { + "illuminate/support": "5.3.* || 5.4.*", + "laravelcollective/html": "5.3.* || 5.4.*" + }, + "require-dev": { + "orchestra/testbench": "~3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Luthfi\\FormField\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nafies Luthfi", + "email": "nafiesl@gmail.com" + } + ], + "description": "Form Field helper class for Laravel 5.3 with Twitter Bootstrap", + "time": "2017-06-16T03:22:15+00:00" + }, + { "name": "monolog/monolog", "version": "1.23.0", "source": { diff --git a/config/app.php b/config/app.php index 135e977..91a5552 100644 --- a/config/app.php +++ b/config/app.php @@ -64,7 +64,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => 'Asia/Makassar', /* |-------------------------------------------------------------------------- @@ -77,7 +77,7 @@ return [ | */ - 'locale' => 'en', + 'locale' => 'id', /* |-------------------------------------------------------------------------- @@ -120,7 +120,7 @@ return [ | */ - 'log' => env('APP_LOG', 'single'), + 'log' => env('APP_LOG', 'daily'), 'log_level' => env('APP_LOG_LEVEL', 'debug'), @@ -167,6 +167,7 @@ return [ * Package Service Providers... */ Laravel\Tinker\TinkerServiceProvider::class, + Luthfi\FormField\FormFieldServiceProvider::class, /* * Application Service Providers... @@ -226,6 +227,10 @@ return [ 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'FormField' => Luthfi\FormField\FormFieldFacade::class, + 'Form' => Collective\Html\FormFacade::class, + 'Html' => Collective\Html\HtmlFacade::class, + ], ]; diff --git a/config/database.php b/config/database.php index cab5d06..5ed066d 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/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php new file mode 100644 index 0000000..757d821 --- /dev/null +++ b/resources/views/auth/login.blade.php @@ -0,0 +1,68 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Login
+
+
+ {{ csrf_field() }} + +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+
+
+ +
+
+
+ +
+
+ + + + Forgot Your Password? + +
+
+
+
+
+
+
+
+@endsection diff --git a/resources/views/auth/passwords/email.blade.php b/resources/views/auth/passwords/email.blade.php new file mode 100644 index 0000000..e566cfb --- /dev/null +++ b/resources/views/auth/passwords/email.blade.php @@ -0,0 +1,46 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Reset Password
+
+ @if (session('status')) +
+ {{ session('status') }} +
+ @endif + +
+ {{ csrf_field() }} + +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+
+ +
+
+
+
+
+
+
+
+@endsection diff --git a/resources/views/auth/passwords/reset.blade.php b/resources/views/auth/passwords/reset.blade.php new file mode 100644 index 0000000..6ed9298 --- /dev/null +++ b/resources/views/auth/passwords/reset.blade.php @@ -0,0 +1,76 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Reset Password
+ +
+ @if (session('status')) +
+ {{ session('status') }} +
+ @endif + +
+ {{ csrf_field() }} + + + +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+ +
+ + + @if ($errors->has('password_confirmation')) + + {{ $errors->first('password_confirmation') }} + + @endif +
+
+ +
+
+ +
+
+
+
+
+
+
+
+@endsection diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php new file mode 100644 index 0000000..4206301 --- /dev/null +++ b/resources/views/auth/register.blade.php @@ -0,0 +1,98 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Register
+
+
+ {{ csrf_field() }} + +
+ + +
+ + + @if ($errors->has('nickname')) + + {{ $errors->first('nickname') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('name')) + + {{ $errors->first('name') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('email')) + + {{ $errors->first('email') }} + + @endif +
+
+ +
+ + +
+ {!! FormField::radios('gender_id', [1 => 'Laki-laki', 2 => 'Perempuan'], ['label' => false]) !!} +
+
+ +
+ + +
+ + + @if ($errors->has('password')) + + {{ $errors->first('password') }} + + @endif +
+
+ +
+ + +
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+@endsection diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..602d36f --- /dev/null +++ b/resources/views/home.blade.php @@ -0,0 +1,96 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Profile
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Nama Panggilan{{ $currentUser->nickname }}
Nama{{ $currentUser->name }}
Jenis Kelamin{{ $currentUser->gender }}
Ayah + @if ($currentUser->father_id) + {{ $currentUser->father->name }} + @else + {{ Form::open() }} +
+ {{ Form::text('set_father', null, ['class' => 'form-control input-sm']) }} + + {{ Form::submit('update', ['class' => 'btn btn-info btn-sm']) }} + +
+ {{ Form::close() }} + @endif +
Ibu + @if ($currentUser->mother_id) + {{ $currentUser->mother->name }} + @else + {{ Form::open() }} +
+ {{ Form::text('set_mother', null, ['class' => 'form-control input-sm']) }} + + {{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_father_button']) }} + +
+ {{ Form::close() }} + @endif +
Anak-Anak
+
    + @foreach($currentUser->childs as $child) +
  • + {{ $child->nickname }} ({{ $child->gender }}) +
  • + @endforeach +
  • + {{ Form::open() }} +
    +
    + {!! FormField::text('add_child_name', ['label' => 'Nama Anak']) !!} +
    +
    + {!! FormField::radios('add_child_gender_id', [1 => 'Laki-laki', 2 => 'Perempuan'], ['label' => 'Jenis Kelamin Anak']) !!} +
    +
    +
    + {{ Form::submit('Tambah Anak', ['class' => 'btn btn-success btn-sm']) }} +
    +
    + {{ Form::close() }} +
  • +
+
+
+
+
+
+
+@endsection diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php new file mode 100644 index 0000000..d4745b4 --- /dev/null +++ b/resources/views/layouts/app.blade.php @@ -0,0 +1,80 @@ + + + + + + + + + + + {{ config('app.name', 'Laravel') }} + + + + + +
+ + + @yield('content') +
+ + + + + diff --git a/routes/web.php b/routes/web.php index 810aa34..f168fe2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,3 +14,8 @@ Route::get('/', function () { return view('welcome'); }); + +Auth::routes(); + +Route::get('/home', 'HomeController@index')->name('home'); +Route::get('/profile', 'HomeController@index')->name('profile'); 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/Feature/ManageUserFamiliesTest.php b/tests/Feature/ManageUserFamiliesTest.php new file mode 100644 index 0000000..402aeb1 --- /dev/null +++ b/tests/Feature/ManageUserFamiliesTest.php @@ -0,0 +1,25 @@ +loginAsUser(); + $this->visit(route('profile')); + $this->seePageIs(route('profile')); + + $this->see($user->nickname); + $this->seeElement('input', ['name' => 'set_father']); + $this->seeElement('input', ['name' => 'set_mother']); + $this->seeElement('input', ['name' => 'add_child_name']); + $this->seeElement('input', ['name' => 'add_child_gender_id']); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index b55950f..f2ee8d3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,7 @@ namespace Tests; +use App\User; use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase