summaryrefslogtreecommitdiffstats
path: root/inc/user.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-03 14:26:22 +0200
committerSimon Rettberg2015-06-03 14:26:22 +0200
commit5136f6622e7ca87695c158a31cb8e78299f1967a (patch)
tree554c58c63fdbf58401fcf4e49ac9685e1eff9634 /inc/user.inc.php
parentAdd AddUser mask for creating test accounts (diff)
downloadbwlp-webadmin-5136f6622e7ca87695c158a31cb8e78299f1967a.tar.gz
bwlp-webadmin-5136f6622e7ca87695c158a31cb8e78299f1967a.tar.xz
bwlp-webadmin-5136f6622e7ca87695c158a31cb8e78299f1967a.zip
Allow registration, add support for creating test accounts, rename satellite to organization
Diffstat (limited to 'inc/user.inc.php')
-rw-r--r--inc/user.inc.php51
1 files changed, 46 insertions, 5 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php
index 3325421..c09e936 100644
--- a/inc/user.inc.php
+++ b/inc/user.inc.php
@@ -60,6 +60,13 @@ class User
return self::$user['firstname'] . ' ' . self::$user['lastname'];
}
+ public static function getFirstName()
+ {
+ if (!self::isLoggedIn())
+ return false;
+ return self::$user['firstname'];
+ }
+
public static function getLastName()
{
if (!self::isLoggedIn())
@@ -87,6 +94,11 @@ class User
), true);
}
+ /**
+ * Organization ID used locally in our DB
+ *
+ * @return string
+ */
public static function getOrganizationId()
{
$org = self::getOrganization();
@@ -103,6 +115,11 @@ class User
return $org['name'];
}
+ /**
+ * Organization ID as supplied by shibboleth
+ *
+ * @return string
+ */
public static function getRemoteOrganizationId()
{
if (empty(self::$user['organization']))
@@ -115,8 +132,8 @@ class User
if (!self::isLoggedIn())
return false;
if (is_null(self::$organization)) {
- self::$organization = Database::queryFirst('SELECT organizationid, name FROM satellite_suffix '
- . ' INNER JOIN satellite USING (organizationid) '
+ self::$organization = Database::queryFirst('SELECT organizationid, name FROM organization_suffix '
+ . ' INNER JOIN organization USING (organizationid) '
. ' WHERE suffix = :org LIMIT 1', array('org' => self::$user['organization']));
}
return self::$organization;
@@ -194,21 +211,44 @@ class User
return true;
}
- public static function deploy($anonymous)
+ public static function deploy($anonymous, $existingLogin = false)
{
if (empty(self::$user['shibid']))
Util::traceError('NO SHIBID');
+
+ // Merging with test-account:
+ if (!empty($existingLogin)) {
+ if ($anonymous) {
+ $ret = Database::exec("UPDATE user SET shibid = :shibid, firstname = '', lastname = '', email = '', password = '' "
+ . " WHERE login = :login LIMIT 1", array(
+ 'shibid' => self::$user['shibid'],
+ 'login' => $existingLogin
+ ));
+ } else {
+ $ret = Database::exec("UPDATE user SET shibid = :shibid, password = '', firstname = :firstname, lastname = :lastname, email = :email "
+ . " WHERE login = :login LIMIT 1", array(
+ 'shibid' => self::$user['shibid'],
+ 'login' => $existingLogin,
+ 'firstname' => self::$user['firstname'],
+ 'lastname' => self::$user['lastname'],
+ 'email' => self::$user['email']
+ ));
+ }
+ return $ret > 0;
+ }
+
+ // New account
if ($anonymous) {
Database::exec("INSERT INTO user (shibid, login, organizationid, firstname, lastname, email) "
. " VALUES (:shibid, :shibid, :org, '', '', '') "
- . " ON DUPLICATE KEY UPDATE firstname = '', lastname = '', email = ''", array(
+ . " ON DUPLICATE KEY UPDATE firstname = '', lastname = '', email = '', password = ''", array(
'shibid' => self::$user['shibid'],
'org' => self::getOrganizationId()
));
} else {
Database::exec("INSERT INTO user (shibid, login, organizationid, firstname, lastname, email) "
. " VALUES (:shibid, :shibid, :org, :firstname, :lastname, :email) "
- . " ON DUPLICATE KEY UPDATE firstname = VALUES(firstname), lastname = VALUES(lastname), email = VALUES(email)", array(
+ . " ON DUPLICATE KEY UPDATE firstname = VALUES(firstname), lastname = VALUES(lastname), email = VALUES(email), password = ''", array(
'shibid' => self::$user['shibid'],
'firstname' => self::$user['firstname'],
'lastname' => self::$user['lastname'],
@@ -216,6 +256,7 @@ class User
'org' => self::getOrganizationId()
));
}
+ return true;
}
public static function updatePassword($pass)