diff options
author | Simon Rettberg | 2016-05-19 17:00:35 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-19 17:00:35 +0200 |
commit | 4e65c3bc0bccf6be849cceb185aacd18e337f7f4 (patch) | |
tree | b877d3502b3d48fa3f65a316e4615465d41af8a8 /modules-available/usermanagement | |
parent | Fix CSRF token checking; improve token/sid generation (diff) | |
download | slx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.tar.gz slx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.tar.xz slx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.zip |
[usermanagement] Merge changes from 'gitlab.c3sl.ufpr.br/cdn/slx-admin.git'
Diffstat (limited to 'modules-available/usermanagement')
-rw-r--r-- | modules-available/usermanagement/page.inc.php | 51 | ||||
-rw-r--r-- | modules-available/usermanagement/templates/user-management.html | 107 |
2 files changed, 97 insertions, 61 deletions
diff --git a/modules-available/usermanagement/page.inc.php b/modules-available/usermanagement/page.inc.php index 34dc517f..605f66c0 100644 --- a/modules-available/usermanagement/page.inc.php +++ b/modules-available/usermanagement/page.inc.php @@ -23,7 +23,7 @@ class Page_Usermanagement extends Page $this->edit(Request::post('userid'),Request::post('username'),Request::post('phone'),Request::post('email'), 4); break; case "create": - $this->create(Request::post('login'),Request::post('username'),Request::post('pass'),Request::post('phone'),Request::post('email'), 4); + $this->create(Request::post('login'),Request::post('username'),Request::post('pass'),Request::post('phone'),Request::post('email'), Request::post('city')); break; case "delete": $this->delete(Request::post('userid')); @@ -59,16 +59,28 @@ class Page_Usermanagement extends Page ); } - //$pag = new Paginate($users,$this->page); + // load every city + $cities = array(); + $res = Database::simpleQuery("SELECT cityid, name, ip FROM cities ORDER BY name DESC"); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $cities[] = array( + 'id' => $row['cityid'], + 'name' => $row['name'], + 'ip' => $row['ip'] + ); + } + + $pag = new Pagination($users,$this->page); Render::addTemplate('user-management', array( 'admin_id' => $admin[0], 'admin_username' => $admin[1], 'admin_name' => $admin[2], 'admin_telephone' => $admin[3], - 'admin_email' => $admin[4] - //'users' => $pag->getItems(), - //'pages' => $pag->getPagination() + 'admin_email' => $admin[4], + 'cities' => $cities, + 'users' => $pag->getItems(), + 'pages' => $pag->getPagination() )); } @@ -84,15 +96,34 @@ class Page_Usermanagement extends Page Message::addSuccess('update-user'); } - private function create($login, $username, $password, $phone, $email){ - $data = array ( + private function create($login, $username, $password, $phone, $email, $city){ + if (empty($login) || empty($username) || empty ($password)) { + Message::addError ( 'empty-field' ); + Util::redirect ( '?do=Usermanagement' ); + } else { + $data = array ( 'login' => $login, 'pass' => Crypto::hash6 ( $password ), 'name' => $username, 'phone' => $phone, - 'email' => $email - ); - User::addUser($data); + 'email' => $email, + 'city' => $city, + 'permission' => 4 + ); + // TODO: Remove city column from user table; should be done in an n:m fashion via extra table + Database::exec ( "INSERT INTO user SET login = :login, passwd = :pass, fullname = :name, phone = :phone, email = :email, city = :city, permissions = :permission", $data ); + $ret = Database::queryFirst('SELECT userid FROM user WHERE login = :user LIMIT 1', array('user' => $data['login'])); + $user = array( + 'user' => $ret['userid'] + ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '44', size = '5G', mount_point = '/tmp', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '43', size = '20G', mount_point = '/boot', options = 'bootable', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '40', size = '20G', mount_point = '/cache/export/dnbd3', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '41', size = '5G', mount_point = '/home', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '82', size = '1G', user = :user", $user ); + Message::addSuccess('add-user'); + EventLog::info ( User::getName () . ' created user ' . $data['login'] ); + } } private function delete($userid){ diff --git a/modules-available/usermanagement/templates/user-management.html b/modules-available/usermanagement/templates/user-management.html index fc14355f..4e4ce7dc 100644 --- a/modules-available/usermanagement/templates/user-management.html +++ b/modules-available/usermanagement/templates/user-management.html @@ -11,18 +11,18 @@ <th style="text-align: center;">{{lang_email}}</th> <th style="text-align: center;"></th> </tr> - <tr> - <form method="post" action=""> - <input type="hidden" name="action" value="editAdmin"> - <input type="hidden" name="token" value="{{token}}"> - <td><input class="form-control" name="userid" type="text" readonly="readonly" value="{{admin_id}}" size="3"></td> - <td><input class="form-control" type="text" disabled="disabled" value="{{admin_username}}"></td> - <td><input class="form-control" name="username" type="text" value="{{admin_name}}"></td> - <td><input class="form-control" name="phone" type="text" value="{{admin_telephone}}"></td> - <td><input class="form-control" name="email" type="text" value="{{admin_email}}"></td> - <td><input class="btn btn-primary" type="submit" value="{{lang_save}}"></td> - </form> - </tr> + <tr> + <form method="post" action=""> + <input type="hidden" name="action" value="editAdmin"> + <input type="hidden" name="token" value="{{token}}"> + <td><input class="form-control" name="userid" type="text" readonly="readonly" value="{{admin_id}}" size="3"></td> + <td><input class="form-control" type="text" disabled="disabled" value="{{admin_username}}"></td> + <td><input class="form-control" name="username" type="text" value="{{admin_name}}"></td> + <td><input class="form-control" name="phone" type="text" value="{{admin_telephone}}"></td> + <td><input class="form-control" name="email" type="text" value="{{admin_email}}"></td> + <td><input class="btn btn-primary" type="submit" value="{{lang_save}}"></td> + </form> + </tr> </table> </div> @@ -32,21 +32,26 @@ </div> <div class="panel-body"> <p> - {{lang_userInfo}} + {{lang_userInfo}} </p> - + </div> <table class="table"> <tr> <form method="post" action="?do=Usermanagement"> - <input type="hidden" name="action" value="create"> - <input type="hidden" name="token" value="{{token}}"> - <td><input class="form-control" name="login" type="text" placeholder="{{lang_login}}"></td> - <td><input class="form-control" name="username" type="text" placeholder="{{lang_username}}"></td> - <td><input class="form-control" name="pass" type="password" placeholder="{{lang_password}}"></td> - <td><input class="form-control" name="phone" type="text" placeholder="{{lang_telephone}}"></td> - <td><input class="form-control" name="email" type="text" placeholder="{{lang_email}}"></td> - <td><input class="btn btn-primary" type="submit" value="{{lang_create}}"></td> + <input type="hidden" name="action" value="create"> + <input type="hidden" name="token" value="{{token}}"> + <td><input class="form-control" name="login" type="text" placeholder="{{lang_login}}*"></td> + <td><input class="form-control" name="username" type="text" placeholder="{{lang_username}}*"></td> + <td><input class="form-control" name="pass" type="password" placeholder="{{lang_password}}*"></td> + <td><input class="form-control" name="phone" type="text" placeholder="{{lang_telephone}}"></td> + <td><input class="form-control" name="email" type="text" placeholder="{{lang_email}}"></td> + <td><select class="form-control" name="city"> + {{#cities}} + <option value="{{id}}">{{name}}</option> + {{/cities}} + </select></td> + <td><input class="btn btn-primary" type="submit" value="{{lang_create}}"></td> </form> </tr> <tr> @@ -86,35 +91,35 @@ <div class="modal-content"> <div class="modal-header"><h4 class="modal-title">{{lang_editUser}}</h4></div> <div class="modal-body"> - <form method="post" action=""> - <input type="hidden" name="action" value="edit"> - <input type="hidden" name="token" value="{{token}}"> - <div class="form-group"> - <label for="userid">ID</label> - <input type="text" class="form-control" name="userid" readonly="readonly" name="userid" value="{{id}}"> - </div> - <div class="form-group"> - <label for="userid">Login</label> - <input type="text" class="form-control" name="login" disabled="disabled" placeholder="{{lang_login}}" value="{{username}}"> - </div> - <div class="form-group"> - <label for="userid">{{lang_username}}</label> - <input type="text" class="form-control" name="username" placeholder="{{lang_username}}" value="{{name}}"> - </div> - <div class="form-group"> - <label for="userid">{{lang_telephone}}</label> - <input type="text" class="form-control" name="phone" placeholder="{{lang_telephone}}" value="{{telephone}}"> - </div> - <div class="form-group"> - <label for="userid">{{lang_email}}</label> - <input type="text" class="form-control" name="email" placeholder="{{lang_email}}" value="{{email}}"> - </div> - <div class="form-group"> - <b>Permissões:</b> - <select name="permissions" class="form-control"> - <option value="4">Normal</option> - </select> - </div> + <form method="post" action=""> + <input type="hidden" name="action" value="edit"> + <input type="hidden" name="token" value="{{token}}"> + <div class="form-group"> + <label for="userid">ID</label> + <input type="text" class="form-control" name="userid" readonly="readonly" name="userid" value="{{id}}"> + </div> + <div class="form-group"> + <label for="userid">Login</label> + <input type="text" class="form-control" name="login" disabled="disabled" placeholder="{{lang_login}}" value="{{username}}"> + </div> + <div class="form-group"> + <label for="userid">{{lang_username}}</label> + <input type="text" class="form-control" name="username" placeholder="{{lang_username}}" value="{{name}}"> + </div> + <div class="form-group"> + <label for="userid">{{lang_telephone}}</label> + <input type="text" class="form-control" name="phone" placeholder="{{lang_telephone}}" value="{{telephone}}"> + </div> + <div class="form-group"> + <label for="userid">{{lang_email}}</label> + <input type="text" class="form-control" name="email" placeholder="{{lang_email}}" value="{{email}}"> + </div> + <div class="form-group"> + <b>Permissões:</b> + <select name="permissions" class="form-control"> + <option value="4">Normal</option> + </select> + </div> </div> <div class="modal-footer"> <input class="btn btn-primary" type="submit" value="{{lang_save}}"> |