如何在客户端删除 Meteor 用户?
How to delete Meteor Users on client side?
我正在使用 meteor ui 推特帐户。我试图做的基本上是在单击清除按钮时从 Meteor 集合中删除所有用户。这是我的代码:
HTML 文件:
<div ng-controller="TweetsCtrl">
<meteor-include src="loginButtons"></meteor-include>
<ul>
<br>
<div ng-repeat="t in twitterAccs">
<img src = "{{t.services.twitter.profile_image_url_https}}">
<br>
<i>@{{t.services.twitter.screenName}}</i>
<br>
<br>
</div>
<button ng-click="clearUsers()">Clear</button>
</ul>
JS 文件:
if (Meteor.isClient) {
angular.module('twitter-example',['angular-meteor']);
angular.module('twitter-example').controller('TweetsCtrl',['$scope','$meteor',function($scope,$meteor) {
$scope.twitterAccs = $meteor.collection(Meteor.users);
$scope.clearUsers = function () {
$scope.twitterAccs = $meteor.collection(Meteor.users.remove({}) );
console.log("hello");
}
}]);
}
我想这只是为了开发目的吧?允许您网站的访问者删除您的所有用户是很糟糕的。你为它设置了一个很好的按钮这一事实让我担心这是一个功能!
最简单的方法是连接 Meteor.method,例如
if (Meteor.isServer) {
Meteor.methods({
clearUsers: function() {
Meteor.users.remove({});
}
});
}
然后在 console.log("hello") 所在的位置执行 Meteor.call('clearUsers')。您还可以 运行 通过浏览器控制台调用,我有时会进行此设置,而不是通过终端直接转到数据库。
您也可以通过允许拒绝规则来实现(参见:http://docs.meteor.com/#/full/allow),默认情况下会设置一条规则,因此用户只能编辑自己的配置文件对象。
最后,你可以包含不安全的流星包(我假设你一定已经删除了它),这将允许任何人编辑任何集合,假设你没有设置任何允许,拒绝上述规则。
我正在使用 meteor ui 推特帐户。我试图做的基本上是在单击清除按钮时从 Meteor 集合中删除所有用户。这是我的代码:
HTML 文件:
<div ng-controller="TweetsCtrl">
<meteor-include src="loginButtons"></meteor-include>
<ul>
<br>
<div ng-repeat="t in twitterAccs">
<img src = "{{t.services.twitter.profile_image_url_https}}">
<br>
<i>@{{t.services.twitter.screenName}}</i>
<br>
<br>
</div>
<button ng-click="clearUsers()">Clear</button>
</ul>
JS 文件:
if (Meteor.isClient) {
angular.module('twitter-example',['angular-meteor']);
angular.module('twitter-example').controller('TweetsCtrl',['$scope','$meteor',function($scope,$meteor) {
$scope.twitterAccs = $meteor.collection(Meteor.users);
$scope.clearUsers = function () {
$scope.twitterAccs = $meteor.collection(Meteor.users.remove({}) );
console.log("hello");
}
}]);
}
我想这只是为了开发目的吧?允许您网站的访问者删除您的所有用户是很糟糕的。你为它设置了一个很好的按钮这一事实让我担心这是一个功能!
最简单的方法是连接 Meteor.method,例如
if (Meteor.isServer) {
Meteor.methods({
clearUsers: function() {
Meteor.users.remove({});
}
});
}
然后在 console.log("hello") 所在的位置执行 Meteor.call('clearUsers')。您还可以 运行 通过浏览器控制台调用,我有时会进行此设置,而不是通过终端直接转到数据库。
您也可以通过允许拒绝规则来实现(参见:http://docs.meteor.com/#/full/allow),默认情况下会设置一条规则,因此用户只能编辑自己的配置文件对象。
最后,你可以包含不安全的流星包(我假设你一定已经删除了它),这将允许任何人编辑任何集合,假设你没有设置任何允许,拒绝上述规则。