0
votes

I am using cakephp v3.x

Below is my login function.

public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(__('Invalid username or password, try again'));
    }
} //public function login()

I am trying to get the username who tried to log in. I tried reading http://book.cakephp.org/3.0/en/controllers/components/authentication.html I am not able to find the API to retrieve the username. How can this be done?

2
Guessing you can just access the post params like you'd do normally book.cakephp.org/3.0/en/controllers/… - JimL
Do you mean tried to login but not login succeeded ? or after login you want to get the name ? - Alimon Karim
@Alimon Karim, thanks for asking. I have found the answer myself. See answer provided. - user781486
@JimL, thanks to u, I found the answer. See answer provided. - user781486
@user768421 I just read the docs ;) - JimL

2 Answers

0
votes

You will get all details for user :

$user_details = $this->Auth->User();
echo $user_details['username'];
0
votes

Thanks to hint from JimL, the answer is as follows;

$username = $this->request->data['username'];