feat(web/user/edit): github

This commit is contained in:
Baoshuo Ren 2022-10-19 22:16:10 +08:00
parent e33e3ef413
commit b433a907e5
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 18 additions and 1 deletions

View File

@ -70,6 +70,16 @@ EOD);
$vdata['qq'] = $qq;
return '';
}, null);
$update_profile_form->addVInput('github', 'text', 'GitHub', $user['github'],
function($github, &$vdata) {
if ($github && !validateGitHubUsername($github)) {
return 'GitHub 用户名不合法。';
}
$vdata['github'] = $github;
return '';
}, null);
if (isSuperUser($myUser)) {
@ -117,6 +127,7 @@ EOD);
$update_profile_form->handle = function(&$vdata) use ($user, $myUser) {
$esc_email = DB::escape($vdata['email']);
$esc_qq = DB::escape($vdata['qq']);
$esc_github = DB::escape($vdata['github']);
$esc_sex = DB::escape($vdata['sex']);
$esc_motto = DB::escape($vdata['motto']);
$esc_codeforces_handle = DB::escape($vdata['codeforces_handle']);
@ -127,7 +138,7 @@ EOD);
DB::update("UPDATE user_info SET school = '$esc_school' WHERE username = '{$user['username']}'");
}
DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle' WHERE username = '{$user['username']}'");
DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle', github = '$esc_github' WHERE username = '{$user['username']}'");
};
$update_profile_form->submit_button_config['margin_class'] = 'mt-3';
$update_profile_form->submit_button_config['text'] = '更新';

View File

@ -55,3 +55,7 @@ function validateURL($url) {
function validateString($str) {
return preg_match('/[^0-9a-zA-Z]/', $str) !== true;
}
function validateGitHubUsername($username) {
return is_string($username) && preg_match('/^[a-zA-Z0-9_-]{1,20}$/', $username);
}

View File

@ -1 +1,2 @@
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `codeforces_handle`;
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `github`;

View File

@ -1 +1,2 @@
ALTER TABLE `user_info` ADD COLUMN `codeforces_handle` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '';
ALTER TABLE `user_info` ADD COLUMN `github` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '';