diff options
author | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
commit | 50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66 (patch) | |
tree | 05e99fdffa696434960d7c77966c0bc36d6339e8 /modules-available/adduser | |
parent | Second half of merge.... (diff) | |
download | slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.gz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.xz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.zip |
WIP
Diffstat (limited to 'modules-available/adduser')
-rw-r--r-- | modules-available/adduser/config.json | 3 | ||||
-rw-r--r-- | modules-available/adduser/lang/de/templates/page-adduser.json | 8 | ||||
-rw-r--r-- | modules-available/adduser/lang/en/module.json | 8 | ||||
-rw-r--r-- | modules-available/adduser/lang/en/templates/page-adduser.json | 8 | ||||
-rw-r--r-- | modules-available/adduser/lang/pt/module.json | 8 | ||||
-rw-r--r-- | modules-available/adduser/page.inc.php | 60 | ||||
-rw-r--r-- | modules-available/adduser/templates/page-adduser.html | 28 |
7 files changed, 123 insertions, 0 deletions
diff --git a/modules-available/adduser/config.json b/modules-available/adduser/config.json new file mode 100644 index 00000000..4da67ef8 --- /dev/null +++ b/modules-available/adduser/config.json @@ -0,0 +1,3 @@ +{ + "enabled":"true" +} diff --git a/modules-available/adduser/lang/de/templates/page-adduser.json b/modules-available/adduser/lang/de/templates/page-adduser.json new file mode 100644 index 00000000..0f446025 --- /dev/null +++ b/modules-available/adduser/lang/de/templates/page-adduser.json @@ -0,0 +1,8 @@ +{ + "lang_confirmation": "Wiederholen", + "lang_createUser": "Benutzer anlegen", + "lang_fullName": "Vollst\u00e4ndiger Name", + "lang_password": "Passwort", + "lang_telephone": "Telefon", + "lang_username": "Benutzerkennung" +}
\ No newline at end of file diff --git a/modules-available/adduser/lang/en/module.json b/modules-available/adduser/lang/en/module.json new file mode 100644 index 00000000..170c12f6 --- /dev/null +++ b/modules-available/adduser/lang/en/module.json @@ -0,0 +1,8 @@ +{ + "lang_confirmation": "Confirm Password", + "lang_createUser": "Create User", + "lang_fullName": "Fullname", + "lang_password": "Password", + "lang_telephone": "Telephone", + "lang_username": "Username" +}
\ No newline at end of file diff --git a/modules-available/adduser/lang/en/templates/page-adduser.json b/modules-available/adduser/lang/en/templates/page-adduser.json new file mode 100644 index 00000000..42bae6dc --- /dev/null +++ b/modules-available/adduser/lang/en/templates/page-adduser.json @@ -0,0 +1,8 @@ +{ + "lang_confirmation": "Confirm Password", + "lang_createUser": "Create User", + "lang_fullName": "Full Name", + "lang_password": "Password", + "lang_telephone": "Telephone", + "lang_username": "Username" +}
\ No newline at end of file diff --git a/modules-available/adduser/lang/pt/module.json b/modules-available/adduser/lang/pt/module.json new file mode 100644 index 00000000..524f3dd5 --- /dev/null +++ b/modules-available/adduser/lang/pt/module.json @@ -0,0 +1,8 @@ +{ + "lang_confirmation": "Confirmar Senha", + "lang_createUser": "Criar Usu\u00e1rio", + "lang_fullName": "Nome Completo", + "lang_password": "Senha", + "lang_telephone": "Telefone", + "lang_username": "Nome de Usu\u00e1rio" +}
\ No newline at end of file diff --git a/modules-available/adduser/page.inc.php b/modules-available/adduser/page.inc.php new file mode 100644 index 00000000..c236cb6f --- /dev/null +++ b/modules-available/adduser/page.inc.php @@ -0,0 +1,60 @@ +<?php + +class Page_AddUser extends Page +{ + + protected function doPreprocess() + { + User::load(); + + if (isset($_POST['action']) && $_POST['action'] === 'adduser') { + // Check required fields + if (empty($_POST['user']) || empty($_POST['pass1']) || empty($_POST['pass2']) || empty($_POST['fullname'])) { + Message::addError('empty-field'); + Util::redirect('?do=AddUser'); + } elseif ($_POST['pass1'] !== $_POST['pass2']) { + Message::addError('password-mismatch'); + Util::redirect('?do=AddUser'); + } elseif (!User::hasPermission('superadmin') && Database::queryFirst('SELECT userid FROM user LIMIT 1') !== false) { + Message::addError('adduser-disabled'); + Util::redirect('?do=Session&action=login'); + } else { + $data = array( + 'user' => $_POST['user'], + 'pass' => Crypto::hash6($_POST['pass1']), + 'fullname' => $_POST['fullname'], + 'phone' => $_POST['phone'], + 'email' => $_POST['email'], + ); + if (Database::exec('INSERT INTO user SET login = :user, passwd = :pass, fullname = :fullname, phone = :phone, email = :email', $data) != 1) { + Util::traceError('Could not create new user in DB'); + } + // Make it superadmin if first user. This method sucks as it's a race condition but hey... + $ret = Database::queryFirst('SELECT Count(*) AS num FROM user'); + if ($ret !== false && $ret['num'] == 1) { + Database::exec('UPDATE user SET permissions = 1'); + EventLog::clear(); + EventLog::info('Created first user ' . $_POST['user']); + } else { + EventLog::info(User::getName() . ' created user ' . $_POST['user']); + } + Message::addInfo('adduser-success'); + Util::redirect('?do=Session&action=login'); + } + } + } + + protected function doRender() + { + // No user was added, check if current user is allowed to add a new user + // Currently you can only add users if there is no user yet. :) + if (!User::hasPermission('superadmin') && Database::queryFirst('SELECT userid FROM user LIMIT 1') !== false) { + Message::addError('adduser-disabled'); + } else { + + Render::setTitle(Dictionary::translate('lang_createUser')); + Render::addTemplate('page-adduser', $_POST); + } + } + +} diff --git a/modules-available/adduser/templates/page-adduser.html b/modules-available/adduser/templates/page-adduser.html new file mode 100644 index 00000000..0b097890 --- /dev/null +++ b/modules-available/adduser/templates/page-adduser.html @@ -0,0 +1,28 @@ +<form class="form-adduser" action="?do=AddUser" method="post"> + <input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;"> + <input type="password" name="password_fake" id="password_fake" value="" style="display:none;"> + <h2 class="form-signin-heading">{{lang_createUser}}</h2> + <div class="row"> + <div class="col-md-4">{{lang_username}} *</div> + <div class="col-md-4"><input type="text" name="user" value="{{user}}" class="form-control" placeholder="{{lang_username}}" autofocus></div> + </div> + <div class="row"> + <div class="col-md-4">{{lang_password}} *</div> + <div class="col-md-4"><input type="password" name="pass1" class="form-control" placeholder="{{lang_password}}"></div> + <div class="col-md-4"><input type="password" name="pass2" class="form-control" placeholder="{{lang_confirmation}}"></div> + </div> + <div class="row"> + <div class="col-md-4">{{lang_fullName}} *</div> + <div class="col-md-4"><input type="text" name="fullname" value="{{fullname}}" class="form-control" placeholder="{{lang_fullName}}"></div> + </div> + <div class="row"> + <div class="col-md-4">{{lang_telephone}}</div> + <div class="col-md-4"><input type="text" name="phone" value="{{phone}}" class="form-control" placeholder="{{lang_telephone}}"></div> + </div> + <div class="row"> + <div class="col-md-4">E-Mail</div> + <div class="col-md-4"><input type="text" name="email" value="{{email}}" class="form-control" placeholder="E-Mail"></div> + </div> + <button class="btn btn-lg btn-primary btn-block" type="submit">{{lang_createUser}}</button> + <input type="hidden" name="action" value="adduser"> +</form>
\ No newline at end of file |