diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 18a0d08..6d476bd 100755 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -1,40 +1,125 @@ middleware('guest')->except('logout'); + } -} + + + + public function login(Request $request) + + { + + $input = $request->all(); + + + + $this->validate($request, [ + + 'email' => 'required|email', + + 'password' => 'required', + + ]); + + + + if(auth()->attempt(array('email' => $input['email'], 'password' => $input['password']))) + + { + + if (auth()->user()->is_admin == 1) { + + return redirect()->route('admin.home'); + + }else{ + + return redirect()->route('home'); + + } + + }else{ + + return redirect()->route('login') + + ->with('error','Email-Address And Password Are Wrong.'); + + } + + + + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..dd91390 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,36 @@ +middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Contracts\Support\Renderable + */ + public function index() + { + return view('home'); + } + + public function adminHome() + + { + + return view('adminHome'); + + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index deb65e8..4dc8223 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -51,16 +51,27 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ + 'auth' => \App\Http\Middleware\Authenticate::class, + 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, + 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + + 'is_admin' => \App\Http\Middleware\IsAdmin::class, + ]; /** diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php new file mode 100644 index 0000000..769867d --- /dev/null +++ b/app/Http/Middleware/IsAdmin.php @@ -0,0 +1,47 @@ +user()->is_admin == 1){ + + return $next($request); + + } + + + + return redirect(‘home’)->with(‘error’,"You don't have admin access."); + + } + +} \ No newline at end of file diff --git a/app/Http/User.php b/app/Http/User.php new file mode 100644 index 0000000..a06bc9b --- /dev/null +++ b/app/Http/User.php @@ -0,0 +1,77 @@ + 'datetime', + + ]; + +} \ No newline at end of file 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 a91e1d3..8b5d1d8 100755 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,36 +1,73 @@ bigIncrements('id'); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - } /** - * Reverse the migrations. + + * Run the migrations. + * + * @return void + */ - public function down() + + public function up() + { - Schema::dropIfExists('users'); + + Schema::create('users', function (Blueprint $table) { + + $table->bigIncrements('id'); + + $table->string('name'); + + $table->string('email'); + + // $table->timestamp('email_verified_at')->nullable(); + + $table->boolean('is_admin')->nullable(); + + $table->string('password'); + + $table->rememberToken(); + + $table->timestamps(); + + }); + } -} + + + + /** + + * Reverse the migrations. + + * + + * @return void + + */ + + public function down() + + { + + Schema::dropIfExists('users'); + + } + +} \ No newline at end of file diff --git a/database/seeds/CreateUsersSeeder.php b/database/seeds/CreateUsersSeeder.php new file mode 100644 index 0000000..6aa51c0 --- /dev/null +++ b/database/seeds/CreateUsersSeeder.php @@ -0,0 +1,67 @@ +'Admin', + + 'email'=>'admin@admin.fr', + + 'is_admin'=>'1', + + 'password'=> bcrypt('123456'), + + ], + + [ + + 'name'=>'User', + + 'email'=>'user@itsolutionstuff.com', + + 'is_admin'=>'0', + + 'password'=> bcrypt('123456'), + + ], + + ]; + + + + foreach ($user as $key => $value) { + + User::create($value); + + } + + } + +} \ No newline at end of file diff --git a/resources/views/adminHome.blade.php b/resources/views/adminHome.blade.php new file mode 100644 index 0000000..7dc4af2 --- /dev/null +++ b/resources/views/adminHome.blade.php @@ -0,0 +1,31 @@ +@extends('layouts.app') + + + +@section('content') + +
+ +
+ +
+ +
+ +
Dashboard
+ +
+ + You are Admin. + +
+ +
+ +
+ +
+ +
+ +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 0c67001..e8ca31f 100755 --- a/routes/web.php +++ b/routes/web.php @@ -21,3 +21,4 @@ Route::post('contact-us', ['as' => 'contactus.store', 'uses' => 'ContactUSContro Auth::routes(); Route::get('/home', 'HomeController@index')->name('home'); +Route::get('admin/home', 'HomeController@adminHome')->name('admin.home')->middleware('is_admin'); \ No newline at end of file