简体   繁体   English

如何在Meteor中检查用于用户注册的电子邮件

[英]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是一个包含addressverified字段的对象数组。 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.

相关问题 使用meteor js成功注册用户后发送电子邮件 - Send email after successful user registration using meteor js 如何正确验证用户注册的电子邮件? - How to properly do email validation on user registration? 如何确定用户在Meteor中使用的登录类型? - How to Determine Type of Login that User Used in Meteor? 流星检查用户是否为管理员 - Meteor Check if User is Admin 在插入新用户之前尝试检查我的 mongodb 中是否存在用户(以防止多个相同的电子邮件注册) - Trying to check if a user exist in my mongodb before inserting a new user (To prevent multiple same-email registration) 如何禁用流星帐户用户注册? - howto disable meteor accounts user registration? 如何在METEOR.js中使用Google登录时获取用户的电子邮件 - How to get user's email on sign in with google in METEOR.js 流星-如何找出是否可以使用Meteor.user()而不会引发错误? - Meteor - How to find out if Meteor.user() can be used without raising an error? 使用Meteor和React进行注册确认之前的电子邮件验证 - Email verification before registration confirmation using Meteor and React 流星:如何检查用户是否从chrome扩展名登录 - Meteor: how to check if an user is logged in from chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM