Cakephp 3.x updating user data

I have written a basic login script and now need to update the data stored in the auth component and then save it to the database, this is what i have so far;

public function login()
{
if ($this->request->is(‘post’)) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$this->Auth->user()->last_activity = date(“Y-m-d”);
$this->Users->save($this->Auth->user());
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__(‘Email or password is incorrect, please try again.’));
}
}
I’ve tried a few different variations but can’t get any to work. Any ideas?

I think this is what you are looking for …

public function login()
{
	if ($this->request->is('post')) {
		$user = $this->Auth->identify();
		if ($user) { 
			$this->Auth->setUser($user);
			$this->request->session()->write('Auth.User.last_activity', date("Y-m-d"));
			$updateData = ['last_activity' => date("Y-m-d")]; 
			$this->Users->query()->update()->set($updateData)->where(['id' => $user['id']])->execute();
			return $this->redirect($this->Auth->redirectUrl());
		}   
		$this->Flash->error(__('Email or password is incorrect, please try again.'));
	}
}