简体   繁体   中英

How to Check an Email Used for User Registration in Meteor

I want to validate a user details being registered in Meteor.users collection.

I know that I can check username uniqueness by simply querying the db field username of the Meteor.users ; 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. 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.

It is a good idea to get the error at the point of insertion than to use Meteor.users.findOne() on the browser side.

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.

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.

<?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);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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