User and Admin Login CodeIgniter 4

289 Views Asked by At

`

  public function loginAuth()
  {
    $session = session();
    $userModel = new UserModel();
    $email = $this->request->getVar('email');
    $password = $this->request->getVar('password');
    $data = $userModel->where('email', $email)->first();
    if($data)
    {
      $pass = $data['password'];
      $authenticatePassword = password_verify($password, $pass);
      if($authenticatePassword)
      {
        $ses_data = [
          'id' => $data['id'],
          'name' => $data['name'],
          'email' => $data['email'],
          'isLoggedIn' => TRUE
        ];
        $session->set($ses_data);
        return redirect()->to('/profile');
      }else{
        $session->setFlashdata('msg', 'Password is incorrect.');
        return redirect()->to('/signin');
      }
    }else{
      $session->setFlashdata('msg', 'Email does not exist.');
      return redirect()->to('/signin');
    }
  }

`

When the user logs in, the profile page will be displayed, and when the admin logs in, it will display the admin page.

0

There are 0 best solutions below