diff --git a/adduser.php b/adduser.php index 1ccad89..57bc98d 100644 --- a/adduser.php +++ b/adduser.php @@ -18,7 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - require_once("auth.php"); + require_once("auth.php"); // sets $mysqli, $user /** * Exit with xml response @@ -42,51 +42,17 @@ exit; } - /** - * Check if login is allowed - * @param string $login Login - */ - function checkUser($login) { - global $mysqli; - $sql = "SELECT id FROM users WHERE login = ?"; - $query = $mysqli->prepare($sql); - $query->bind_param('s', $login); - $query->execute(); - if ($query->errno) { - exitWithStatus(true, $query->error); - } - $query->store_result(); - if ($query->num_rows) { - exitWithStatus(true, $lang_userexists); - } - $query->free_result(); - $query->close(); - } - - /** - * Add new user to database - * @param string $login Login - * @param string $hash Password hash - */ - function insertUser($login, $hash) { - global $mysqli; - $sql = "INSERT INTO users (login, password) VALUES (?, ?)"; - $query = $mysqli->prepare($sql); - $query->bind_param('ss', $login, $hash); - $query->execute(); - if ($query->errno) { - exitWithStatus(true, $query->error); - $isError = false; - } - $query->close(); - } - $login = isset($_REQUEST['login']) ? trim($_REQUEST['login']) : NULL; $hash = isset($_REQUEST['pass']) ? password_hash($_REQUEST['pass'], PASSWORD_DEFAULT) : NULL; - if ($admin && !empty($login) && !empty($hash)) { - checkUser($login); - insertUser($login, $hash); + if ($user->isAdmin && !empty($login) && !empty($hash)) { + $newUser = new uUser($login); + if ($newUser->isValid) { + exitWithStatus(true, $lang_userexists); + } + if ($newUser->add($login, $hash) === false) { + exitWithStatus(true, $mysqli->error); + } } exitWithStatus(false); - + ?> \ No newline at end of file diff --git a/admin.js b/admin.js index b118c38..6e22906 100644 --- a/admin.js +++ b/admin.js @@ -17,19 +17,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -function showModal(contentHTML) { - var div = document.createElement("div"); - div.setAttribute("id", "modal"); - div.innerHTML = '
'; - document.body.appendChild(div); - var modalBody = document.getElementById('modal-body'); - modalBody.innerHTML = contentHTML; -} - -function removeModal() { - document.body.removeChild(document.getElementById('modal')); -} - function addUser() { var form = ' '; } - // prepare track select form -$track_form = ' -'.$lang_track.'