|
@@ -65,7 +65,7 @@ Server.prototype.onListen = function() {
|
|
|
function redirectToSlackAuth(res) {
|
|
function redirectToSlackAuth(res) {
|
|
|
res.writeHeader("302", {
|
|
res.writeHeader("302", {
|
|
|
Location: "https://slack.com/oauth/authorize"
|
|
Location: "https://slack.com/oauth/authorize"
|
|
|
- +"?client_id=" +config.clientId
|
|
|
|
|
|
|
+ +"?client_id=" +config.login.slack.clientId
|
|
|
+"&scope=" +slackManager.getScope().join(",")
|
|
+"&scope=" +slackManager.getScope().join(",")
|
|
|
+"&redirect_uri=" +config.rootUrl
|
|
+"&redirect_uri=" +config.rootUrl
|
|
|
});
|
|
});
|
|
@@ -78,7 +78,12 @@ Server.prototype.onRequest = function(req, res) {
|
|
|
req.session = sessionManager.forRequest(req);
|
|
req.session = sessionManager.forRequest(req);
|
|
|
req.urlObj = new Url(req.url);
|
|
req.urlObj = new Url(req.url);
|
|
|
|
|
|
|
|
- if (!req.session || !req.session.slackToken) {
|
|
|
|
|
|
|
+ if (req.urlObj.isTemplate() && req.urlObj.template.needLogin === false) {
|
|
|
|
|
+ var resp = req.urlObj.template.exec(req, res);
|
|
|
|
|
+ res.writeHeader(resp.status || 200);
|
|
|
|
|
+ res.end(resp.body);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if (!req.session || !req.session.slackToken) {
|
|
|
if (req.urlObj.queryTokens.code) {
|
|
if (req.urlObj.queryTokens.code) {
|
|
|
Slack.getOauthToken(req.urlObj.queryTokens.code, config.rootUrl, (token) => {
|
|
Slack.getOauthToken(req.urlObj.queryTokens.code, config.rootUrl, (token) => {
|
|
|
if (token) {
|
|
if (token) {
|
|
@@ -95,8 +100,16 @@ Server.prototype.onRequest = function(req, res) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- redirectToSlackAuth(res);
|
|
|
|
|
|
|
+ res.writeHeader("302", {
|
|
|
|
|
+ Location: "login"
|
|
|
|
|
+ });
|
|
|
|
|
+ res.end();
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (req.urlObj.isTemplate()) {
|
|
|
|
|
+ var resp = req.urlObj.template.exec(req, res);
|
|
|
|
|
+ res.writeHeader(resp.status || 200);
|
|
|
|
|
+ res.end(resp.body);
|
|
|
|
|
+ return;
|
|
|
} else if (req.urlObj.isPublic()) {
|
|
} else if (req.urlObj.isPublic()) {
|
|
|
if (!config.isDebug)
|
|
if (!config.isDebug)
|
|
|
res.setHeader('Cache-Control', 'private, max-age=' +15 * 60);
|
|
res.setHeader('Cache-Control', 'private, max-age=' +15 * 60);
|