1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<?php
class Page_AddUser extends Page
{
protected function doPreprocess()
{
User::load();
if (!User::isShibbolethAuth()) {
Message::addError('Not bwIDM');
Util::redirect('?do=Main');
}
if (!User::isAdmin()) {
Message::addError('Not admin!');
Util::redirect('?do=Main');
}
// Add?
if (Request::post('action') === 'add') {
$organizationid = Request::post('organization', '');
$firstname = Request::post('firstname', '');
$lastname = Request::post('lastname', '');
$password = Request::post('password', '');
$login = Request::post('login', '');
if (empty($organizationid)) {
Message::addError('Keine Einrichtung gewählt.');
} else if (empty($firstname) || empty($lastname)
|| empty($login) || empty($password)) {
Message:addError('Ein Feld wurde nicht ausgefüllt.');
} else {
// Validate login
if (preg_match('/^[a-z0-9_\.\-]+@([a-z0-9_\.\-]+)$/i', $login, $out)) {
// Complete login
$suffix = $out[1];
} else if (strpos($login, '@') !== false) {
// Has @ but invalid format
Message::addError('Ungültige Syntax für Login');
$suffix = '<invalid>';
} 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));
}
}
|