add login feature
This commit is contained in:
parent
c4dfc3dc73
commit
c28c77aad4
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IndexAdminController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('admin.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
public function postlogin(Request $request)
|
||||
{
|
||||
if(Auth::attempt($request->only('email','password'))){
|
||||
return redirect('admin/index');
|
||||
}
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
|
@ -65,5 +65,6 @@ class Kernel extends HttpKernel
|
|||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'ceklevel' => \App\Http\Middleware\CekLevel::class,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CekLevel
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$levels): Response
|
||||
{
|
||||
if(in_array($request->user()->level,$levels)){
|
||||
return $next($request);
|
||||
}
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ public function up(): void
|
|||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('level');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
|
|
|
@ -18,5 +18,6 @@ public function run(): void
|
|||
// 'name' => 'Test User',
|
||||
// 'email' => 'test@example.com',
|
||||
// ]);
|
||||
$this->call(UserSeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::truncate();
|
||||
User::create([
|
||||
'name' => 'Admin SIPETAN',
|
||||
'level' => 'admin',
|
||||
'email' => 'sipetan@admin.com',
|
||||
'password' => bcrypt('12345678'),
|
||||
'remember_token' => Str::random(60),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
@section('body')
|
||||
|
||||
<section class="section">
|
||||
<div class="container mt-5">
|
||||
<div class="container mt-4">
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4">
|
||||
<div class="login-brand">
|
||||
|
@ -11,10 +11,11 @@
|
|||
</div>
|
||||
|
||||
<div class="card card-primary">
|
||||
<div class="card-header"><h4>Login</h4></div>
|
||||
<div class="card-header text-center"><h4>Login</h4></div>
|
||||
|
||||
<div class="card-body">
|
||||
<form method="POST" action="#" class="needs-validation" novalidate="">
|
||||
<form method="POST" action="/postlogin" class="needs-validation" novalidate="">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input id="email" type="email" class="form-control" name="email" tabindex="1" required autofocus>
|
||||
|
@ -52,7 +53,7 @@
|
|||
</div>
|
||||
</form>
|
||||
<div class="mt-5 text-muted text-center">
|
||||
Don't have an account? <a href="/auth/register">Create One</a>
|
||||
Tidak punya akun? <a href="/auth/register">Daftar</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@
|
|||
<i class="fas fa-cog"></i> Settings
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="#" class="dropdown-item has-icon text-danger">
|
||||
<a href="/logout" class="dropdown-item has-icon text-danger">
|
||||
<i class="fas fa-sign-out-alt"></i> Logout
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
</li>
|
||||
<li class="menu-header">DATA</li>
|
||||
<li><a class="nav-link" href="/admin/subdistrict"><i class="fas fa-map-marker-alt"></i> <span>Data Kecamatan</span></a></li>
|
||||
@if (auth()->user()->level == 'user')
|
||||
<li class="dropdown">
|
||||
<a href="#" class="nav-link has-dropdown" data-toggle="dropdown"><i class="fas fa-columns"></i> <span>Layout</span></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
@ -25,6 +26,7 @@
|
|||
<li><a class="nav-link" href="layout-top-navigation.html">Top Navigation</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@endif
|
||||
<li><a class="nav-link" href="blank.html"><i class="far fa-square"></i> <span>Blank Page</span></a></li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="nav-link has-dropdown"><i class="fas fa-th"></i> <span>Bootstrap</span></a>
|
||||
|
@ -51,6 +53,7 @@
|
|||
<li><a class="nav-link" href="bootstrap-typography.html">Typography</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@if (auth()->user()->level == 'user')
|
||||
<li class="menu-header">Stisla</li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="nav-link has-dropdown"><i class="fas fa-th-large"></i> <span>Components</span></a>
|
||||
|
@ -98,6 +101,7 @@
|
|||
<li><a class="nav-link" href="modules-weather-icon.html">Weather Icon</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@endif
|
||||
<li class="menu-header">Pages</li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="nav-link has-dropdown"><i class="far fa-user"></i> <span>Auth</span></a>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -17,12 +18,13 @@
|
|||
return view('welcome');
|
||||
});
|
||||
|
||||
Route::get('/admin/index', function () {
|
||||
return view('admin/index');
|
||||
});
|
||||
|
||||
Route::get('/auth/login', function () { return view('auth/login'); });
|
||||
Route::get('/auth/register', function () { return view('auth/register'); });
|
||||
Route::get('/auth/forgot-password', function () { return view('auth/forgot-password'); });
|
||||
|
||||
Route::get('login',[App\Http\Controllers\LoginController::class, 'index'])->name('login');
|
||||
Route::post('/postlogin',[App\Http\Controllers\LoginController::class, 'postlogin'])->name('postlogin');
|
||||
Route::get('/logout',[App\Http\Controllers\LoginController::class, 'logout'])->name('logout');
|
||||
Route::get('/admin/subdistrict', function () { return view('admin/subdistrict'); });
|
||||
|
||||
|
||||
Route::middleware(['auth','ceklevel:admin,user'])->group(function () {
|
||||
Route::get('/admin/index',[App\Http\Controllers\IndexAdminController::class, 'index'])->name('/index/admin');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue