Commit e9cf1386 authored by Nicolas Pernoud's avatar Nicolas Pernoud
Browse files

feat: redirect to original subdomain after login

parent 1a50c137
Pipeline #5779 passed with stages
in 2 minutes and 31 seconds
......@@ -66,7 +66,7 @@ func ValidateAuthMiddleware(next http.Handler, allowedRoles []string, checkXSRF
}
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusUnauthorized)
responseContent := fmt.Sprintf("error extracting token: %v<meta http-equiv=\"Refresh\" content=\"0; url=https://%v/#login\"/>", err.Error(), redirectTo)
responseContent := fmt.Sprintf("error extracting token: %v<meta http-equiv=\"Refresh\" content=\"0; url=https://%v?redirectAfterLogin=%v#login\"/>", err.Error(), redirectTo, r.Host)
fmt.Fprintf(w, responseContent)
return
}
......
......@@ -62,14 +62,14 @@ export function mount(where) {
function registerModalFields() {
login_field = document.getElementById("login-login");
password_field = document.getElementById("login-password");
password_field.addEventListener("keyup", function(event) {
password_field.addEventListener("keyup", function (event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
doLogin();
}
});
login_inmemory = document.getElementById("login-inmemory");
login_inmemory.addEventListener("click", function() {
login_inmemory.addEventListener("click", function () {
doLogin();
});
login_icon = document.getElementById("login-icon");
......@@ -82,13 +82,19 @@ async function doLogin() {
method: "POST",
body: JSON.stringify({
login: login_field.value,
password: password_field.value
})
password: password_field.value,
}),
});
if (response.status !== 200) {
throw new Error(`Login error (status ${response.status})`);
}
await Auth.GetUser();
// Redirect to original subdomain if login was displayed after an authentication error on the original subdomain
const urlParams = new URLSearchParams(window.location.search);
const redirectAfterLogin = urlParams.get("redirectAfterLogin");
if (redirectAfterLogin != "" && redirectAfterLogin != null) {
window.location.replace("https://" + redirectAfterLogin);
}
location.hash = "#davs";
Navbar.CreateMenu();
} catch (e) {
......
......@@ -70,7 +70,7 @@
</div>
<div class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item"><p>v4.3.19</p></div>
<div class="navbar-item"><p>v4.3.20</p></div>
</div>
</div>
</nav>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment