[英]How to Check an Email Used for User Registration in Meteor
I want to validate a user details being registered in Meteor.users
collection. 我想验证在Meteor.users
集合中注册的用户详细信息。
I know that I can check username uniqueness by simply querying the db field username
of the Meteor.users
; 我知道我可以通过简单地查询Meteor.users
的db字段username
来检查用户名的唯一性; ie 即
var obj = Meteor.users.findOne({username:userId});
if (obj!=null) {
alert('Username is already in use');
}
But how do I check the uniqueness of the email as well? 但是,我该如何检查电子邮件的唯一性呢? Because from the documentation, the emails
is an array of an object with address
and verified
fields. 因为从文档来看, emails
是一个包含address
和verified
字段的对象数组。 How do I consturct the filter for this? 我该如何构造过滤器?
You wouldn't have to do this. 您不必这样做。 If you tried to insert a document where someone already has the email address it wouldn't allow it. 如果您试图在某人已经拥有该电子邮件地址的地方插入文档,则该文件将被禁止。 The emails.address
is set as a unique key and mongo wouldn't allow it to be inserted. emails.address
设置为唯一键,mongo不允许插入。
It is a good idea to get the error at the point of insertion than to use Meteor.users.findOne()
on the browser side. 与在浏览器端使用Meteor.users.findOne()
相比,在插入时获取错误是个好主意。
This is because you would need to publish all the users email's for the code to work on the browser and this wouldn't be 1) scalable and 2) bad from a privacy standpoint. 这是因为您需要发布所有用户的电子邮件,代码才能在浏览器上运行,并且从隐私角度来看,这不会1)可扩展。
Another option is to check whether the email exists with Meteor.call and Meteor methods if you want to display a dynamic status label on whether the address is available or not. 另一个选择是,如果要显示有关地址是否可用的动态状态标签,请检查电子邮件是否存在Meteor.call和Meteor方法。
<?php
session_start();
include 'include/config.php';
//$sql=$dbset->query("select * from registries WHERE email_id LIKE'".$_POST['email']."'");
$sql=mysql_query("select * from registries WHERE email_id LIKE '".$_POST['email']."'");
echo $count = mysql_num_rows($sql);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.