EVOLUTION-NINJA
Edit File: AuthController.php
<?php namespace App\Controllers; use App\Models\UserModel; use App\Models\UserModel2; class AuthController extends BaseController { public function forgotPasswordForm() { return view('admin/forgot_password'); } public function sendOtp() { $email = $this->request->getPost('email'); // Check if user exists $userModel = new UserModel(); $user = $userModel->where('email', $email)->first(); if (!$user) { return redirect()->back()->with('error', 'Email not registered.'); } $otp = rand(100000, 999999); session()->set('reset_email', $email); session()->set('reset_otp', $otp); // send email (you need to configure email service in CI4) $emailService = \Config\Services::email(); $emailService->setTo($email); $emailService->setSubject('Password Reset OTP'); $emailService->setMessage("Your OTP is: $otp"); $emailService->send(); return redirect()->to('/verify-otp')->with('message', 'OTP sent to your email.'); } public function verifyOtpForm() { return view('admin/verify_otp'); } public function verifyOtp() { $inputOtp = $this->request->getPost('otp'); $newPassword = $this->request->getPost('new_password'); $confirmPassword = $this->request->getPost('confirm_password'); if ($newPassword !== $confirmPassword) { return redirect()->back()->with('error', 'Passwords do not match.'); } if ($inputOtp == session()->get('reset_otp')) { $userModel = new UserModel(); $email = session()->get('reset_email'); $user = $userModel->where('email', $email)->first(); if ($user) { $userModel->update($user['id'], [ 'password' => password_hash($newPassword, PASSWORD_DEFAULT) ]); session()->remove(['reset_email', 'reset_otp']); return redirect()->to('/')->with('message', 'Password reset successfully.'); } } //return redirect()->back()->with('error', 'Invalid OTP.'); } }?>