From f8a97f058aa4f919cd576907dc116598cbb83af7 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Wed, 23 Dec 2020 14:22:26 +0100 Subject: [PATCH 1/4] show app token in fullscreen modal --- options/locale/locale_en-US.ini | 3 +++ routers/user/setting/applications.go | 9 ++++++--- templates/user/settings/applications.tmpl | 2 ++ templates/user/settings/token_modal.tmpl | 23 +++++++++++++++++++++++ web_src/js/index.js | 10 ++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 templates/user/settings/token_modal.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d7d6b751f6a4a..fb54da3dc0f63 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -22,6 +22,7 @@ enable_javascript = This website works better with JavaScript. toc = Table of Contents licenses = Licenses return_to_gitea = Return to Gitea +copy_to_clipboard = Copy username = Username email = Email Address @@ -81,6 +82,7 @@ add = Add add_all = Add All remove = Remove remove_all = Remove All +ok = OK write = Write preview = Preview @@ -568,6 +570,7 @@ new_token_desc = Applications using a token have full access to your account. token_name = Token Name generate_token = Generate Token generate_token_success = Your new token has been generated. Copy it now as it will not be shown again. +generate_token_success_short = Token Generated generate_token_name_duplicate = %s has been used as an application name already. Please use a new one. delete_token = Delete access_token_deletion = Delete Access Token diff --git a/routers/user/setting/applications.go b/routers/user/setting/applications.go index 04f9d9f7f9b92..60a1a1f034f66 100644 --- a/routers/user/setting/applications.go +++ b/routers/user/setting/applications.go @@ -60,10 +60,13 @@ func ApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) { return } - ctx.Flash.Success(ctx.Tr("settings.generate_token_success")) - ctx.Flash.Info(t.Token) + // show alert in addition to modal for no-JS fallback + ctx.Flash.Success(ctx.Tr("settings.generate_token_success"), true) + ctx.Flash.Info(t.Token, true) - ctx.Redirect(setting.AppSubURL + "/user/settings/applications") + loadApplicationsData(ctx) + ctx.Data["Token"] = t.Token + ctx.HTML(200, tplSettingsApplications) } // DeleteApplication response for delete user access token diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index 5f5f96d4eb157..06dee24bfb0a6 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -54,6 +54,8 @@ +{{template "user/settings/token_modal" Dict "Title" "settings.generate_token_success_short" "Info" "settings.generate_token_success" "Token" .Token "i18n" .i18n}} + +{{template "user/settings/token_modal" Dict "Title" "settings.twofa_enrolled" "Info" "settings.twofa_enrolled_info" "Token" .ScratchToken "i18n" .i18n}} + {{template "base/footer" .}} From 4e1ea2f489e67c68a6f0832ea77209c0202e0eb3 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Wed, 23 Dec 2020 15:38:14 +0100 Subject: [PATCH 3/4] s/scratch token/recovery token/ this is much more common terminology. A step towards #3508 --- options/locale/locale_en-US.ini | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 82ec37dfde56a..c96a3bfcd03d6 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -31,7 +31,7 @@ access_token = Access Token re_type = Re-Type Password captcha = CAPTCHA twofa = Two-Factor Authentication -twofa_scratch = Two-Factor Scratch Code +twofa_scratch = Two-Factor Recovery Code passcode = Passcode u2f_insert_key = Insert your security key @@ -275,11 +275,11 @@ reset_password_wrong_user = You are signed in as %s, but the account recovery li password_too_short = Password length cannot be less than %d characters. non_local_account = Non-local users can not update their password through the Gitea web interface. verify = Verify -scratch_code = Scratch code -use_scratch_code = Use a scratch code -twofa_scratch_used = You have used your scratch code. You have been redirected to the two-factor settings page so you may remove your device enrollment or generate a new scratch code. -twofa_passcode_incorrect = Your passcode is incorrect. If you misplaced your device, use your scratch code to sign in. -twofa_scratch_token_incorrect = Your scratch code is incorrect. +scratch_code = Recovery code +use_scratch_code = Use a recovery code +twofa_scratch_used = You have used your recovery code, which is now no longer valid. You have been redirected to the two-factor settings page and should generate a new recovery code. +twofa_passcode_incorrect = Your passcode is incorrect. If you misplaced your device, use your recovery code to sign in. +twofa_scratch_token_incorrect = Your recovery code is incorrect. login_userpass = Sign In login_openid = OpenID oauth_signup_tab = Register New Account @@ -613,19 +613,19 @@ twofa_desc = Two-factor authentication enhances the security of your account. twofa_is_enrolled = Your account is currently enrolled in two-factor authentication. twofa_not_enrolled = Your account is not currently enrolled in two-factor authentication. twofa_disable = Disable Two-Factor Authentication -twofa_scratch_token_regenerate = Regenerate Scratch Token -twofa_scratch_token_regenerated = Your scratch token is now %s. Store it in a safe place. +twofa_scratch_token_regenerate = Regenerate Recovery Token +twofa_scratch_token_regenerated = Your new recovery token is %s. Store it in a safe place. twofa_enroll = Enroll into Two-Factor Authentication twofa_disable_note = You can disable two-factor authentication if needed. twofa_disable_desc = Disabling two-factor authentication will make your account less secure. Continue? -regenerate_scratch_token_desc = If you misplaced your scratch token or have already used it to sign in you can reset it here. +regenerate_scratch_token_desc = If you misplaced your recovery token or have already used it to sign in you can reset it here. twofa_disabled = Two-factor authentication has been disabled. scan_this_image = Scan this image with your authentication application: or_enter_secret = Or enter the secret: %s then_enter_passcode = And enter the passcode shown in the application: passcode_invalid = The passcode is incorrect. Try again. twofa_enrolled = Two-Factor Authentication Enabled -twofa_enrolled_info = Your account has been enrolled into two-factor authentication. The following scratch token can be used as fallback. Store it in a safe place, it is only shown once! +twofa_enrolled_info = Your account has been enrolled into two-factor authentication. The following recovery token can be used as fallback. Store it in a safe place, it is only shown once! u2f_desc = Security keys are hardware devices containing cryptographic keys. They can be used for two-factor authentication. Security keys must support the FIDO U2F standard. u2f_require_twofa = Your account must be enrolled in two-factor authentication to use security keys. From 711b83d777991693a5e217e9859ae1941ac3d02a Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Thu, 24 Dec 2020 08:03:05 +0100 Subject: [PATCH 4/4] non-basic modal --- templates/user/settings/token_modal.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/user/settings/token_modal.tmpl b/templates/user/settings/token_modal.tmpl index 3aae47aa7c982..0aa19078e1bcf 100644 --- a/templates/user/settings/token_modal.tmpl +++ b/templates/user/settings/token_modal.tmpl @@ -1,5 +1,5 @@ {{if .Token}} -