我正在使用 meteor 帐户进行登录和用户注册。
当用户点击底线(注册)时:
他被重定向到创建帐户页面:
这些页面背后的代码是 jade 模板和 javascript 的混合体。
template(name="userFormsLayout")
section.auth-layout
section.auth-dialog
+Template.dynamic(template=content)
点击注册链接时内容似乎被替换了,据我所知...
我想通过禁用注册页面上的最终注册按钮和/或禁用完整注册页面来阻止用户创建新帐户。
我也对其他阻止用户注册的解决方案持开放态度。
相关: How can I set forbidClientAccountCreation to false in Meteor?
更新: 这个我也试过
AccountsTemplates.configure({
forbidClientAccountCreation: true
但是得到了:
Error: signUp route configured but forbidClientAccountCreation set to true!
谁能帮我解决这个问题?
最佳答案
我没有完整的答案,但我可以给你一些帮助你入门的东西。
首先,您可以告诉 AccountsTemplates (AT) 使用您的布局。你可以把它放在任何加载到客户端和服务器的地方,例如库/atConfig:
AccountsTemplates.configureRoute('signIn', {
layoutTemplate: 'LoginLayout'
});
这是布局模板:
<template name="LoginLayout">
<main>
<div>
{{> Template.dynamic template=main}}
</div>
</main>
</template>
在 JS 中,您可以隐藏模板中不想让用户看到的部分。在这里,我隐藏了密码表单和分隔符。您可以深入了解 DOM 以确定要隐藏哪些位:
Template.LoginLayout.onRendered(function() {
this.autorun(() => {
if (this.subscriptionsReady()) {
Tracker.afterFlush(() => {
$('.at-pwd-form').remove();
$('.at-sep').remove();
});
}
});
});
对于服务器,您可以检查新用户的尝试,如果他们使用用户名和密码进行尝试,则拒绝他们。我认为这应该可行,但您可能需要尝试一下:
import {Meteor} from 'meteor/meteor';
Meteor.startup(() => {
/**
* reject registration via username/password.
*/
Accounts.validateNewUser(function(attemptInfo) {
if (attemptInfo && attemptInfo.services && attemptInfo.services.password) {
return false;
}
return true;
});
});
关于javascript - 如何禁用 meteor 帐户用户注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42484777/