diff --git a/ppl2/app/Http/Controllers/AutentikasiController.php b/ppl2/app/Http/Controllers/AutentikasiController.php new file mode 100644 index 0000000000000000000000000000000000000000..8f20b56fedb09b4776b56a80c24e5c0d38efa739 --- /dev/null +++ b/ppl2/app/Http/Controllers/AutentikasiController.php @@ -0,0 +1,73 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; + +use App\Http\Requests; + +use View; + +use Validator; + +use Input; + +use Redirect; + +use Auth; + + +class AutentikasiController extends Controller +{ + // + + public function showLogin() + { + // show the form + Auth::logout(); + return View::make('pages.loginPage'); + } + + public function doLogin() + { + // process the form + // validate the info, create rules for the inputs + $rules = array( + 'email' => 'required|email', // make sure the email is an actual email + 'password' => 'required|alphaNum|min:3' // password can only be alphanumeric and has to be greater than 3 characters + ); + + // run the validation rules on the inputs from the form + $validator = Validator::make(Input::all(), $rules); + + // if the validator fails, redirect back to the form + if ($validator->fails()) { + return Redirect::to('login') + ->withErrors($validator) // send back all errors to the login form + ->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form + } else { + + // create our user data for the authentication + $userdata = array( + 'email' => Input::get('email'), + 'password' => Input::get('password') + ); + + // attempt to do the login + if (Auth::attempt($userdata)) { + // validation successful! + // redirect them to the secure section or whatever + // return Redirect::to('secure'); + // for now we'll just echo success (even though echoing in a controller is bad) + echo 'SUCCESS!'; + return Redirect::to('daftarinstitusi'); + + } else { + // validation not successful, send back to form + return Redirect::to('/'); + + } + + } + } +} diff --git a/ppl2/app/Http/routes.php b/ppl2/app/Http/routes.php index ffecfea4d5990f0ff9ee0503c655145f7efc9de0..1b5ffe099f15c5685d9c63a1d48415c686a2cdc9 100644 --- a/ppl2/app/Http/routes.php +++ b/ppl2/app/Http/routes.php @@ -11,9 +11,16 @@ | */ -Route::get('/', function () { - return view('pages.loginPage'); -}); + + +// route to show the login form +Route::get('/', array('uses' => 'AutentikasiController@showLogin')); + +Route::get('logout', array('uses' => 'AutentikasiController@showLogin')); + +// route to process the form +Route::post('login', array('uses' => 'AutentikasiController@doLogin')); + Route::get('pendidikan-formal/new', function() { return view('pages.formPendidikan'); diff --git a/ppl2/config/app.php b/ppl2/config/app.php index cee856adea5729d5d39f50d30994bc307265ba7e..fce72eac5d7d5131632b7d8469bc6421a916a908 100644 --- a/ppl2/config/app.php +++ b/ppl2/config/app.php @@ -201,6 +201,7 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'Input' => Illuminate\Support\Facades\Input::class ], diff --git a/ppl2/database/seeds/DatabaseSeeder.php b/ppl2/database/seeds/DatabaseSeeder.php index e119db624aa8f894d74ef57283c4947e734015b0..5b6a5d3afb157dffe450ccd28acffecfbb44ee25 100644 --- a/ppl2/database/seeds/DatabaseSeeder.php +++ b/ppl2/database/seeds/DatabaseSeeder.php @@ -12,5 +12,8 @@ class DatabaseSeeder extends Seeder public function run() { // $this->call(UsersTableSeeder::class); + Eloquent::unguard(); + + $this->call(UserTableSeeder::class); } } diff --git a/ppl2/database/seeds/UserTableSeeder.php b/ppl2/database/seeds/UserTableSeeder.php new file mode 100644 index 0000000000000000000000000000000000000000..bac413f1012cb1e6c7eb6f54d2c72ea04d6efab9 --- /dev/null +++ b/ppl2/database/seeds/UserTableSeeder.php @@ -0,0 +1,20 @@ +<?php + +use Illuminate\Database\Seeder; +use Illuminate\Database\Eloquent\Model; + +use App\User; +class UserTableSeeder extends Seeder +{ + +public function run() +{ + DB::table('users')->delete(); + User::create(array( + 'name' => 'Yoga Adrian', + 'email' => 'admin@a.a', + 'password' => Hash::make('admin'), + )); +} + +} \ No newline at end of file diff --git a/ppl2/resources/views/app_template.blade.php b/ppl2/resources/views/app_template.blade.php index e41b9ffa1dad3485a51a5fa607fd023d617f4860..295d344fb53d00640dfb84f1831fa3fd02c156e1 100644 --- a/ppl2/resources/views/app_template.blade.php +++ b/ppl2/resources/views/app_template.blade.php @@ -60,28 +60,56 @@ <ul class="dropdown-menu" role="menu"> <li> + + @if (Auth::check()) <a href="{{URL::to('pendidikan-formal')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <span>Pendidikan Formal</span> </a> </li> <li> + @if (Auth::check()) <a href="{{URL::to('pendidikan-informal')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif + <span>Pendidikan Informal</span> </a> </li> <li> - <a href="{{URL::to('daftarinstitusi')}}"> + @if (Auth::check()) + <a href="{{URL::to('daftarinstitusi')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif + <span>Institusi</span> </a> </li> <li> - <a href="{{URL::to('penjadwalan')}}"> + @if (Auth::check()) + <a href="{{URL::to('penjadwalan')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <span>Penjadwalan</span> </a> </li> <li> - <a href="{{URL::to('statistik')}}"> + @if (Auth::check()) + <a href="{{URL::to('statistik')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <span>Statistik</span> </a> </li> @@ -147,7 +175,7 @@ </li> <li class="divider"></li> <li> - <a>Logout</a> + <a href='logout'>Logout</a> </li> </ul> <!-- / dropdown --> @@ -232,31 +260,57 @@ <span>Components</span> </li> <li> - <a href="{{URL::to('pendidikan-formal')}}"> + @if (Auth::check()) + <a href="{{URL::to('pendidikan-formal')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif + <i class="icon-bdg_table"></i> <span class="font-bold">Formal</span> </a> </li> <li> - <a href="{{URL::to('pendidikan-informal')}}"> + @if (Auth::check()) + <a href="{{URL::to('pendidikan-informal')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <i class="icon-bdg_table"></i> <span class="font-bold">Informal</span> </a> </li> <li> - <a href="{{URL::to('daftarinstitusi')}}"> + @if (Auth::check()) + <a href="{{URL::to('daftarinstitusi')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <i class="icon-bdg_table"></i> <span class="font-bold">Institusi</span> </a> </li> <li> - <a href="{{URL::to('penjadwalan')}}"> + @if (Auth::check()) + <a href="{{URL::to('penjadwalan')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <i class="icon-bdg_table"></i> <span class="font-bold">Penjadwalan</span> </a> </li> <li> - <a href="{{URL::to('statistik')}}"> + @if (Auth::check()) + <a href="{{URL::to('statistik')}}"> + @else + + <a href="{{URL::to('/')}}"> + @endif <i class="icon-bdg_table"></i> <span class="font-bold">Statistik</span> </a> diff --git a/ppl2/resources/views/pages/loginPage.blade.php b/ppl2/resources/views/pages/loginPage.blade.php index 32241f054007acccfc6041e5c36afd700f4a952a..d31dec2dbfd9585af332b8ebbfd77c4037735df8 100644 --- a/ppl2/resources/views/pages/loginPage.blade.php +++ b/ppl2/resources/views/pages/loginPage.blade.php @@ -20,7 +20,7 @@ <div class="panel panel-default"> <div class="panel-heading font-bold">Login</div> <div class="panel-body"> - <form class="bs-example form-horizontal" method = "GET" action = "{{URL::to('daftarinstitusi')}}"> + <form class="bs-example form-horizontal" method = "POST" action = "{{URL::to('login')}}"> <div class="form-group"> <label class="col-lg-2 control-label">e-mail</label> <div class="col-lg-8">