diff --git a/locales/ar.json b/locales/ar.json index e371daac..55dc3dcf 100644 --- a/locales/ar.json +++ b/locales/ar.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/bn_BD.json b/locales/bn_BD.json index bc92b927..b43fe551 100644 --- a/locales/bn_BD.json +++ b/locales/bn_BD.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/cs.json b/locales/cs.json index f759f167..11f68f0e 100644 --- a/locales/cs.json +++ b/locales/cs.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/da.json b/locales/da.json index e20b3ac5..5f541ed9 100644 --- a/locales/da.json +++ b/locales/da.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/de.json b/locales/de.json index 0758e3f8..4fbd540a 100644 --- a/locales/de.json +++ b/locales/de.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/el.json b/locales/el.json index b951e3f4..8a07ea87 100644 --- a/locales/el.json +++ b/locales/el.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/en-US.json b/locales/en-US.json index eb838fc1..34b7417b 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "The TOTP code entered is invalid", "general-totp-enter-code-field": "6 digit number", "general-totp-enter-code-header": "Two-factor authentication", - "general-totp-verify-button": "Verifiy" + "general-totp-verify-button": "Verify", + "remove-totp-header": "Remove two-factor authentication", + "remove-totp-confirm-message": "Are you sure you would like to remove two-factor-authentication?" } diff --git a/locales/eo.json b/locales/eo.json index ed7e2284..294fc29d 100644 --- a/locales/eo.json +++ b/locales/eo.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/es.json b/locales/es.json index 37c9cc6b..e03e1ffa 100644 --- a/locales/es.json +++ b/locales/es.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/eu.json b/locales/eu.json index f29e8892..0c8bfcc6 100644 --- a/locales/eu.json +++ b/locales/eu.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/fa.json b/locales/fa.json index 15cff988..3c69baa6 100644 --- a/locales/fa.json +++ b/locales/fa.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/fi.json b/locales/fi.json index 86d7093e..dd9b5168 100644 --- a/locales/fi.json +++ b/locales/fi.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/fr.json b/locales/fr.json index 1568748f..15aa696f 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/he.json b/locales/he.json index 990ab51f..4020e8b8 100644 --- a/locales/he.json +++ b/locales/he.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/hr.json b/locales/hr.json index cc3c4dd2..6169f763 100644 --- a/locales/hr.json +++ b/locales/hr.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/hu-HU.json b/locales/hu-HU.json index ae9fcad8..d61ec36c 100644 --- a/locales/hu-HU.json +++ b/locales/hu-HU.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/id.json b/locales/id.json index 59729272..e26eff28 100644 --- a/locales/id.json +++ b/locales/id.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/is.json b/locales/is.json index d059bb37..020d8edf 100644 --- a/locales/is.json +++ b/locales/is.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/it.json b/locales/it.json index f871b27b..1a4ec353 100644 --- a/locales/it.json +++ b/locales/it.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/ja.json b/locales/ja.json index b20175e8..57d99ce3 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/lt.json b/locales/lt.json index 657db3ec..eaa0ee6e 100644 --- a/locales/lt.json +++ b/locales/lt.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/nb-NO.json b/locales/nb-NO.json index c839241a..6f1a03eb 100644 --- a/locales/nb-NO.json +++ b/locales/nb-NO.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/nl.json b/locales/nl.json index e32e964a..28cb65ad 100644 --- a/locales/nl.json +++ b/locales/nl.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/pl.json b/locales/pl.json index 61a0f3bf..f6b52676 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/pt-BR.json b/locales/pt-BR.json index 27c37aca..396b1736 100644 --- a/locales/pt-BR.json +++ b/locales/pt-BR.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/pt-PT.json b/locales/pt-PT.json index fa047259..79170a71 100644 --- a/locales/pt-PT.json +++ b/locales/pt-PT.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/ro.json b/locales/ro.json index 5b44dbbf..7540258c 100644 --- a/locales/ro.json +++ b/locales/ro.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/ru.json b/locales/ru.json index f5d8ba6f..a21fe658 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/si.json b/locales/si.json index ba6f84f6..17154057 100644 --- a/locales/si.json +++ b/locales/si.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/sk.json b/locales/sk.json index 3f5a9b2d..e3ba0409 100644 --- a/locales/sk.json +++ b/locales/sk.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/sr.json b/locales/sr.json index a21142d5..7585e363 100644 --- a/locales/sr.json +++ b/locales/sr.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/sr_Cyrl.json b/locales/sr_Cyrl.json index f76b1219..02819246 100644 --- a/locales/sr_Cyrl.json +++ b/locales/sr_Cyrl.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/sv-SE.json b/locales/sv-SE.json index fb138b8e..043ed21d 100644 --- a/locales/sv-SE.json +++ b/locales/sv-SE.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/tr.json b/locales/tr.json index f4c01d68..75199f0d 100644 --- a/locales/tr.json +++ b/locales/tr.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/uk.json b/locales/uk.json index a3cbc55a..c2095477 100644 --- a/locales/uk.json +++ b/locales/uk.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/vi.json b/locales/vi.json index 1783acb2..ab5b515f 100644 --- a/locales/vi.json +++ b/locales/vi.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/zh-CN.json b/locales/zh-CN.json index 68ffa289..0fba5483 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/locales/zh-TW.json b/locales/zh-TW.json index c647cf24..2deb3280 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -433,5 +433,7 @@ "general-totp-invalid-code": "", "general-totp-enter-code-field": "", "general-totp-enter-code-header": "", - "general-totp-verify-button": "" + "general-totp-verify-button": "", + "remove-totp-header": "", + "remove-totp-confirm-message": "" } diff --git a/src/invidious.cr b/src/invidious.cr index d3e8c9f8..5edec97b 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -347,6 +347,8 @@ Invidious::Routing.get "/toggle_theme", Invidious::Routes::PreferencesRoute, :to Invidious::Routing.get "/setup_2fa", Invidious::Routes::Accounts, :setup_2fa_page Invidious::Routing.post "/setup_2fa", Invidious::Routes::Accounts, :setup_2fa +Invidious::Routing.get "/remove_2fa", Invidious::Routes::Accounts, :remove_2fa_page +Invidious::Routing.post "/remove_2fa", Invidious::Routes::Accounts, :remove_2fa Invidious::Routing.post "/validate_2fa", Invidious::Routes::Accounts, :validate_2fa # Users diff --git a/src/invidious/routes/accounts.cr b/src/invidious/routes/accounts.cr index 1715bd76..f8728035 100644 --- a/src/invidious/routes/accounts.cr +++ b/src/invidious/routes/accounts.cr @@ -21,6 +21,43 @@ class Invidious::Routes::Accounts < Invidious::Routes::BaseRoute return templated "account/setup_2fa" end + # Endpoint to remove 2fa + def remove_2fa_page(env) + locale = LOCALES[env.get("preferences").as(Preferences).locale]? + referer = get_referer(env) + + user = env.get("user").as(User) + sid = env.get("sid").as(String) + csrf_token = generate_response(sid, {":remove_2fa"}, HMAC_KEY, PG_DB) + + return templated "account/remove_2fa" + end + + # Remove 2fa post request. + def remove_2fa(env) + locale = LOCALES[env.get("preferences").as(Preferences).locale]? + + user = env.get? "user" + sid = env.get? "sid" + referer = get_referer(env, unroll: false) + + if !user + return env.redirect referer + end + + user = user.as(User) + sid = sid.as(String) + token = env.params.body["csrf_token"]? + + begin + validate_request(token, sid, env.request, HMAC_KEY, PG_DB, locale) + rescue ex + return error_template(400, ex) + end + + PG_DB.exec("UPDATE users SET totp_secret = $1 WHERE email = $2", nil, user.email) + end + # Setup TOTP (post) request. def setup_2fa(env) locale = LOCALES[env.get("preferences").as(Preferences).locale]? @@ -29,8 +66,6 @@ class Invidious::Routes::Accounts < Invidious::Routes::BaseRoute sid = env.get? "sid" referer = get_referer(env, unroll: false) - puts referer - if !user return env.redirect referer end diff --git a/src/invidious/views/account/remove_2fa.ecr b/src/invidious/views/account/remove_2fa.ecr new file mode 100644 index 00000000..47f92263 --- /dev/null +++ b/src/invidious/views/account/remove_2fa.ecr @@ -0,0 +1,24 @@ +<% content_for "header" do %> +<%= translate(locale, "remove-totp-header") %> - Invidious +<% end %> + +
+
+ <%= translate(locale, "remove-totp-confirm-message") %> + +
+
+ +
+ +
+ + +
+