mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Add endpoint to disable 2fa
This commit is contained in:
parent
79daa920e1
commit
946275c187
41 changed files with 177 additions and 40 deletions
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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?"
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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": ""
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
24
src/invidious/views/account/remove_2fa.ecr
Normal file
24
src/invidious/views/account/remove_2fa.ecr
Normal file
|
@ -0,0 +1,24 @@
|
|||
<% content_for "header" do %>
|
||||
<title><%= translate(locale, "remove-totp-header") %> - Invidious</title>
|
||||
<% end %>
|
||||
|
||||
<div class="h-box">
|
||||
<form class="pure-form pure-form-aligned" action="/remove_2fa?referer=<%= URI.encode_www_form(referer) %>" method="post">
|
||||
<legend><%= translate(locale, "remove-totp-confirm-message") %></legend>
|
||||
|
||||
<div class="pure-g">
|
||||
<div class="pure-u-1-2">
|
||||
<button type="submit" name="submit" value="remove_2fa" class="pure-button pure-button-primary">
|
||||
<%= translate(locale, "Yes") %>
|
||||
</button>
|
||||
</div>
|
||||
<div class="pure-u-1-2">
|
||||
<a class="pure-button" href="<%= URI.encode_www_form(referer) %>">
|
||||
<%= translate(locale, "No") %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="csrf_token" value="<%= URI.encode_www_form(csrf_token) %>">
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in a new issue