Commit e92d6a90 authored by Donal McMullan's avatar Donal McMullan
Browse files

Move some methods from the User to LiveUser classes

parent dc933f02
......@@ -89,52 +89,6 @@ class User {
}
/**
* Take a username, password and institution and try to authenticate the
* user
*
* @param string $username
* @param string $password
* @param string $institution
* @return bool
*/
public function login($username, $password, $institution) {
$users = get_records_select_array('usr', 'LOWER(username) = ? AND institution = ?', array($username, $institution), 'authinstance', '*');
if ($users == false) {
throw new AuthUnknownUserException("\"$username\" at \"$institution\" is not known");
}
foreach($users as $user) {
$auth = AuthFactory::create($user->authinstance);
if ($auth->authenticate_user_account($user, $password)) {
$this->authenticate($user);
return true;
}
}
return false;
}
/**
* When a user creates a security context by whatever method, we do some
* standard stuff
*
* @param object $user Record from the usr table
* @return void
*/
protected function authenticate($user) {
$this->authenticated = true;
$this->populate($user);
session_regenerate_id(true);
$this->sessionid = session_id();
$this->logout_time = time() + get_config('session_timeout');
$this->sesskey = get_random_key();
$this->activityprefs = load_activity_preferences($user->id);
$this->accountprefs = load_account_preferences($user->id);
$this->commit();
}
/**
*
*/
......@@ -376,6 +330,52 @@ class LiveUser extends User {
}
}
/**
* Take a username, password and institution and try to authenticate the
* user
*
* @param string $username
* @param string $password
* @param string $institution
* @return bool
*/
public function login($username, $password, $institution) {
$users = get_records_select_array('usr', 'LOWER(username) = ? AND institution = ?', array($username, $institution), 'authinstance', '*');
if ($users == false) {
throw new AuthUnknownUserException("\"$username\" at \"$institution\" is not known");
}
foreach($users as $user) {
$auth = AuthFactory::create($user->authinstance);
if ($auth->authenticate_user_account($user, $password)) {
$this->authenticate($user);
return true;
}
}
return false;
}
/**
* When a user creates a security context by whatever method, we do some
* standard stuff
*
* @param object $user Record from the usr table
* @return void
*/
protected function authenticate($user) {
$this->authenticated = true;
$this->populate($user);
session_regenerate_id(true);
$this->sessionid = session_id();
$this->logout_time = time() + get_config('session_timeout');
$this->sesskey = get_random_key();
$this->activityprefs = load_activity_preferences($user->id);
$this->accountprefs = load_account_preferences($user->id);
$this->commit();
}
/**
* Gets the user property keyed by $key.
*
......
Markdown is supported
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