EVOLUTION-NINJA
Edit File: Login.php
<?php namespace App\Controllers; class Login extends BaseController { public function __construct() { $this->db = \Config\Database::connect(); date_default_timezone_set('Asia/Kolkata'); } // public function index(){ // return view('login_page'); // } public function login() { $email = $this->request->getVar('username'); $password = $this->request->getPost('password'); if (!empty($email) && !empty($password)) { $adminBuilder = $this->db->table('admin'); $adminBuilder->where('email', $email); $admin = $adminBuilder->get()->getRow(); if ($admin) { if (md5($password) === $admin->password) { $sessionData = [ 'id' => $admin->id, 'username' => $admin->username, 'email' => $admin->email, 'role_name' => $admin->role_name, 'role' => $admin->role, ]; session()->set($sessionData); $role=$admin->role; return $this->response->setJSON(['result' => 1, 'message' => 'Admin Login Successful','role'=>$role]); } else { return $this->response->setJSON(['result' => 3, 'message' => 'Invalid Password']); } } // User Login Check $userBuilder = $this->db->table('user'); $userBuilder->where('email', $email) ->where('valid_user',1); $user = $userBuilder->get()->getRow(); if ($user) { if (md5($password)===($user->password)) { $sessionData = [ 'id' => $user->id, 'username' => $user->name, 'email' => $user->email, 'role_name' => $user->role_name, 'role' => $user->role, 'promoter_id' => $user->promoter_id, ]; session()->set($sessionData); $role=$user->role; return $this->response->setJSON(['result' => 1, 'message' => 'Promoter Login Successful','role'=>$role]); } else { return $this->response->setJSON(['result' => 3, 'message' => 'Invalid Password']); } } $customerBuilder = $this->db->table('Customers'); $customerBuilder->where('email', $email); $customerBuilder->where('password', $password); // Direct comparison for plain text $customer = $customerBuilder->get()->getRow(); if ($customer) { $sessionData = [ 'id' => $customer->id, 'username' => $customer->name, 'email' => $customer->email, 'role_name' => 'Customer', 'role' => 'customer', ]; session()->set($sessionData); $role=$customer->role; return $this->response->setJSON(['result' => 1, 'message' => 'Customer Login Successfully','role'=>$role]); } else{ return $this->response->setJSON(['result' => 2, 'message' => 'Invalid Email or Password']); } } } public function logout(){ session()->destroy(); return redirect()->to('/'); } } ?>