This commit is contained in:
parent
c3d3226556
commit
3449d4f954
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Models\Account;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
|
||||
class LupaPasswordController extends Controller
|
||||
{
|
||||
// Menampilkan form input email untuk lupa password
|
||||
public function showInputEmail()
|
||||
{
|
||||
return view('layouts.inputemail');
|
||||
}
|
||||
|
||||
// Menampilkan form OTP
|
||||
public function showOtpForm()
|
||||
{
|
||||
return view('layouts.otp');
|
||||
}
|
||||
|
||||
// Menampilkan form reset password
|
||||
public function showResetPass()
|
||||
{
|
||||
return view('layouts.resetpass');
|
||||
}
|
||||
|
||||
// Mengirimkan OTP ke email pengguna
|
||||
public function sendOtp(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email|exists:accounts,email',
|
||||
]);
|
||||
|
||||
$otp = rand(100000, 999999);
|
||||
|
||||
// Simpan OTP ke database
|
||||
$account = Account::where('email', $request->email)->first();
|
||||
$account->otp_code = $otp;
|
||||
$account->otp_expires_at = Carbon::now()->addMinutes(10);
|
||||
$account->save();
|
||||
|
||||
try {
|
||||
// Kirim OTP ke email
|
||||
Mail::raw("Kode OTP Anda adalah: $otp. OTP ini berlaku selama 10 menit.", function ($message) use ($request) {
|
||||
$message->to($request->email)
|
||||
->subject('Reset Password OTP');
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
return back()->withErrors(['email' => 'Gagal mengirim email. Silakan coba lagi.']);
|
||||
}
|
||||
|
||||
return redirect()->route('otp.form')->with('email', $request->email);
|
||||
}
|
||||
|
||||
public function verifyOtp(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
'otp_code' => 'required',
|
||||
]);
|
||||
|
||||
// Cari akun berdasarkan email dan kode OTP yang valid
|
||||
$account = Account::where('email', $request->email)
|
||||
->where('otp_code', $request->otp_code)
|
||||
->where('otp_expires_at', '>', Carbon::now())
|
||||
->first();
|
||||
|
||||
// Log untuk debugging
|
||||
Log::debug('Verifikasi OTP: ', [
|
||||
'email' => $request->email,
|
||||
'otp_code' => $request->otp_code,
|
||||
'otp_expires_at' => $account ? $account->otp_expires_at : 'null',
|
||||
'found_account' => $account ? 'true' : 'false',
|
||||
]);
|
||||
|
||||
if (!$account) {
|
||||
return back()->withErrors(['otp_code' => 'Kode OTP tidak valid atau sudah kedaluwarsa.']);
|
||||
}
|
||||
|
||||
// OTP valid, simpan email di session dan arahkan ke form reset password
|
||||
session(['email' => $request->email]);
|
||||
|
||||
return redirect()->route('reset.password.form');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Reset password
|
||||
public function resetPassword(Request $request)
|
||||
{
|
||||
Log::debug('Reset Password Request:', $request->all());
|
||||
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|confirmed|min:6',
|
||||
]);
|
||||
|
||||
$account = Account::where('email', $request->email)->firstOrFail();
|
||||
|
||||
$account->password = Hash::make($request->password);
|
||||
$account->otp_code = null;
|
||||
$account->otp_expires_at = null;
|
||||
$account->save();
|
||||
|
||||
return redirect()->route('login')->with('success', 'Password berhasil direset.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
@extends('layouts.auth')
|
||||
|
||||
@section('title', 'Lupa Password')
|
||||
|
||||
@section('content')
|
||||
|
||||
<style>
|
||||
button {
|
||||
margin-top: 10px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="login">
|
||||
|
||||
<h1>Lupa Password</h1>
|
||||
|
||||
<form action="{{ route('otp.send') }}" method="POST" class="form login-form">
|
||||
@csrf
|
||||
|
||||
<label class="form-label" for="email">Email</label>
|
||||
<div class="form-group">
|
||||
<svg class="form-icon-left" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 512 512">
|
||||
<path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z" />
|
||||
</svg>
|
||||
<input class="form-input" type="email" name="email" placeholder="Email" id="email" value="{{ old('email') }}" required>
|
||||
</div>
|
||||
|
||||
@error('email')
|
||||
<div class="msg error">
|
||||
<p>{{ $message }}</p>
|
||||
</div>
|
||||
@enderror
|
||||
|
||||
@if (session('status'))
|
||||
<div class="msg success">
|
||||
<p>{{ session('status') }}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<button class="btn blue" type="submit">Kirim</button>
|
||||
<p class="register-link">Sudah punya akun? <a href="{{ route('login') }}" class="form-link">Login</a></p>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
|
@ -3,6 +3,7 @@
|
|||
@section('title', 'Login')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="login">
|
||||
|
||||
<h1>Login Dulu Sob</h1>
|
||||
|
@ -32,8 +33,8 @@
|
|||
@endif
|
||||
|
||||
<button class="btn blue" type="submit">Login</button>
|
||||
|
||||
<p class="register-link">Don't have an account? <a href="{{ route('register') }}" class="form-link">Register</a></p>
|
||||
<p class="register-link">Lupa kata sandi? <a href="{{ route('lupa.kata.sandi') }}" class="form-link">Lupa Password</a></p>
|
||||
<p class="register-link">Tidak mempunyai akun? <a href="{{ route('register') }}" class="form-link">Register</a></p>
|
||||
|
||||
</form>
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
@extends('layouts.auth')
|
||||
|
||||
@section('title', 'Otp')
|
||||
|
||||
@section('content')
|
||||
|
||||
<style>
|
||||
button {
|
||||
margin-top: 10px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="login">
|
||||
<h1>Masukkan Kode OTP</h1>
|
||||
|
||||
<form action="{{ route('otp.verify') }}" method="POST" class="form login-form">
|
||||
@csrf
|
||||
|
||||
<input type="hidden" name="email" value="{{ session('email') }}">
|
||||
|
||||
<label class="form-label" for="otp">Kode OTP</label>
|
||||
<div class="form-group">
|
||||
<svg class="form-icon-left" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 512 512">
|
||||
<path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z" />
|
||||
</svg>
|
||||
<input class="form-input" type="text" name="otp_code" placeholder="OTP" id="otp" required>
|
||||
</div>
|
||||
|
||||
@error('otp')
|
||||
<div class="msg error">
|
||||
<p>{{ $message }}</p>
|
||||
</div>
|
||||
@enderror
|
||||
|
||||
@if (session('status'))
|
||||
<div class="msg success">
|
||||
<p>{{ session('status') }}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<button class="btn blue" type="submit">Kirim</button>
|
||||
<p class="register-link">Sudah punya akun? <a href="{{ route('login') }}" class="form-link">Login</a></p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@endsection
|
|
@ -67,7 +67,7 @@
|
|||
|
||||
<button class="btn blue" type="submit">Register</button>
|
||||
|
||||
<p class="register-link">Already have an account? <a href="{{ route('login') }}" class="form-link">Login</a></p>
|
||||
<p class="register-link">Sudah Memiliki Akun? <a href="{{ route('login') }}" class="form-link">Login</a></p>
|
||||
|
||||
</form>
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
@extends('layouts.auth')
|
||||
|
||||
@section('title', 'Reset Sandi')
|
||||
|
||||
@section('content')
|
||||
|
||||
<style>
|
||||
button {
|
||||
margin-top: 10px !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="login">
|
||||
<h1>Masukkan Sandi Baru</h1>
|
||||
|
||||
<form action="{{ route('reset.password') }}" method="POST" class="form login-form">
|
||||
@csrf
|
||||
|
||||
<input type="hidden" name="email" value="{{ session('email') }}">
|
||||
|
||||
<label class="form-label" for="new_password">Sandi Baru</label>
|
||||
<div class="form-group">
|
||||
<svg class="form-icon-left" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 512 512">
|
||||
<path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z" />
|
||||
</svg>
|
||||
<input class="form-input" type="password" name="password" placeholder="Sandi Baru" id="new_password" required minlength="8">
|
||||
</div>
|
||||
|
||||
@error('password')
|
||||
<div class="msg error">
|
||||
<p>{{ $message }}</p>
|
||||
</div>
|
||||
@enderror
|
||||
|
||||
<label class="form-label" for="new_password_confirmation">Konfirmasi Sandi Baru</label>
|
||||
<div class="form-group">
|
||||
<svg class="form-icon-left" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 512 512">
|
||||
<path d="M48 64C21.5 64 0 85.5 0 112c0 15.1 7.1 29.3 19.2 38.4L236.8 313.6c11.4 8.5 27 8.5 38.4 0L492.8 150.4c12.1-9.1 19.2-23.3 19.2-38.4c0-26.5-21.5-48-48-48H48zM0 176V384c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V176L294.4 339.2c-22.8 17.1-54 17.1-76.8 0L0 176z" />
|
||||
</svg>
|
||||
<input class="form-input" type="password" name="password_confirmation" placeholder="Konfirmasi Sandi Baru" id="new_password_confirmation" required>
|
||||
</div>
|
||||
|
||||
@error('password_confirmation')
|
||||
<div class="msg error">
|
||||
<p>{{ $message }}</p>
|
||||
</div>
|
||||
@enderror
|
||||
|
||||
@if (session('status'))
|
||||
<div class="msg success">
|
||||
<p>{{ session('status') }}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<button class="btn blue" type="submit">Reset Sandi</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@endsection
|
|
@ -223,7 +223,7 @@
|
|||
<h2 class="mb-2"><span>Gallyndra Fatkhu Dinata, S.P., M.P.</span></h2>
|
||||
<p>
|
||||
Gallyndra Fatkhu Dinata, S.P., M.P. merupakan dosen di Jurusan Produksi Pertanian, Politeknik Negeri Jember.
|
||||
Beliau memiliki keahlian dalam bidang budidaya pertanian dan pengelolaan tanaman hortikultura, serta aktif dalam berbagai kegiatan penelitian pada tanaman maupun hama.
|
||||
Beliau memiliki keahlian dalam bidang budidaya pertanian dan pengelolaan tanaman hortikultura, serta aktif dalam berbagai kegiatan penelitian pada tanaman.
|
||||
Sebagai pakar, beliau telah banyak membantu mahasiswa dalam mengembangkan penelitian yang aplikatif di bidang pertanian modern.
|
||||
</p>
|
||||
<table>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// Import the controllers
|
||||
use App\Http\Controllers\Auth\LoginController;
|
||||
use App\Http\Controllers\Auth\RegisterController;
|
||||
use App\Http\Controllers\Auth\LupaPasswordController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\HistoryController;
|
||||
|
@ -64,6 +65,25 @@
|
|||
Route::delete('/gejala/{id}', [DaftarGejalaController::class, 'destroy'])->name('gejala.destroy');
|
||||
});
|
||||
|
||||
// Route untuk menampilkan form input email
|
||||
Route::get('lupa-kata-sandi', [LupaPasswordController::class, 'showInputEmail'])->name('lupa.kata.sandi');
|
||||
|
||||
// Route untuk mengirimkan OTP ke email
|
||||
Route::post('kirim-otp', [LupaPasswordController::class, 'sendOtp'])->name('otp.send');
|
||||
|
||||
// Route untuk menampilkan form OTP
|
||||
Route::get('otp', [LupaPasswordController::class, 'showOtpForm'])->name('otp.form');
|
||||
|
||||
// Route untuk memverifikasi OTP
|
||||
Route::post('verifikasi-otp', [LupaPasswordController::class, 'verifyOtp'])->name('otp.verify');
|
||||
|
||||
// Route untuk menampilkan form reset password
|
||||
Route::get('reset-password', [LupaPasswordController::class, 'showResetPass'])->name('reset.password.form');
|
||||
|
||||
// Route untuk melakukan reset password
|
||||
Route::post('reset-password', [LupaPasswordController::class, 'resetPassword'])->name('reset.password');
|
||||
|
||||
|
||||
// Registration Routes
|
||||
Route::get('register', [RegisterController::class, 'showRegistrationForm'])->name('register');
|
||||
Route::post('register', [RegisterController::class, 'register']);
|
||||
|
@ -73,6 +93,11 @@
|
|||
Route::post('/diagnosa/process', [DiagnosaController::class, 'process'])->name('diagnosa.process')->middleware('auth');
|
||||
Route::get('/diagnosa/hasil/{id}', [DiagnosaController::class, 'hasil'])->name('diagnosa.hasil')->middleware('auth');
|
||||
|
||||
// Lupa Pass
|
||||
Route::get('/lupapass', function () {
|
||||
return view('layouts.inputemail');
|
||||
})->name('lupapass');
|
||||
|
||||
|
||||
// Login Routes
|
||||
Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
|
||||
|
@ -111,7 +136,6 @@
|
|||
// Route ke halaman detail riwayat
|
||||
Route::get('/history/{id}/detail', [HistoryController::class, 'detail'])->name('history.detail');
|
||||
Route::get('/history/{id}/print', [HistoryController::class, 'print'])->name('history.print')->middleware('auth');
|
||||
|
||||
});
|
||||
|
||||
// Rincian detail penyakit
|
||||
|
|
Loading…
Reference in New Issue