hostr/web/routes/index.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-07-09 23:01:43 +01:00
import uuid from 'node-uuid';
import auth from '../lib/auth';
export function* main() {
if (this.session.user) {
if (this.query['app-token']) {
2016-06-06 15:37:00 +01:00
this.redirect('/');
return;
2015-07-09 23:01:43 +01:00
}
const token = uuid.v4();
yield this.redis.set(token, this.session.user.id, 'EX', 604800);
this.session.user.token = token;
2016-06-06 15:37:00 +01:00
yield this.render('index', { user: this.session.user });
2015-07-09 23:01:43 +01:00
} else {
if (this.query['app-token']) {
const user = yield auth.fromToken(this, this.query['app-token']);
yield auth.setupSession(this, user);
this.redirect('/');
} else if (this.cookies.r) {
const user = yield auth.fromCookie(this, this.cookies.r);
yield auth.setupSession(this, user);
this.redirect('/');
} else {
yield this.render('marketing');
}
}
}
export function* staticPage(next) {
if (this.session.user) {
const token = uuid.v4();
yield this.redis.set(token, this.session.user.id, 'EX', 604800);
this.session.user.token = token;
2016-06-06 15:37:00 +01:00
yield this.render('index', { user: this.session.user });
2015-07-09 23:01:43 +01:00
} else {
2015-08-23 22:12:32 +01:00
switch (this.originalUrl) {
2016-06-06 15:37:00 +01:00
case '/terms':
yield this.render('terms');
break;
case '/privacy':
yield this.render('privacy');
break;
case '/pricing':
yield this.render('pricing');
break;
case '/apps':
yield this.render('apps');
break;
case '/stats':
yield this.render('index', { user: {} });
break;
default:
yield next;
2015-07-09 23:01:43 +01:00
}
}
}