Meteor.js:获取匿名访问者的唯一 ID/ip/什么? [英] Meteor.js: Get anonymous visitors unique ID/ip/whatever?

查看:19
本文介绍了Meteor.js:获取匿名访问者的唯一 ID/ip/什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在使用meteor.js 构建一个应用程序,我只是从用户那里收集一些简单的表单数据.也许是一个简单问题的答案或其他东西.他们无需登录即可提交数据.

Let's say I'm building an app using meteor.js where I just collect some simple form data from users. Maybe an answer to a simple question or something. They don't need to log in to submit data.

我如何保护我的应用免受在 Chrome 控制台中创建 js 循环的人的侵害,该循环只是将废话插入我的数据库中?

我可以通过这样做来保护删除和更新:

I can protect removal and updates by doing this:

Formanswers.allow({
  insert: function () {
    return true;
  },
  update: function () {
    return false;
  },
  remove: function () {
    return false;
  },
});

如果用户已登录(您记得在我的应用程序中并非如此),我可以为每个插入添加时间戳并检查如下内容:

And if the user was logged in (which as you remember is not the case in my app) I could timestamp each insert and check something like:

  insert: function (userId, doc) {
        if (userId && (Formanswers.findOnd({userid: userId, time: SOMETHING TIME SPECIFIC}).count() < 1)) return true;
  },

所以我的问题是:有没有其他方法可以为匿名(未登录)用户获取唯一的 userId 或 IP 地址,以便我也可以对他进行上述检查?

So my question is: is there any other way of getting a unique userId-thing or IP-address or something for an anonymous (not logged in) user so I can do the above check on him as well?

谢谢!

推荐答案

可以使用陨石包.

帐户-匿名

https://github.com/tmeasday/meteor-accounts-anonymous

所以你使用

Meteor.loginAnonymously();

如果用户第一次访问你的页面,使用 .allow 查看你需要的内容

if the user visits your page for the first time, and use .allow to check what you need

这篇关于Meteor.js:获取匿名访问者的唯一 ID/ip/什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆