Commit 76bc21ee by Siti Aisah

registrasi dan reset password mahasiswa

parent afde90e5
......@@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use App\Models\User;
use Illuminate\Console\View\Components\Alert;
use Illuminate\Support\Facades\Redis;
class LoginController extends Controller
......@@ -48,10 +49,10 @@ public function login(Request $request)
return $this->redirectToDashboard();
}
// throw ValidationException::withMessages([
// 'email' => [trans('auth.failed')],
// ]);
return redirect()->route('login')->with('error', 'Email atau password Anda salah.');
// Jika gagal, ubah pesan error
return redirect()->back()->withErrors([
'email' => 'Email atau password Anda salah!',
]);
}
public function logout(Request $request)
......@@ -68,7 +69,7 @@ private function redirectToDashboard()
//Mapping roles ke routes
$roleRoutes = [
'admin' => 'admin.dashboard',
'admin' => 'mahasiswa.dashboard',
'laman' => 'mahasiswa.dashboard',
];
......
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use App\Models\User;
use Illuminate\Console\View\Components\Alert;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Hash;
use Uuid;
class RegistrasiController extends Controller
{
// public function __construct()
// {
// $this->middleware('guest')->except('logout');
// }
public function index()
{
return view('registrasi');
}
public function register(Request $request)
{
// Validasi input pengguna
$request->validate([
'name' => 'required|string',
'email' => 'required|string|email|unique:users,email',
'password' => 'required|string|min:8|confirmed',
], [
'name.required' => 'Nama harus diisi',
'email.required' => 'Email harus diisi.',
'email.email' => 'Format email tidak valid.',
'email.unique' => 'Email sudah digunakan.',
'password.required' => 'Password harus diisi.',
'password.min' => 'Password harus minimal 8 karakter.',
'password.confirmed' => 'Konfirmasi password tidak cocok.',
]);
// Simpan user baru ke database
$uuid = Uuid::generate();
User::create([
'id' => $uuid,
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
// 'password' => bcrypt($request->password),
'role' => 'laman',
'is_active' => 1
]);
return redirect()->route('login')->with('success', 'Registrasi berhasil! Silakan login');
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use App\Models\User;
use Illuminate\Console\View\Components\Alert;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Hash;
use Uuid;
class ResetPasswordController extends Controller
{
// public function __construct()
// {
// $this->middleware('guest')->except('logout');
// }
public function index()
{
return view('reset-password');
}
public function cek(Request $request)
{
// Validasi input email
$request->validate([
'email' => 'required|email|exists:users,email',
], [
'email.required' => 'Email harus diisi.',
'email.email' => 'Format email tidak valid.',
'email.exists' => 'Email tidak terdaftar.', // Menghindari pengecekan manual di database
]);
// Ambil user dari database
$user = User::where('email', $request->email)->first();
// Simpan data ke session
session()->put([
'reset_email' => $user->email,
'reset_name' => $user->name
]);
return redirect()->route('reset-password')->with('success', 'Email ditemukan, silakan reset password.');
}
public function reset(Request $request)
{
// Pastikan email tersedia di session
if (!session()->has('reset_email')) {
return redirect()->route('reset-password')->with('error', 'Silakan cek email terlebih dahulu.');
}
$email = session('reset_email');
// Validasi password baru
$request->validate([
'password' => 'required|string|min:8|confirmed',
], [
'password.required' => 'Password harus diisi.',
'password.min' => 'Password harus minimal 8 karakter.',
'password.confirmed' => 'Konfirmasi password tidak cocok.',
]);
// Update password user
User::where('email', $email)->update([
'password' => Hash::make($request->password),
]);
// Hapus session setelah reset password berhasil
session()->forget(['reset_email', 'reset_name']);
return redirect()->route('login')->with('success', 'Reset Password berhasil! Silakan login.');
}
}
\ No newline at end of file
......@@ -27,8 +27,8 @@
</a>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdown-user"><div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{route('admin.logout')}}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();"><i class="me-50" data-feather="power"></i> Logout</a>
<form id="logout-form" action="{{route('admin.logout')}}" method="POST" style="display: none;">
<a class="dropdown-item" href="{{route('logout')}}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();"><i class="me-50" data-feather="power"></i> Logout</a>
<form id="logout-form" action="{{route('logout')}}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</div>
......
......@@ -66,10 +66,13 @@
{{-- <img src="{{ url('theme/images/logo/logoumc.png') }}" width="40%"> --}}
<h2 class="brand-text text-primary ms-1">Golden Ticket UNESA</h2>
</a>
@if(Session::has('message'))
<div class="alert alert-success" style="float:none">
{{ Session::get('message') }}
{{Session::forget('message')}}
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@elseif (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
<form class="text-left" method="POST" action="{{ route('login') }}">
......@@ -78,10 +81,10 @@
<div class="col-md-12">
@if ($errors->has('email'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>{{ $errors->first('email') }}</strong>
</div>
@endif
<label class="col-md-3">Email</label>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required placeholder="Masukkan Email">
</div>
</div><br>
......@@ -90,17 +93,20 @@
<div class="col-md-12">
@if ($errors->has('password'))
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>{{ $errors->first('password') }}</strong>
</div>
@endif
<label class="col-md-3">Password</label>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" value="{{ old('password') }}" required placeholder="Masukkan Password">
</div>
</div><br>
<button type="submit" class="btn btn-primary w-100" tabindex="4">Login</button>
<div class="cold-md-6 mt-1">
Belum punya akun? <a href="{{ route('register') }}">Daftar di sini</a>
Belum punya akun? <a href="{{ route('registrasi') }}">Daftar di sini</a>
</div>
<div class="cold-md-6 mt-1">
Lupa password? <a href="{{ route('reset-password') }}">Reset password</a>
</div>
</form>
......
<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr">
<!-- BEGIN: Head-->
<head>
<link rel="apple-touch-icon" href="{{ url('theme/images/ico/apple-icon-120.png') }}">
<link rel="shortcut icon" type="image/x-icon" href="{{ url('theme/images/ico/favicon.ico') }}">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400;1,500;1,600" rel="stylesheet">
<meta http-equiv="Content-Type" charset="utf-8">
<meta name="universitas-negeri-surabaya" content="custom" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Golden Ticket UNESA">
<meta name="author" content="PPTI Unesa Surabaya">
<meta name="keywords" content="sistem, informasi, unesa, seleksi, penerimaan, mahasiswa, maba">
<meta name="language" content="id">
<meta name="geo.region" content="ID" />
<meta name="geo.position" content="-7.300818;112.672689">
<meta name="geo.placename" content="Surabaya">
<meta name="geo.region" content="Indonesia">
<title>Registrasi Akun</title>
<!-- BEGIN: Vendor CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/vendors/css/vendors.min.css') }}">
<!-- END: Vendor CSS-->
<!-- BEGIN: Theme CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/bootstrap.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/bootstrap-extended.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/colors.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/components.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/dark-layout.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/bordered-layout.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/semi-dark-layout.css') }}">
<!-- BEGIN: Page CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/core/menu/menu-types/horizontal-menu.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/plugins/forms/form-validation.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/pages/authentication.css') }}">
<!-- END: Page CSS-->
<!-- BEGIN: Custom CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/assets/css/style.css') }}">
<!-- END: Custom CSS-->
</head>
<!-- END: Head-->
<!-- BEGIN: Body-->
<body class="horizontal-layout horizontal-menu blank-page navbar-floating footer-static " data-open="hover" data-menu="horizontal-menu" data-col="blank-page">
<!-- BEGIN: Content-->
<div class="app-content content ">
<div class="content-overlay"></div>
<div class="header-navbar-shadow"></div>
<div class="content-wrapper">
<div class="content-header row">
</div>
<div class="content-body">
<div class="auth-wrapper auth-basic px-2">
<div class="auth-inner my-2">
<!-- Login basic -->
<div class="card mb-0">
<div class="card-body">
<a href="index.html" class="brand-logo">
{{-- <img src="{{ url('theme/images/logo/logoumc.png') }}" width="40%"> --}}
<h2 class="brand-text text-primary ms-1">Registrasi Akun</h2>
</a>
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
<form class="text-left" method="POST" action="{{ route('registrasi') }}">
@csrf
<div class="form-group" >
<div class="col-md-12">
@if ($errors->has('name'))
<div class="alert alert-danger" role="alert">
<strong>{{ $errors->first('name') }}</strong>
</div>
@endif
<label class="col-md-3">Nama</label>
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required placeholder="Masukkan Nama">
</div>
</div><br>
<div class="form-group" >
<div class="col-md-12">
@if ($errors->has('email'))
<div class="alert alert-danger" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</div>
@endif
<label class="col-md-3">Email</label>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required placeholder="Masukkan Email">
</div>
</div><br>
<div class="form-group">
<div class="col-md-12">
@if ($errors->has('password'))
<div class="alert alert-danger" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</div>
@endif
<label class="col-md-3">Password</label>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required placeholder="Masukkan Password">
</div>
</div><br>
<div class="form-group">
<div class="col-md-12">
@if ($errors->has('password_confirmation'))
<div class="alert alert-danger" role="alert">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</div>
@endif
<label class="col-md-6">Konfirmasi Password</label>
<input id="password_confirmation" type="password" class="form-control{{ $errors->has('password_confirmation') ? ' is-invalid' : '' }}" name="password_confirmation" required placeholder="Ulangi Password">
</div>
</div><br>
<button type="submit" class="btn btn-primary w-100" tabindex="4">Daftar</button>
<div class="cold-md-6 mt-1">
Sudah punya akun? <a href="{{ route('login') }}">Login di sini</a>
</div>
</form>
</br>
</div>
</div>
<!-- /Login basic -->
</div>
</div>
</div>
</div>
</div>
<!-- END: Content-->
<!-- BEGIN: Vendor JS-->
<script src="{{ url('theme/vendors/js/vendors.min.js') }}"></script>
<!-- BEGIN Vendor JS-->
<!-- BEGIN: Page Vendor JS-->
<script src="{{ url('theme/vendors/js/ui/jquery.sticky.js') }}"></script>
<script src="{{ url('theme/vendors/js/forms/validation/jquery.validate.min.js') }}"></script>
<!-- END: Page Vendor JS-->
<!-- BEGIN: Theme JS-->
<script src="{{ url('theme/js/core/app-menu.js') }}"></script>
<script src="{{ url('theme/js/core/app.js') }}"></script>
<!-- END: Theme JS-->
<!-- BEGIN: Page JS-->
<script src="{{ url('theme/js/scripts/pages/auth-login.js') }}"></script>
<!-- END: Page JS-->
<script>
$(window).on('load', function() {
if (feather) {
feather.replace({
width: 14,
height: 14
});
}
})
</script>
</body>
<!-- END: Body-->
</html>
<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr">
<!-- BEGIN: Head-->
<head>
<link rel="apple-touch-icon" href="{{ url('theme/images/ico/apple-icon-120.png') }}">
<link rel="shortcut icon" type="image/x-icon" href="{{ url('theme/images/ico/favicon.ico') }}">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;1,400;1,500;1,600" rel="stylesheet">
<meta http-equiv="Content-Type" charset="utf-8">
<meta name="universitas-negeri-surabaya" content="custom" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Golden Ticket UNESA">
<meta name="author" content="PPTI Unesa Surabaya">
<meta name="keywords" content="sistem, informasi, unesa, seleksi, penerimaan, mahasiswa, maba">
<meta name="language" content="id">
<meta name="geo.region" content="ID" />
<meta name="geo.position" content="-7.300818;112.672689">
<meta name="geo.placename" content="Surabaya">
<meta name="geo.region" content="Indonesia">
<title>Reset Password</title>
<!-- BEGIN: Vendor CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/vendors/css/vendors.min.css') }}">
<!-- END: Vendor CSS-->
<!-- BEGIN: Theme CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/bootstrap.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/bootstrap-extended.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/colors.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/components.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/dark-layout.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/bordered-layout.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/themes/semi-dark-layout.css') }}">
<!-- BEGIN: Page CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/core/menu/menu-types/horizontal-menu.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/plugins/forms/form-validation.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url('theme/css/pages/authentication.css') }}">
<!-- END: Page CSS-->
<!-- BEGIN: Custom CSS-->
<link rel="stylesheet" type="text/css" href="{{ url('theme/assets/css/style.css') }}">
<!-- END: Custom CSS-->
</head>
<!-- END: Head-->
<!-- BEGIN: Body-->
<body class="horizontal-layout horizontal-menu blank-page navbar-floating footer-static " data-open="hover" data-menu="horizontal-menu" data-col="blank-page">
<!-- BEGIN: Content-->
<div class="app-content content ">
<div class="content-overlay"></div>
<div class="header-navbar-shadow"></div>
<div class="content-wrapper">
<div class="content-header row">
</div>
<div class="content-body">
<div class="auth-wrapper auth-basic px-2">
<div class="auth-inner my-2">
<!-- Login basic -->
<div class="card mb-0">
<div class="card-body">
<a href="index.html" class="brand-logo">
{{-- <img src="{{ url('theme/images/logo/logoumc.png') }}" width="40%"> --}}
<h2 class="brand-text text-primary ms-1">Reset Password</h2>
</a>
@if(session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
{{-- CEK APAKAH USER SUDAH MEMASUKKAN EMAIL --}}
@if(!session()->has('reset_email'))
{{-- FORM CEK EMAIL --}}
<form class="text-left" method="POST" action="{{ route('cek-email') }}">
@csrf
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" name="email" required placeholder="Masukkan Email">
</div>
<br>
<button type="submit" class="btn btn-primary w-100">Cek Email</button>
</form>
@else
{{-- FORM RESET PASSWORD --}}
<form class="text-left" method="POST" action="{{ route('submit-password') }}">
@csrf
<div class="form-group">
<label>Nama</label>
<input type="text" class="form-control" value="{{ session('reset_name') }}" readonly>
</div>
<br>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" value="{{ session('reset_email') }}" readonly>
</div>
<br>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control @error('password') is-invalid @enderror" name="password" required placeholder="Masukkan Password">
@error('password')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<br>
<div class="form-group">
<label>Konfirmasi Password</label>
<input type="password" class="form-control @error('password_confirmation') is-invalid @enderror" name="password_confirmation" required placeholder="Ulangi Password">
@error('password_confirmation')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
<br>
<button type="submit" class="btn btn-primary w-100">Reset Password</button>
</form>
@endif
</br>
</div>
</div>
<!-- /Login basic -->
</div>
</div>
</div>
</div>
</div>
<!-- END: Content-->
<!-- BEGIN: Vendor JS-->
<script src="{{ url('theme/vendors/js/vendors.min.js') }}"></script>
<!-- BEGIN Vendor JS-->
<!-- BEGIN: Page Vendor JS-->
<script src="{{ url('theme/vendors/js/ui/jquery.sticky.js') }}"></script>
<script src="{{ url('theme/vendors/js/forms/validation/jquery.validate.min.js') }}"></script>
<!-- END: Page Vendor JS-->
<!-- BEGIN: Theme JS-->
<script src="{{ url('theme/js/core/app-menu.js') }}"></script>
<script src="{{ url('theme/js/core/app.js') }}"></script>
<!-- END: Theme JS-->
<!-- BEGIN: Page JS-->
<script src="{{ url('theme/js/scripts/pages/auth-login.js') }}"></script>
<!-- END: Page JS-->
<script>
$(window).on('load', function() {
if (feather) {
feather.replace({
width: 14,
height: 14
});
}
})
</script>
</body>
<!-- END: Body-->
</html>
......@@ -2,6 +2,8 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegistrasiController;
use App\Http\Controllers\Auth\ResetPasswordController;
use App\Http\Controllers\Mahasiswa\BiodataController;
use App\Http\Controllers\Mahasiswa\DashboardController;
......@@ -16,6 +18,12 @@
|
*/
Route::get('registrasi', [RegistrasiController::class, 'index'])->name('registrasi');
Route::post('registrasi', [RegistrasiController::class, 'register']);
Route::get('reset-password', [ResetPasswordController::class, 'index'])->name('reset-password');
Route::post('cek-email', [ResetPasswordController::class, 'cek'])->name('cek-email');
Route::post('reset-password/submit', [ResetPasswordController::class, 'reset'])->name('submit-password');
Route::get('login', [LoginController::class, 'index'])->name('login');
Route::post('login', [LoginController::class, 'login']);
......@@ -28,7 +36,7 @@
return redirect()->route('mahasiswa.dashboard');
}
elseif (auth()->user()->role == 'admin') {
return redirect()->route('admin.dashboard');
return redirect()->route('mahasiswa.dashboard');
} else {
return redirect()->route('login');
}
......@@ -47,4 +55,4 @@
});
});
Route::get('/logout', [LoginController::class, 'logout'])->name('admin.logout');
\ No newline at end of file
// Route::get('/logout', [LoginController::class, 'logout'])->name('admin.logout');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment