mirror of https://github.com/calzoneman/sync.git
Fix cross-domain cookie issue
This commit is contained in:
parent
ced68d9304
commit
93d5980f05
|
@ -15,6 +15,9 @@ http:
|
||||||
host: ''
|
host: ''
|
||||||
port: 8080
|
port: 8080
|
||||||
domain: 'http://localhost'
|
domain: 'http://localhost'
|
||||||
|
# Specifies the root domain for cookies. If you have multiple domains
|
||||||
|
# e.g. a.example.com and b.example.com, the root domain is example.com
|
||||||
|
root-domain: 'localhost'
|
||||||
# Use express-minify to minify CSS and Javascript
|
# Use express-minify to minify CSS and Javascript
|
||||||
minify: false
|
minify: false
|
||||||
# Static content cache (in seconds)
|
# Static content cache (in seconds)
|
||||||
|
|
|
@ -26,6 +26,7 @@ var defaults = {
|
||||||
host: "",
|
host: "",
|
||||||
port: 8080,
|
port: 8080,
|
||||||
domain: "http://localhost",
|
domain: "http://localhost",
|
||||||
|
"root-domain": "localhost",
|
||||||
minify: false,
|
minify: false,
|
||||||
"cache-ttl": 0
|
"cache-ttl": 0
|
||||||
},
|
},
|
||||||
|
|
|
@ -106,6 +106,7 @@ function handleLoginPage(req, res) {
|
||||||
*/
|
*/
|
||||||
function handleLogout(req, res) {
|
function handleLogout(req, res) {
|
||||||
res.clearCookie("auth");
|
res.clearCookie("auth");
|
||||||
|
res.clearCookie("auth", { domain: Config.get("http.root-domain") });
|
||||||
// Try to find an appropriate redirect
|
// Try to find an appropriate redirect
|
||||||
var ref = req.header("referrer");
|
var ref = req.header("referrer");
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
|
|
|
@ -13,7 +13,9 @@ function merge(locals) {
|
||||||
var _locals = {
|
var _locals = {
|
||||||
siteTitle: Config.get("html-template.title"),
|
siteTitle: Config.get("html-template.title"),
|
||||||
siteDescription: Config.get("html-template.description"),
|
siteDescription: Config.get("html-template.description"),
|
||||||
siteAuthor: "Calvin 'calzoneman' 'cyzon' Montgomery"
|
siteAuthor: "Calvin 'calzoneman' 'cyzon' Montgomery",
|
||||||
|
loginDomain: Config.get("https.enabled") ? Config.get("https.domain")+":"+Config.get("https.port")
|
||||||
|
: Config.get("http.domain")+":"+Config.get("http.port")
|
||||||
};
|
};
|
||||||
if (typeof locals !== "object") {
|
if (typeof locals !== "object") {
|
||||||
return _locals;
|
return _locals;
|
||||||
|
|
|
@ -64,12 +64,13 @@ function logRequest(req, status) {
|
||||||
|
|
||||||
function cookieall(res, name, val, opts) {
|
function cookieall(res, name, val, opts) {
|
||||||
res.cookie(name, val, opts);
|
res.cookie(name, val, opts);
|
||||||
opts.domain = Config.get("http.domain");
|
|
||||||
res.cookie(name, val, opts);
|
opts.domain = Config.get("http.root-domain");
|
||||||
if (Config.get("https.enabled")) {
|
if (Config.get("http.domain").indexOf(opts.domain) === -1) {
|
||||||
opts.domain = Config.get("https.domain");
|
opts.domain = Config.get("http.domain");
|
||||||
res.cookie(name, val, opts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.cookie(name, val, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,9 @@ mixin navloginlogout(redirect)
|
||||||
|
|
||||||
mixin navloginform(redirect)
|
mixin navloginform(redirect)
|
||||||
.visible-md.visible-lg
|
.visible-md.visible-lg
|
||||||
form#loginform.navbar-form.navbar-right(action="/login", method="post")
|
if loginDomain == null
|
||||||
|
- loginDomain = ""
|
||||||
|
form#loginform.navbar-form.navbar-right(action="#{loginDomain}/login", method="post")
|
||||||
input(type="hidden", name="redirect", value=redirect)
|
input(type="hidden", name="redirect", value=redirect)
|
||||||
.form-group
|
.form-group
|
||||||
input#username.form-control(type="text", name="name", placeholder="Username")
|
input#username.form-control(type="text", name="name", placeholder="Username")
|
||||||
|
|
|
@ -445,6 +445,20 @@ Callbacks = {
|
||||||
|
|
||||||
if (!CLIENT.guest) {
|
if (!CLIENT.guest) {
|
||||||
socket.emit("initUserPLCallbacks");
|
socket.emit("initUserPLCallbacks");
|
||||||
|
var logoutform = $("<p/>").attr("id", "logoutform")
|
||||||
|
.addClass("navbar-text pull-right")
|
||||||
|
.insertAfter($("#loginform"));
|
||||||
|
|
||||||
|
$("<span/>").attr("id", "welcome").text("Welcome, " + CLIENT.name)
|
||||||
|
.appendTo(logoutform);
|
||||||
|
$("<span/>").html(" · ").appendTo(logoutform);
|
||||||
|
var domain = $("#loginform").attr("action").replace("/login", "");
|
||||||
|
$("<a/>").attr("id", "logout")
|
||||||
|
.attr("href", domain + "/logout?redirect=/r/" + CHANNEL.name)
|
||||||
|
.text("Logout")
|
||||||
|
.appendTo(logoutform);
|
||||||
|
|
||||||
|
$("#loginform").remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue