Skip to content
Snippets Groups Projects
Commit 340ec43c authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Add last_login and auth_method to user table. (#1171)

parent 55cc5abd
Branches
Tags
No related merge requests found
--
-- Modifications to table `user`
--
ALTER TABLE "user"
ADD COLUMN last_login timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
ADD COLUMN auth_method varchar(50) DEFAULT NULL;
...@@ -198,6 +198,8 @@ CREATE TABLE `user` ( ...@@ -198,6 +198,8 @@ CREATE TABLE `user` (
`home_library` varchar(100) NOT NULL DEFAULT '', `home_library` varchar(100) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `created` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`verify_hash` varchar(42) NOT NULL DEFAULT '', `verify_hash` varchar(42) NOT NULL DEFAULT '',
`last_login` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`auth_method` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`), UNIQUE KEY `username` (`username`),
UNIQUE KEY `cat_id` (`cat_id`) UNIQUE KEY `cat_id` (`cat_id`)
......
...@@ -123,6 +123,8 @@ major varchar(100) NOT NULL DEFAULT '', ...@@ -123,6 +123,8 @@ major varchar(100) NOT NULL DEFAULT '',
home_library varchar(100) NOT NULL DEFAULT '', home_library varchar(100) NOT NULL DEFAULT '',
created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00', created timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
verify_hash varchar(42) NOT NULL DEFAULT '', verify_hash varchar(42) NOT NULL DEFAULT '',
last_login timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
auth_method varchar(50) DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE (username), UNIQUE (username),
UNIQUE (cat_id) UNIQUE (cat_id)
......
...@@ -515,6 +515,7 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface ...@@ -515,6 +515,7 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface
public function create($request) public function create($request)
{ {
$user = $this->getAuth()->create($request); $user = $this->getAuth()->create($request);
$this->updateUser($user);
$this->updateSession($user); $this->updateSession($user);
return $user; return $user;
} }
...@@ -578,6 +579,9 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface ...@@ -578,6 +579,9 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface
throw new AuthException('authentication_error_technical'); throw new AuthException('authentication_error_technical');
} }
// Update user object
$this->updateUser($user);
// Store the user in the session and send it back to the caller: // Store the user in the session and send it back to the caller:
$this->updateSession($user); $this->updateSession($user);
return $user; return $user;
...@@ -627,4 +631,23 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface ...@@ -627,4 +631,23 @@ class Manager implements \ZfcRbac\Identity\IdentityProviderInterface
{ {
return $this->getAuth()->validateCredentials($request); return $this->getAuth()->validateCredentials($request);
} }
/**
* Update common user attributes on login
*
* @param \VuFind\Db\Row\User $user User object
*
* @return void
*/
protected function updateUser($user)
{
if ($this->getAuth() instanceof ChoiceAuth) {
$method = $this->getAuth()->getSelectedAuthOption();
} else {
$method = $this->activeAuth;
}
$user->auth_method = strtolower($method);
$user->last_login = date('Y-m-d H:i:s');
$user->save();
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment