【发布时间】:2016-02-12 00:28:08
【问题描述】:
Meteor 问题:实现真实会话的最佳方式是什么? 我有一个带有统计信息的正常登录页面。没有问题。
现在,我希望人们能够使用特定的 URL 进行签到;假设他们以后 点击http://localhost:3000/checkin/area1之类的网址
如何与他们的登录协调?
我有签到路线:
Router.route('/checkin/:_id', function () {
var req = this.request;
var res = this.response;
this.userId = 'steve'; //TODO: Need way to pull userId
if (!this.userId) {
res.end('Please login first');
} else {
//Verify correct area
//Verify that haven't check before
var lastCheckin = checkins.find({ user: this.userId, visited: this.params._id });
if (lastCheckin.count() == 0) {
//we haven't checkedin yet
checkins.insert({ user: this.userId, visited: this.params._id, createdAt: new Date() })
res.end('Checkin '+this.userId+' for '+this.params._id);
} else {
console.log('already checked in '+lastCheckin.createdAt);
res.end(this.userId+' already visited '+this.params._id);
}
}
}, {where: 'server'});
我尝试过的事情:
- 持久会话:但这不起作用,因为请求不是来自主页面,因此没有要提取的会话变量。
- 在请求中拉取 cookie(因为持久会话似乎有 1 个)。原始登录似乎没有请求对象,所以我不知道从哪里得到它。
- 其他(差异情况)在路由中显示了 Meteor.user(),但软件抱怨它只能在方法中使用。路由中可以使用什么?
我还能尝试什么?
感谢您的帮助。
【问题讨论】:
标签: meteor iron-router