简体   繁体   English

Node.js Meteor创建一个初始页面,并输入密码以进入该应用程序。 保持用户登录独立,并在应用程序内超过启动页面

[英]Node.js Meteor create a splash page with password to enter into the app. Keeping user login separate and inside the app past the splash page

Wanting to create a splash page where a user can enter a site password that is the same for everyone. 想要创建一个初始页面,用户可以在其中输入每个人都相同的站点密码。 It's to hide the site while it's in preview only. 仅在预览时隐藏网站。 Not sure why I'm not getting how to do this. 不知道为什么我没有做到这一点。 It's got to be relatively straight forward in meteor. 流星必须相对直截了当。

Currently have Meteor-Router installed. 当前已安装流星路由器。 Is this the best approach? 这是最好的方法吗? How do I go about this? 我该怎么办?

Thank you 谢谢

Here is one possible answer in CoffeeScript: 这是CoffeeScript中的一个可能答案:

Add a filter on the Router like: Router上添加一个过滤器,例如:

Meteor.Router.filters
  'authorizeUser': (page) ->
    if Session.get 'knowsTheSecret' then page else 'splash'

Meteor.Router.filter 'authorizeUser'

That says every page request must have the knowsTheSecret session variable set or the user will get booted back to the splash page (defined elsewhere). 也就是说,每个页面请求必须设置了knowsTheSecret会话变量,否则用户将被引导回到splash页面(在其他地方定义)。

On the server (as in put this in the server directory). 在服务器上(将其放在server目录中)。 Create a method to validate the password: 创建一种方法来验证密码:

Meteor.methods
  checkSecret: (string) ->
    string is 'super secret password'

When the user clicks the login button on your splash page, you can call the method like so: 当用户单击初始页面上的登录按钮时,可以这样调用方法:

Template.splash.events
  'click button': ->
    password = $('#text-field').val()
    Meteor.call 'checkSecret', password, (err, result) ->
      Session.set 'knowsTheSecret', result

So the Session varable will only get set if the user actually knows the secret. 因此,只有在用户实际知道秘密的情况下, Session变量才会被设置。 This, of course, is not secure in any real way (They user could just open a console and set the session variable manually) but it's a start. 当然,这在任何方面都不是安全的(他们用户可以打开控制台并手动设置会话变量),但这只是一个开始。 Play around with all that and see if it gets you closer to a working solution. 尝试所有这些,看看它是否使您更接近可行的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM