From 5136f6622e7ca87695c158a31cb8e78299f1967a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 3 Jun 2015 14:26:22 +0200 Subject: Allow registration, add support for creating test accounts, rename satellite to organization --- inc/image.inc.php | 10 ++++++++++ inc/user.inc.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/image.inc.php b/inc/image.inc.php index 2c0ec74..5b8f077 100644 --- a/inc/image.inc.php +++ b/inc/image.inc.php @@ -9,6 +9,16 @@ class Image return false; return Database::exec('DELETE FROM image WHERE ownerid = :userid', array('userid' => $userid)); } + + public static function getImageCount($login) + { + $ret = Database::queryFirst('SELECT Count(*) AS cnt FROM image ' + . ' INNER JOIN user ON (image.ownerid = user.userid) ' + . ' WHERE user.login = :login', array('login' => $login)); + if ($ret === false) + return 0; + return $ret['cnt']; + } } 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) -- cgit v1.2.3-55-g7522