From 47517c76094834d582121b84098c84c0bcb8353f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 23 Apr 2015 17:40:24 +0200 Subject: Add AddUser mask for creating test accounts --- inc/user.inc.php | 17 ++++++++++ index.php | 1 + modules/adduser.inc.php | 81 ++++++++++++++++++++++++++++++++++++++++++++ templates/adduser/_page.html | 68 +++++++++++++++++++++++++++++++++++++ templates/main-menu.html | 6 +++- 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 modules/adduser.inc.php create mode 100644 templates/adduser/_page.html diff --git a/inc/user.inc.php b/inc/user.inc.php index e2b7e43..3325421 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -76,6 +76,16 @@ class User { return isset(self::$user['role']) && self::$user['role'] === 'tutor'; } + + public static function isAdmin() + { + // TODO: Not hardcoded; per Institution... + return in_array(self::getShibId(), array( + '5fb22037697816a70a847d15245c9f88', + '94e48d34587ab9963a2013ddc97e1e45', + 'fb91f270a95a5b006be916f2b2da305c', + ), true); + } public static function getOrganizationId() { @@ -111,6 +121,13 @@ class User } return self::$organization; } + + public static function getShibId() + { + if (empty(self::$user['shibid'])) + return false; + return self::$user['shibid']; + } public static function load() { diff --git a/index.php b/index.php index b38753d..8e06975 100644 --- a/index.php +++ b/index.php @@ -106,6 +106,7 @@ User::load(); Render::addTemplate('main-menu', array( 'url' => urlencode($_SERVER['REQUEST_URI']), 'user' => User::getName(), + 'admin' => User::isAdmin(), )); Message::renderList(); diff --git a/modules/adduser.inc.php b/modules/adduser.inc.php new file mode 100644 index 0000000..fc0dfa7 --- /dev/null +++ b/modules/adduser.inc.php @@ -0,0 +1,81 @@ +'; + } else { + // No @, try add orgid + $suffix = $organizationid; + $login .= "@$suffix"; + } + $ok = Database::queryFirst('SELECT organizationid FROM satellite_suffix WHERE organizationid = :o AND suffix = :s LIMIT 1', array( + 'o' => $organizationid, + 's' => $suffix + )); + if ($ok === false) { + Message::addError('Login-Suffix @{{0}} ist ungültig.', $suffix); + } else { + Database::exec('INSERT INTO user (login, password, organizationid, firstname, lastname, email) ' + . ' VALUES (:login, :password, :organization, :firstname, :lastname, :email)', array( + 'login' => $login, + 'password' => Crypto::hash6($password), + 'organization' => $organizationid, + 'firstname' => $firstname, + 'lastname' => $lastname, + 'email' => Request::post('email') + )); + Message::addSuccess('Benutzer {{0}} angelegt', $login); + } + } + Util::redirect('?do=Main'); + } + } + + protected function doRender() + { + // Show mask + $res = Database::simpleQuery('SELECT organizationid, name FROM satellite ORDER BY name ASC'); + $orgs = array(); + $orgs[] = array( + 'organizationid' => '', + 'name' => ' -- Bitte wählen -- ' + ); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $orgs[] = $row; + } + Render::addTemplate('adduser/_page', array('orgs' => $orgs)); + } + +} \ No newline at end of file diff --git a/templates/adduser/_page.html b/templates/adduser/_page.html new file mode 100644 index 0000000..857c2c4 --- /dev/null +++ b/templates/adduser/_page.html @@ -0,0 +1,68 @@ +

Neuen Benutzer hinzufügen

+ +
+ + +
+ +
+ + Einrichtung + + +
+ +
+ + Login + + +
+ +
+ + Passwort + + +
+ +
+ + Vorname + + +
+ +
+ + Nachname + + +
+ +
+ + Mail + + +
+ +
+ +
+ +
+
+ + \ No newline at end of file diff --git a/templates/main-menu.html b/templates/main-menu.html index 8e78bc2..2cfe389 100644 --- a/templates/main-menu.html +++ b/templates/main-menu.html @@ -10,6 +10,11 @@ bwLehrpool - -- cgit v1.2.3-55-g7522