mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
core: allow switch account
This commit is contained in:
1 parent
7ca2881787
commit
89424ec9cd
7 files changed
+71
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.1.13",
|
||||
"version": "3.1.14",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -115,10 +115,19 @@ export class FSDownloadHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
export class SwitchAccountHandler extends Handler {
|
||||
@param('uid', Types.Int)
|
||||
async get(domainId: string, uid: number) {
|
||||
this.session.uid = uid;
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply() {
|
||||
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
||||
Route('home_files', '/file', FilesHandler, PRIV.PRIV_CREATE_FILE);
|
||||
Route('fs_download', '/file/:uid/:filename', FSDownloadHandler);
|
||||
Route('switch_account', '/account', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM);
|
||||
}
|
||||
|
||||
global.Hydro.handler.misc = apply;
|
||||
@@ -1,7 +1,12 @@
|
||||
import Slideout from 'slideout';
|
||||
|
||||
import { AutoloadPage } from 'vj/misc/Page';
|
||||
import createHint from 'vj/components/hint';
|
||||
import tpl from 'vj/utils/tpl';
|
||||
import i18n from 'vj/utils/i18n';
|
||||
import request from 'vj/utils/request';
|
||||
import { ActionDialog } from 'vj/components/dialog';
|
||||
import Notification from 'vj/components/notification';
|
||||
import UserSelectAutoComplete from 'vj/components/autocomplete/UserSelectAutoComplete';
|
||||
import { AutoloadPage } from 'vj/misc/Page';
|
||||
|
||||
function handleNavLogoutClick(ev) {
|
||||
const $logoutLink = $(ev.currentTarget);
|
||||
@@ -10,11 +15,54 @@ function handleNavLogoutClick(ev) {
|
||||
.then(() => window.location.reload());
|
||||
ev.preventDefault();
|
||||
}
|
||||
function handlerSwitchAccount(ev) {
|
||||
let userSelector;
|
||||
const promise = new ActionDialog({
|
||||
$body: tpl`
|
||||
<div>
|
||||
<div class="row"><div class="columns">
|
||||
<h1 name="select_user_text">${i18n('Select User')}</h1>
|
||||
</div></div>
|
||||
<div class="row">
|
||||
<div class="columns">
|
||||
<label>
|
||||
${i18n('Username / UID')}
|
||||
<input name="switch_account_target" type="text" class="textbox" autocomplete="off" data-autofocus>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
onDispatch(action) {
|
||||
console.log(action, userSelector.value());
|
||||
if (action === 'ok' && userSelector.value() === null) {
|
||||
userSelector.focus();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
}).open();
|
||||
userSelector = UserSelectAutoComplete.getOrConstruct($('[name="switch_account_target"]'));
|
||||
createHint('Hint::icon::switch_account', $('[name="select_user_text"]'));
|
||||
promise.then(async (action) => {
|
||||
if (action !== 'ok') return;
|
||||
const target = userSelector.value();
|
||||
if (!target) return;
|
||||
try {
|
||||
await request.get('/account', { uid: target._id });
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
Notification.error(error.message);
|
||||
}
|
||||
});
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const navigationPage = new AutoloadPage('navigationPage', () => {
|
||||
if (!document.getElementById('panel') || !document.getElementById('menu')) return;
|
||||
|
||||
$(document).on('click', '[name="nav_logout"]', handleNavLogoutClick);
|
||||
$(document).on('click', '[name="nav_switch_account"]', handlerSwitchAccount);
|
||||
|
||||
const slideout = new Slideout({
|
||||
panel: document.getElementById('panel'),
|
||||
|
||||
@@ -3,6 +3,7 @@ Can be Extended For: Extension
|
||||
Current Status: Status
|
||||
Handled Requests: Req
|
||||
Hint::icon::difficulty: The difficulty of the problems in Hydro will be calculated by algorithm, depending on current submission, sometimes the difficulty may not so exact.
|
||||
Hint::icon::switch_account: As a superadmin, you can switch to anyone's account.
|
||||
manage: System Manage
|
||||
no_translation_warn: <blockquote class="warn">This part of content is under translation.</blockquote>
|
||||
page.problem_detail.sidebar.show_category: Click to Show
|
||||
|
||||
@@ -341,6 +341,7 @@ Highlight discussions: 高亮讨论
|
||||
Highlight: 高亮
|
||||
Hint: 提示
|
||||
Hint::icon::difficulty: Hydro 中题目的难度,根据递交数、通过率以及每个递交的递交时间和评测结果,综合计算得出,可能不准确。
|
||||
Hint::icon::switch_account: 作为超级管理员,您可以直接切换到其他人的账户。
|
||||
Hint::icon::testdata: <a href="https://hydro.js.org/docs/user/testdata/" target="_blank">请参照文档说明</a>
|
||||
Hint::page::main: 欢迎来到 Hydro! 您可在右上角注册或登录。此类提示仅会显示一次。
|
||||
Hint::page::problem_detail: 这是题目详情页面。您可点击右侧“进入在线编程模式"开始编写您的代码。
|
||||
@@ -728,6 +729,7 @@ Submit: 递交
|
||||
Submitted: 已递交
|
||||
SuperUser: 超级管理员
|
||||
Support: 支持
|
||||
Switch account: 切换账户
|
||||
Tags: 标签
|
||||
tasks_list: 任务列表
|
||||
Technical Information: 技术信息
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.26.7",
|
||||
"version": "4.26.8",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -79,6 +79,13 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="menu__seperator"></li>
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM) %}
|
||||
<li class="menu__item nojs--hide">
|
||||
<a class="menu__link" name="nav_switch_account">
|
||||
<span class="icon icon-user"></span> {{ _('Switch account') }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="menu__item">
|
||||
<a href="{{ url('user_logout') }}" class="menu__link" name="nav_logout">
|
||||
<span class="icon icon-logout"></span> {{ _('Logout') }}
|
||||
|
||||
Reference in new issue
Block a user