From a400a1cc55427d24526ac61689bb7b5a7270ae94 Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Wed, 18 Oct 2023 09:50:39 +0800 Subject: [PATCH] * Use js to login demo user. --- module/user/js/login.ui.js | 35 +++++++++++++++++++++++++++++++++++ module/user/ui/login.html.php | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/module/user/js/login.ui.js b/module/user/js/login.ui.js index b2a0059dba..d5b9a8a0e6 100644 --- a/module/user/js/login.ui.js +++ b/module/user/js/login.ui.js @@ -86,4 +86,39 @@ window.safeSubmit = function(e) return false; }; +window.demoSubmit = function($el) +{ + let account = $($el).attr('data-account'); + let password = $($el).attr('data-password'); + let link = $.createLink('user', 'login'); + let timeout = true; + let captcha = $('#captcha').length == 1 ? $('#captcha').val() : ''; + let passwordStrength = computePasswordStrength(password); + + clearTimeout(timeoutID); + timeoutID = setTimeout(function() + { + if(timeout) zui.Modal.alert(loginTimeoutTip); + }, 4000); + $.post(link, + { + "account" : account, + "password" : password, + 'passwordStrength' : passwordStrength, + 'captcha' : captcha + }, + function(data) + { + data = JSON.parse(data); + if(data.result == 'fail') + { + zui.Modal.alert(data.message); + if($('.captchaBox').length == 1) refreshCaptcha($('.captchaBox .input-group .input-group-addon img')); + return false; + } + + location.href = data.locate; + }); +} + document.getElementById("account").focus(); diff --git a/module/user/ui/login.html.php b/module/user/ui/login.html.php index ab65057798..f4721b7973 100644 --- a/module/user/ui/login.html.php +++ b/module/user/ui/login.html.php @@ -42,7 +42,7 @@ if(!empty($this->config->global->showDemoUsers)) foreach($demoUsers as $demoAccount => $demoUser) { if($demoUser->password != $md5Password) continue; - $demoUserItems[] = a(set::href($link . "account={$demoAccount}&password=" . md5($md5Password . $this->session->rand)), $demoUser->realname); + $demoUserItems[] = a(set::href('#'), set::onclick('window.demoSubmit(this)'), set('data-account', $demoAccount), set('data-password', md5($md5Password . $this->session->rand)), $demoUser->realname); } }