mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 17:28:41 +00:00
refactor(super_manage/users): uoj_form_v2
This commit is contained in:
parent
e28f8d97b4
commit
33c8b6bd4a
@ -317,13 +317,10 @@ if ($cur_tab == 'index') {
|
|||||||
$user_list_cond = '1';
|
$user_list_cond = '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
$register_form = new UOJBs4Form('register');
|
$register_form = new UOJForm('register');
|
||||||
$register_form->addVInput(
|
$register_form->addInput('new_username', [
|
||||||
'new_username',
|
'label' => '用户名',
|
||||||
'text',
|
'validator_php' => function ($username, &$vdata) {
|
||||||
'用户名',
|
|
||||||
'',
|
|
||||||
function ($username, &$vdata) {
|
|
||||||
if (!validateUsername($username)) {
|
if (!validateUsername($username)) {
|
||||||
return '用户名不合法';
|
return '用户名不合法';
|
||||||
}
|
}
|
||||||
@ -336,27 +333,24 @@ if ($cur_tab == 'index') {
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_form->addInput('new_password', [
|
||||||
$register_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_password',
|
'type' => 'password',
|
||||||
'password',
|
'label' => '密码',
|
||||||
'密码',
|
'validator_php' => function ($password, &$vdata) {
|
||||||
'',
|
|
||||||
function ($password, &$vdata) {
|
|
||||||
$vdata['password'] = $password;
|
$vdata['password'] = $password;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'validatePassword'
|
'validator_js' => 'validatePassword',
|
||||||
);
|
]);
|
||||||
$register_form->addVInput(
|
$register_form->addInput('new_email', [
|
||||||
'new_email',
|
'div_class' => 'mt-3',
|
||||||
'text',
|
'label' => '电子邮件',
|
||||||
'电子邮件(选填)',
|
'help' => '选填项。填写电子邮件后用户可自主进行密码重置。',
|
||||||
'',
|
'validator_php' => function ($email, &$vdata) {
|
||||||
function ($email, &$vdata) {
|
if (!validateEmail($email)) {
|
||||||
if ($email && !validateEmail($email)) {
|
|
||||||
return '邮件地址不合法';
|
return '邮件地址不合法';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,32 +358,27 @@ if ($cur_tab == 'index') {
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_form->addInput('new_realname', [
|
||||||
$register_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_realname',
|
'label' => '真实姓名',
|
||||||
'text',
|
'help' => '选填项。',
|
||||||
'真实姓名(选填)',
|
'validator_php' => function ($realname, &$vdata) {
|
||||||
'',
|
|
||||||
function ($realname, &$vdata) {
|
|
||||||
$vdata['realname'] = $realname;
|
$vdata['realname'] = $realname;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_form->addInput('new_school', [
|
||||||
$register_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_school',
|
'label' => '学校名称',
|
||||||
'text',
|
'help' => '选填项。常用名称:<code>石家庄市第二中学</code>、<code>石家庄二中实验学校</code>。',
|
||||||
'学校名称(选填)',
|
'validator_php' => function ($school, &$vdata) {
|
||||||
'',
|
|
||||||
function ($school, &$vdata) {
|
|
||||||
$vdata['school'] = $school;
|
$vdata['school'] = $school;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
|
||||||
$register_form->handle = function (&$vdata) {
|
$register_form->handle = function (&$vdata) {
|
||||||
$user = [
|
$user = [
|
||||||
'username' => $vdata['username'],
|
'username' => $vdata['username'],
|
||||||
@ -421,16 +410,13 @@ if ($cur_tab == 'index') {
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
EOD);
|
EOD);
|
||||||
$register_form->runAtServer();
|
$register_form->runAtServer();
|
||||||
|
|
||||||
$register_tmp_user_form = new UOJBs4Form('register_tmp_user');
|
$register_tmp_user_form = new UOJForm('register_tmp_user');
|
||||||
$register_tmp_user_form->addVInput(
|
$register_tmp_user_form->addInput('new_tmp_username', [
|
||||||
'new_tmp_username',
|
'label' => '用户名',
|
||||||
'text',
|
'validator_php' => function ($username, &$vdata) {
|
||||||
'用户名',
|
|
||||||
'',
|
|
||||||
function ($username, &$vdata) {
|
|
||||||
if (!validateUsername($username)) {
|
if (!validateUsername($username)) {
|
||||||
return '用户名不合法';
|
return '用户名不合法';
|
||||||
}
|
}
|
||||||
@ -443,26 +429,23 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_tmp_user_form->addInput('new_tmp_password', [
|
||||||
$register_tmp_user_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_tmp_password',
|
'type' => 'password',
|
||||||
'password',
|
'label' => '密码',
|
||||||
'密码',
|
'validator_php' => function ($password, &$vdata) {
|
||||||
'',
|
|
||||||
function ($password, &$vdata) {
|
|
||||||
$vdata['password'] = $password;
|
$vdata['password'] = $password;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'validatePassword'
|
'validator_js' => 'validatePassword',
|
||||||
);
|
]);
|
||||||
$register_tmp_user_form->addVInput(
|
$register_tmp_user_form->addInput('new_tmp_email', [
|
||||||
'new_tmp_email',
|
'div_class' => 'mt-3',
|
||||||
'text',
|
'label' => '电子邮件',
|
||||||
'电子邮件(选填)',
|
'help' => '选填项。',
|
||||||
'',
|
'validator_php' => function ($email, &$vdata) {
|
||||||
function ($email, &$vdata) {
|
|
||||||
if ($email && !validateEmail($email)) {
|
if ($email && !validateEmail($email)) {
|
||||||
return '邮件地址不合法';
|
return '邮件地址不合法';
|
||||||
}
|
}
|
||||||
@ -471,48 +454,42 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_tmp_user_form->addInput('new_tmp_realname', [
|
||||||
$register_tmp_user_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_tmp_realname',
|
'label' => '真实姓名',
|
||||||
'text',
|
'help' => '选填项。',
|
||||||
'真实姓名(选填)',
|
'validator_php' => function ($realname, &$vdata) {
|
||||||
'',
|
|
||||||
function ($realname, &$vdata) {
|
|
||||||
$vdata['realname'] = $realname;
|
$vdata['realname'] = $realname;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_tmp_user_form->addInput('new_tmp_school', [
|
||||||
$register_tmp_user_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_tmp_school',
|
'label' => '学校名称',
|
||||||
'text',
|
'help' => '选填项。',
|
||||||
'学校名称(选填)',
|
'validator_php' => function ($school, &$vdata) {
|
||||||
'',
|
|
||||||
function ($school, &$vdata) {
|
|
||||||
$vdata['school'] = $school;
|
$vdata['school'] = $school;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$register_tmp_user_form->addInput('new_tmp_expiration_time', [
|
||||||
$register_tmp_user_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'new_tmp_expiration_time',
|
'label' => '过期时间',
|
||||||
'text',
|
'help' => '选填项。默认过期时间为 7 天后。',
|
||||||
'过期时间',
|
'default_value' => UOJTime::time2str((new DateTime())->add(new DateInterval('P7D'))->setTime(0, 0, 0)),
|
||||||
UOJTime::time2str((new DateTime())->add(new DateInterval('P7D'))->setTime(0, 0, 0)),
|
'validator_php' => function ($expiration_time, &$vdata) {
|
||||||
function ($str, &$vdata) {
|
|
||||||
try {
|
try {
|
||||||
$vdata['expiration_time'] = new DateTime($str);
|
$vdata['expiration_time'] = new DateTime($expiration_time);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return '无效时间格式';
|
return '无效时间格式';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
|
||||||
$register_tmp_user_form->handle = function (&$vdata) {
|
$register_tmp_user_form->handle = function (&$vdata) {
|
||||||
$user = [
|
$user = [
|
||||||
'username' => $vdata['username'],
|
'username' => $vdata['username'],
|
||||||
@ -545,15 +522,13 @@ EOD);
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
EOD);
|
EOD);
|
||||||
$register_tmp_user_form->runAtServer();
|
$register_tmp_user_form->runAtServer();
|
||||||
|
|
||||||
$change_password_form = new UOJBs4Form('change_password');
|
$change_password_form = new UOJForm('change_password');
|
||||||
$change_password_form->addVInput(
|
$change_password_form->addInput('p_username', [
|
||||||
'p_username',
|
'label' => '用户名',
|
||||||
'text',
|
'validator_php' =>
|
||||||
'用户名',
|
|
||||||
'',
|
|
||||||
function ($username, &$vdata) {
|
function ($username, &$vdata) {
|
||||||
if (!validateUsername($username)) {
|
if (!validateUsername($username)) {
|
||||||
return '用户名不合法';
|
return '用户名不合法';
|
||||||
@ -567,20 +542,18 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$change_password_form->addInput('p_password', [
|
||||||
$change_password_form->addVInput(
|
'div_class' => 'mt-3',
|
||||||
'p_password',
|
'type' => 'password',
|
||||||
'password',
|
'label' => '密码',
|
||||||
'密码',
|
'validator_php' => function ($password, &$vdata) {
|
||||||
'',
|
|
||||||
function ($password, &$vdata) {
|
|
||||||
$vdata['password'] = $password;
|
$vdata['password'] = $password;
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'validatePassword'
|
'validator_js' => 'validatePassword',
|
||||||
);
|
]);
|
||||||
$change_password_form->handle = function (&$vdata) {
|
$change_password_form->handle = function (&$vdata) {
|
||||||
$password = hash_hmac('md5', $vdata['password'], getPasswordClientSalt());
|
$password = hash_hmac('md5', $vdata['password'], getPasswordClientSalt());
|
||||||
|
|
||||||
@ -596,8 +569,9 @@ EOD);
|
|||||||
|
|
||||||
dieWithJsonData(['status' => 'success', 'message' => '用户 ' . $vdata['username'] . ' 的密码已经被成功重置。']);
|
dieWithJsonData(['status' => 'success', 'message' => '用户 ' . $vdata['username'] . ' 的密码已经被成功重置。']);
|
||||||
};
|
};
|
||||||
$change_password_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
$change_password_form->config['submit_button']['class'] = 'btn btn-secondary';
|
||||||
$change_password_form->submit_button_config['text'] = '重置';
|
$change_password_form->config['submit_button']['text'] = '重置密码';
|
||||||
|
$change_password_form->config['confirm']['smart'] = true;
|
||||||
$change_password_form->setAjaxSubmit(<<<EOD
|
$change_password_form->setAjaxSubmit(<<<EOD
|
||||||
function(res) {
|
function(res) {
|
||||||
if (res.status === 'success') {
|
if (res.status === 'success') {
|
||||||
@ -616,16 +590,13 @@ EOD);
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
EOD);
|
EOD);
|
||||||
$change_password_form->runAtServer();
|
$change_password_form->runAtServer();
|
||||||
|
|
||||||
$change_usergroup_form = new UOJBs4Form('change_usergroup');
|
$change_usergroup_form = new UOJForm('change_usergroup');
|
||||||
$change_usergroup_form->addVInput(
|
$change_usergroup_form->addInput('username', [
|
||||||
'username',
|
'label' => '用户名',
|
||||||
'text',
|
'validator_php' => function ($username, &$vdata) {
|
||||||
'用户名',
|
|
||||||
'',
|
|
||||||
function ($username, &$vdata) {
|
|
||||||
if (!validateUsername($username)) {
|
if (!validateUsername($username)) {
|
||||||
return '用户名不合法';
|
return '用户名不合法';
|
||||||
}
|
}
|
||||||
@ -638,14 +609,17 @@ EOD);
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
null
|
]);
|
||||||
);
|
$change_usergroup_form->addSelect('op_type', [
|
||||||
$change_usergroup_form->addVSelect('op_type', [
|
'div_class' => 'mt-3',
|
||||||
'banneduser' => '设为封禁用户',
|
'label' => '操作类型',
|
||||||
'tempuser' => '设为临时用户',
|
'options' => [
|
||||||
'normaluser' => '设为普通用户',
|
'banneduser' => '设为封禁用户',
|
||||||
'superuser' => '设为超级用户',
|
'tempuser' => '设为临时用户',
|
||||||
], '操作类型', '');
|
'normaluser' => '设为普通用户',
|
||||||
|
'superuser' => '设为超级用户',
|
||||||
|
],
|
||||||
|
]);
|
||||||
$change_usergroup_form->handle = function ($vdata) {
|
$change_usergroup_form->handle = function ($vdata) {
|
||||||
$username = $vdata['username'];
|
$username = $vdata['username'];
|
||||||
$usergroup = '';
|
$usergroup = '';
|
||||||
@ -664,7 +638,9 @@ EOD);
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$usergroup = '被封禁的用户,该用户将无法再次登录系统';
|
$usergroup = '被封禁的用户,该用户将无法再次登录系统';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'tempuser':
|
case 'tempuser':
|
||||||
DB::update([
|
DB::update([
|
||||||
"update user_info",
|
"update user_info",
|
||||||
@ -678,7 +654,9 @@ EOD);
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$usergroup = '临时用户,请前往个人信息编辑页面修改过期时间';
|
$usergroup = '临时用户,请前往个人信息编辑页面修改过期时间';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'normaluser':
|
case 'normaluser':
|
||||||
DB::update([
|
DB::update([
|
||||||
"update user_info",
|
"update user_info",
|
||||||
@ -692,6 +670,7 @@ EOD);
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$usergroup = '普通用户';
|
$usergroup = '普通用户';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'superuser':
|
case 'superuser':
|
||||||
DB::update([
|
DB::update([
|
||||||
@ -705,7 +684,9 @@ EOD);
|
|||||||
"username" => $username,
|
"username" => $username,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$usergroup = '超级用户';
|
$usergroup = '超级用户';
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,7 +710,7 @@ EOD);
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
EOD);
|
EOD);
|
||||||
$change_usergroup_form->runAtServer();
|
$change_usergroup_form->runAtServer();
|
||||||
|
|
||||||
$users_default_permissions = UOJContext::getMeta('users_default_permissions');
|
$users_default_permissions = UOJContext::getMeta('users_default_permissions');
|
||||||
@ -888,7 +869,7 @@ EOD);
|
|||||||
|
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
EOD);
|
EOD);
|
||||||
$update_users_default_permissions_form->config['confirm']['text'] = '你确定要修改所有用户的默认权限吗?';
|
$update_users_default_permissions_form->config['confirm']['text'] = '你确定要修改所有用户的默认权限吗?';
|
||||||
$update_users_default_permissions_form->handle = function () {
|
$update_users_default_permissions_form->handle = function () {
|
||||||
$new_permissions = [
|
$new_permissions = [
|
||||||
|
Loading…
Reference in New Issue
Block a user