Redirect back to previous page after login
This commit is contained in:
@@ -142,7 +142,9 @@ namespace confighttp {
|
|||||||
|
|
||||||
auto fg = util::fail_guard([&]() {
|
auto fg = util::fail_guard([&]() {
|
||||||
if (needsRedirect) {
|
if (needsRedirect) {
|
||||||
send_redirect(response, request, "/login");
|
std::string redir_path = "/login?redir=.";
|
||||||
|
redir_path += request->path;
|
||||||
|
send_redirect(response, request, redir_path.c_str());
|
||||||
} else {
|
} else {
|
||||||
send_unauthorized(response, request);
|
send_unauthorized(response, request);
|
||||||
}
|
}
|
||||||
@@ -247,6 +249,11 @@ namespace confighttp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config::sunshine.username.empty()) {
|
||||||
|
send_redirect(response, request, "/welcome");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fetchStaticPage(response, request, "login.html", false);
|
fetchStaticPage(response, request, "login.html", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,14 @@
|
|||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
this.success = true;
|
this.success = true;
|
||||||
localStorage.setItem('login', JSON.stringify(this.passwordData));
|
localStorage.setItem('login', JSON.stringify(this.passwordData));
|
||||||
location.href = './';
|
const url = new URL(window.location);
|
||||||
|
const redirectUrl = url.searchParams.get('redir');
|
||||||
|
const hash = url.hash;
|
||||||
|
if (redirectUrl) {
|
||||||
|
location.href = redirectUrl + hash;
|
||||||
|
} else {
|
||||||
|
location.href = './' + hash;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
throw new Error('Please check your username and password')
|
throw new Error('Please check your username and password')
|
||||||
|
|||||||
Reference in New Issue
Block a user