ulogger-server/utils/handleuser.php

64 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/* μlogger
*
* Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
*
* This is free software; you can redistribute it and/or modify it under
2017-04-07 00:05:28 +02:00
* the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
2017-04-07 00:05:28 +02:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
2017-04-09 23:35:55 +02:00
2017-08-25 13:59:19 +02:00
require_once(dirname(__DIR__) . "/helpers/auth.php");
2017-05-09 18:18:15 +02:00
require_once(ROOT_DIR . "/helpers/utils.php");
2017-08-25 13:59:19 +02:00
$auth = new uAuth();
2017-04-12 20:16:39 +02:00
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
$login = isset($_REQUEST['login']) ? trim($_REQUEST['login']) : NULL;
$pass = isset($_REQUEST['pass']) ? $_REQUEST['pass'] : NULL;
2017-08-25 13:59:19 +02:00
if (!$auth->isAuthenticated() || !$auth->isAdmin || $auth->user->login == $login || empty($action) || empty($login)) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
}
2017-04-12 20:16:39 +02:00
$aUser = new uUser($login);
switch ($action) {
case 'add':
if ($aUser->isValid) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["userexists"]);
2017-04-12 20:16:39 +02:00
}
if (empty($pass) || uUser::add($login, $pass) === false) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-12 20:16:39 +02:00
}
break;
case 'update':
// update password
if (empty($pass) || $aUser->setPass($pass) === false) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-12 20:16:39 +02:00
}
break;
case 'delete':
if ($aUser->delete() === false) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-12 20:16:39 +02:00
}
break;
default:
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-12 20:16:39 +02:00
break;
}
2017-05-09 18:18:15 +02:00
uUtils::exitWithSuccess();
?>