From a6e18b25bd62b06cc860feaabb147230c19f874f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 17 Mar 2022 19:38:33 +0800 Subject: [PATCH] feat(web): disable register & add user manager --- web/app/controllers/register.php | 4 + web/app/controllers/super_manage.php | 195 ++++++++++++++------- web/app/views/page-header.php | 7 + web/js/jquery.query-object.js | 247 +++++++++++++++++++++++++++ 4 files changed, 389 insertions(+), 64 deletions(-) create mode 100644 web/js/jquery.query-object.js diff --git a/web/app/controllers/register.php b/web/app/controllers/register.php index 315dec0..6ee7492 100644 --- a/web/app/controllers/register.php +++ b/web/app/controllers/register.php @@ -13,6 +13,10 @@ return "无效表单"; } + if (DB::selectCount("SELECT COUNT(*) FROM user_info")) { + return "只有首位用户可以注册。"; + } + $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; diff --git a/web/app/controllers/super_manage.php b/web/app/controllers/super_manage.php index 7bf5824..9805922 100644 --- a/web/app/controllers/super_manage.php +++ b/web/app/controllers/super_manage.php @@ -1,4 +1,7 @@ submit_button_config['align'] = 'compressed'; + $register_form->addInput('new_username', 'text', '用户名', '', + function ($new_username) { + if (!validateUsername($new_username)) { + return '用户名不合法'; + } + if (queryUser($new_username)) { + return '该用户已存在'; + } + return ''; + }, + null + ); + $register_form->addInput('new_password', 'password', '密码', '', + function ($new_password) { + return ''; + }, + null + ); + $register_form->addInput('new_realname', 'text', '真实姓名', '', + function ($new_realname) { + return ''; + }, + null + ); + $register_form->handle = function() { + $new_username = $_POST['new_username']; + $new_password = $_POST['new_password']; + $new_realname = $_POST['new_realname']; + $new_password = hash_hmac('md5', $new_password, getPasswordClientSalt()); + $new_password = getPasswordToStore($new_password, $new_username); + $svn_pw = uojRandString(10); + + DB::query("insert into user_info (username, realname, password, svn_password, register_time, usergroup) values ('$new_username', '$new_realname', '$new_password', '$svn_pw', now(), 'U')"); + }; + $register_form->runAtServer(); + + $change_password_form = new UOJForm('change_password'); + $change_password_form->submit_button_config['align'] = 'compressed'; + $change_password_form->addInput('p_username', 'text', '用户名', '', + function ($p_username) { + if (!validateUsername($p_username)) { + return '用户名不合法'; + } + if (!queryUser($p_username)) { + return '用户不存在'; + } + return ''; + }, + null + ); + $change_password_form->addInput('p_password', 'password', '密码', '', + function ($p_password) { + return ''; + }, + null + ); + $change_password_form->handle = function() { + $p_username = $_POST['p_username']; + $p_password = $_POST['p_password']; + $p_password = hash_hmac('md5', $p_password, getPasswordClientSalt()); + $p_password = getPasswordToStore($p_password, $p_username); + + DB::query("update user_info set password = '$p_password' where username = '$p_username'"); + }; + $change_password_form->runAtServer(); + $change_realname_form = new UOJForm('change_realname'); $change_realname_form->submit_button_config['align'] = 'compressed'; $change_realname_form->addInput('r_username', 'text', '用户名', '', @@ -53,12 +124,12 @@ 'normaluser' => '设为普通用户', 'superuser' => '设为超级用户' ); - $user_form->addSelect('op-type', $options, '操作类型', ''); + $user_form->addSelect('op_type', $options, '操作类型', ''); $user_form->handle = function() { global $user_form; $username = $_POST['username']; - switch ($_POST['op-type']) { + switch ($_POST['op_type']) { case 'banneduser': DB::update("update user_info set usergroup = 'B' where username = '{$username}'"); break; @@ -327,27 +398,48 @@ EOD; EOD; }; - $banlist_cols = array('username', 'usergroup'); - $banlist_config = array(); - $banlist_header_row = << 20, + 'table_classes' => array('table', 'table-bordered', 'table-hover', 'table-striped')); + $userlist_header_row = << 用户名 + 用户类别 + 注册时间 EOD; - $banlist_print_row = function($row) { + + $cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'users'; + + $user_list_cond = array(); + if ($cur_tab === 'users') { + if (isset($_GET['username']) && $_GET['username'] != "") { + $user_list_cond[] = "username like '%" . DB::escape($_GET['username']) . "%'"; + } + if (isset($_GET['usergroup']) && $_GET['usergroup'] != "") { + $user_list_cond[] = "usergroup = '" . DB::escape($_GET['usergroup']) . "'"; + } + } + if ($user_list_cond) { + $user_list_cond = join($user_list_cond, ' and '); + } else { + $user_list_cond = '1'; + } + + $userlist_print_row = function($row) { $hislink = getUserLink($row['username']); echo << ${hislink} + {$row['usergroup']} + {$row['register_time']} EOD; }; - - $cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'users'; - + $tabs_info = array( 'users' => array( - 'name' => '用户操作', + 'name' => '用户管理', 'url' => "/super-manage/users" ), 'blogs' => array( @@ -362,20 +454,12 @@ EOD; 'name' => '自定义测试', 'url' => '/super-manage/custom-test' ), - 'click-zan' => array( - 'name' => '点赞管理', - 'url' => '/super-manage/click-zan' - ), - 'search' => array( - 'name' => '搜索管理', - 'url' => '/super-manage/search' - ), 'judger' => array( 'name' => '评测机管理', 'url' => '/super-manage/judger' ), 'paste' => array( - 'name' => 'Paste管理', + 'name' => '剪贴板管理', 'url' => '/super-manage/paste' ) ); @@ -396,11 +480,37 @@ EOD;
+

添加新用户

+ printHTML(); ?> +

修改用户密码

+ printHTML(); ?> +

用户类别设置

printHTML(); ?>

修改用户真实姓名

printHTML(); ?> -

封禁名单

- +

用户名单

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+

添加到比赛链接

@@ -455,49 +565,6 @@ EOD; } ?> pagination() ?> - - 没写好QAQ - -

一周搜索情况

-
- - -

一月搜索情况

-
- - - idcreated_atremote_addrtypeq', - function($row) { - echo ''; - echo '', $row['id'], ''; - echo '', $row['created_at'], ''; - echo '', $row['remote_addr'], ''; - echo '', $row['type'], ''; - echo '', HTML::escape($row['q']), ''; - echo ''; - }, array( - 'page_len' => 1000 - )) - ?>

添加评测机

diff --git a/web/app/views/page-header.php b/web/app/views/page-header.php index 665dae3..cb24211 100644 --- a/web/app/views/page-header.php +++ b/web/app/views/page-header.php @@ -166,6 +166,11 @@ + + + + + @@ -246,7 +251,9 @@ + +

diff --git a/web/js/jquery.query-object.js b/web/js/jquery.query-object.js new file mode 100644 index 0000000..2046556 --- /dev/null +++ b/web/js/jquery.query-object.js @@ -0,0 +1,247 @@ +/** + * jQuery.query - Query String Modification and Creation for jQuery + * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com) + * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/). + * Date: 2009/8/13 + * + * @author Blair Mitchelmore + * @version 2.2.3 + * + **/ +new function(settings) { + // Various Settings + var $separator = settings.separator || '&'; + var $spaces = settings.spaces === false ? false : true; + var $suffix = settings.suffix === false ? '' : '[]'; + var $prefix = settings.prefix === false ? false : true; + var $hash = $prefix ? settings.hash === true ? "#" : "?" : ""; + var $numbers = settings.numbers === false ? false : true; + + jQuery.query = new function() { + var is = function(o, t) { + return o != undefined && o !== null && (!!t ? o.constructor == t : true); + }; + var parse = function(path) { + var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = []; + while (m = rx.exec(match[2])) tokens.push(m[1]); + return [base, tokens]; + }; + var set = function(target, tokens, value) { + var o, token = tokens.shift(); + if (typeof target != 'object') target = null; + if (token === "") { + if (!target) target = []; + if (is(target, Array)) { + target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value)); + } else if (is(target, Object)) { + var i = 0; + while (target[i++] != null); + target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value); + } else { + target = []; + target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value)); + } + } else if (token && token.match(/^\s*[0-9]+\s*$/)) { + var index = parseInt(token, 10); + if (!target) target = []; + target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value); + } else if (token) { + var index = token.replace(/^\s*|\s*$/g, ""); + if (!target) target = {}; + if (is(target, Array)) { + var temp = {}; + for (var i = 0; i < target.length; ++i) { + temp[i] = target[i]; + } + target = temp; + } + target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value); + } else { + return value; + } + return target; + }; + + var queryObject = function(a) { + var self = this; + self.keys = {}; + + if (a.queryObject) { + jQuery.each(a.get(), function(key, val) { + self.SET(key, val); + }); + } else { + self.parseNew.apply(self, arguments); + } + return self; + }; + + queryObject.prototype = { + queryObject: true, + parseNew: function(){ + var self = this; + self.keys = {}; + jQuery.each(arguments, function() { + var q = "" + this; + q = q.replace(/^[?#]/,''); // remove any leading ? || # + q = q.replace(/[;&]$/,''); // remove any trailing & || ; + if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces + + jQuery.each(q.split(/[&;]/), function(){ + var key = decodeURIComponent(this.split('=')[0] || ""); + var val = decodeURIComponent(this.split('=')[1] || ""); + + if (!key) return; + + if ($numbers) { + if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex + val = parseFloat(val); + else if (/^[+-]?[1-9][0-9]*$/.test(val)) // simple int regex + val = parseInt(val, 10); + } + + val = (!val && val !== 0) ? true : val; + + self.SET(key, val); + }); + }); + return self; + }, + has: function(key, type) { + var value = this.get(key); + return is(value, type); + }, + GET: function(key) { + if (!is(key)) return this.keys; + var parsed = parse(key), base = parsed[0], tokens = parsed[1]; + var target = this.keys[base]; + while (target != null && tokens.length != 0) { + target = target[tokens.shift()]; + } + return typeof target == 'number' ? target : target || ""; + }, + get: function(key) { + var target = this.GET(key); + if (is(target, Object)) + return jQuery.extend(true, {}, target); + else if (is(target, Array)) + return target.slice(0); + return target; + }, + SET: function(key, val) { + if(!key.includes("__proto__")){ + var value = !is(val) ? null : val; + var parsed = parse(key), base = parsed[0], tokens = parsed[1]; + var target = this.keys[base]; + this.keys[base] = set(target, tokens.slice(0), value); + } + return this; + }, + set: function(key, val) { + return this.copy().SET(key, val); + }, + REMOVE: function(key, val) { + if (val) { + var target = this.GET(key); + if (is(target, Array)) { + for (tval in target) { + target[tval] = target[tval].toString(); + } + var index = $.inArray(val, target); + if (index >= 0) { + key = target.splice(index, 1); + key = key[index]; + } else { + return; + } + } else if (val != target) { + return; + } + } + return this.SET(key, null).COMPACT(); + }, + remove: function(key, val) { + return this.copy().REMOVE(key, val); + }, + EMPTY: function() { + var self = this; + jQuery.each(self.keys, function(key, value) { + delete self.keys[key]; + }); + return self; + }, + load: function(url) { + var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1"); + var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1"); + return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash); + }, + empty: function() { + return this.copy().EMPTY(); + }, + copy: function() { + return new queryObject(this); + }, + COMPACT: function() { + function build(orig) { + var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig; + if (typeof orig == 'object') { + function add(o, key, value) { + if (is(o, Array)) + o.push(value); + else + o[key] = value; + } + jQuery.each(orig, function(key, value) { + if (!is(value)) return true; + add(obj, key, build(value)); + }); + } + return obj; + } + this.keys = build(this.keys); + return this; + }, + compact: function() { + return this.copy().COMPACT(); + }, + toString: function() { + var i = 0, queryString = [], chunks = [], self = this; + var encode = function(str) { + str = str + ""; + str = encodeURIComponent(str); + if ($spaces) str = str.replace(/%20/g, "+"); + return str; + }; + var addFields = function(arr, key, value) { + if (!is(value) || value === false) return; + var o = [encode(key)]; + if (value !== true) { + o.push("="); + o.push(encode(value)); + } + arr.push(o.join("")); + }; + var build = function(obj, base) { + var newKey = function(key) { + return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join(""); + }; + jQuery.each(obj, function(key, value) { + if (typeof value == 'object') + build(value, newKey(key)); + else + addFields(chunks, newKey(key), value); + }); + }; + + build(this.keys); + + if (chunks.length > 0) queryString.push($hash); + queryString.push(chunks.join($separator)); + + return queryString.join(""); + } + }; + + return new queryObject(location.search, location.hash); + }; +}(jQuery.query || {}); // Pass in jQuery.query as settings object