简体   繁体   中英

Cakephp3.0 Authentication issue

Problem I am facing I can authenticate using blog tutorial but when I am doing the same thing with patients table and I want to login through url/patients/login but everytime I authenticate it said incorrect username and password and in adding user how can I add hash password .

Or anyone can suggest me code where in users login access I can redirect user based on role like admin and author how can I check if user is admin redirect to admin dashboard and if it is author is it possible if yes then please give login function code

I was searching on net how to add a multi level user authentication system I find a solution I am using blog example as full code and in login system I added this code :

 public function login()
 if ($this->request->is('post')) {
    $user = $this->Auth->identify();
    if ($user['role'] === 'admin') {
        $this->Auth->setUser($user);
        return $this->redirect(['controller' => 'articles']);
    } 
    else if ($user['role'] === 'author'){
         $this->Auth->setUser($user);
        return $this->redirect(['action' => 'login' ,'controller' => 'users']);
    }
    $this->Flash->error(__('Invalid username or password, try again'));
}
}

This is a very simple solution I have just added few lines of code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM