diff options
| author | Shishkevich D. <135337715+shishkevichd@users.noreply.github.com> | 2025-05-08 17:20:58 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-08 17:20:58 +0300 |
| commit | fe3b1c9b52f584b0f045907585b206344fed55db (patch) | |
| tree | aeef0fa82a0355ee899ec3aecee23045a327a6dc /web/html/settings.html | |
| parent | d39ccf4b8f77f99d4468580085e9d89e8b5f0b1c (diff) | |
chore: implement 2fa auth (#2968)
* chore: implement 2fa auth
from #2786
* chore: format code
* chore: replace two factor token input with qr-code
* chore: requesting confirmation of setting/removing two-factor authentication
otpauth library was taken from cdnjs
* chore: revert changes in `ClipboardManager`
don't need it.
* chore: removing twoFactor prop in settings page
* chore: remove `twoFactorQr` object in `mounted` function
Diffstat (limited to 'web/html/settings.html')
| -rw-r--r-- | web/html/settings.html | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/web/html/settings.html b/web/html/settings.html index 82e636d9..dec40de7 100644 --- a/web/html/settings.html +++ b/web/html/settings.html @@ -122,10 +122,13 @@ </a-layout> </a-layout> {{template "js" .}} +<script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script> +<script src="{{ .base_path }}assets/otpauth/otpauth.umd.min.js?{{ .cur_ver }}"></script> <script src="{{ .base_path }}assets/js/model/setting.js?{{ .cur_ver }}"></script> {{template "component/aSidebar" .}} {{template "component/aThemeSwitch" .}} {{template "component/aSettingListItem" .}} +{{template "modals/twoFactorModal"}} <script> const app = new Vue({ delimiters: ['[[', ']]'], @@ -133,7 +136,6 @@ data: { themeSwitcher, spinning: false, - changeSecret: false, oldAllSetting: new AllSetting(), allSetting: new AllSetting(), saveBtnDisable: true, @@ -258,7 +260,6 @@ app.changeRemarkSample(); this.saveBtnDisable = true; } - await this.fetchUserSecret(); }, async updateAllSetting() { this.loading(true); @@ -302,38 +303,34 @@ window.location.replace(url); } }, - async fetchUserSecret() { - this.loading(true); - const userMessage = await HttpUtil.post("/panel/setting/getUserSecret", this.user); - if (userMessage.success) { - this.user = userMessage.obj; - } - this.loading(false); - }, - async updateSecret() { - this.loading(true); - const msg = await HttpUtil.post("/panel/setting/updateUserSecret", this.user); - if (msg && msg.obj) { - this.user = msg.obj; - } - this.loading(false); - await this.updateAllSetting(); - }, - async getNewSecret() { - if (!this.changeSecret) { - this.changeSecret = true; - this.user.loginSecret = ''; - const newSecret = RandomUtil.randomSeq(64); - await PromiseUtil.sleep(1000); - this.user.loginSecret = newSecret; - this.changeSecret = false; - } - }, - async toggleToken(value) { - if (value) { - await this.getNewSecret(); + toggleTwoFactor(newValue) { + if (newValue) { + const newTwoFactorToken = RandomUtil.randomBase32String() + + twoFactorModal.show({ + title: '{{ i18n "pages.settings.security.twoFactorModalSetTitle" }}', + token: newTwoFactorToken, + type: 'set', + confirm: (success) => { + if (success) { + this.allSetting.twoFactorToken = newTwoFactorToken + } + + this.allSetting.twoFactorEnable = success + } + }) } else { - this.user.loginSecret = ""; + twoFactorModal.show({ + title: '{{ i18n "pages.settings.security.twoFactorModalDeleteTitle" }}', + token: this.allSetting.twoFactorToken, + type: 'remove', + confirm: (success) => { + if (success) { + this.allSetting.twoFactorEnable = false + this.allSetting.twoFactorToken = "" + } + } + }) } }, addNoise() { @@ -526,6 +523,7 @@ }, async mounted() { await this.getAllSetting(); + while (true) { await PromiseUtil.sleep(1000); this.saveBtnDisable = this.oldAllSetting.equals(this.allSetting); |
