<![CDATA[ Use Email as username for WebLogin? - My Forums]]> https://forums.modx.com/thread/?thread=44731 <![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-431018 nuwebstudios Jul 23, 2012, 08:28 AM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-431018 <![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-430378
Replace lines 48-85 with this code, instead of the above:

// check for duplicate email address
	$sql = "SELECT internalKey FROM ".$modx->getFullTableName("web_user_attributes")." WHERE email='$email'";
	if(!$rs = $modx->db->query($sql)){
 	   $output = webLoginAlert(WL_ERRONCHECKEMAIL.$email).$tpl;
 	   return;
	} 
	$limit = $modx->db->getRecordCount($rs);
	if($limit>0) {
	    $row=$modx->db->getRow($rs);
 	   if($row['internalKey']!=$id) {
 	       $output = webLoginAlert(WL_EMAILINUSE).$tpl;
 	       return;
 	   }
	}
 	if($email=='' || !preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i", $email)){
        $output = webLoginAlert("E-mail address doesn't seem to be valid!").$tpl;
        return;
    }
	//verify email confirm
	if($email != $modx->db->escape($_POST['username'])){
 	   $output = webLoginAlert(WL_EMAILMISSMATCH).$tpl;
 	   return;
	}
	// verify password
	if ($_POST['password']!=$_POST['confirmpassword']) {
   		$output = webLoginAlert(WL_PASSMISSMATCH).$tpl;
    	return;
	}
 
	// check for duplicate user name
	if($username=="") {
    	$output = webLoginAlert(WL_MISSINGUNAME).$tpl;
    	return;
	}
	else {
    	$sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
    	if(!$rs = $modx->db->query($sql)){
        	$output = webLoginAlert(WL_ERRONCKECHUNAME.$username).$tpl;
        	return;
    	} 
    	$limit = $modx->db->getRecordCount($rs);
    	if($limit>0) {
        	$output = webLoginAlert(WL_UNAMEISUSED).$tpl;
        	return;
    	}       
	}


This changes the order of checking the db records, checking the email before the username.
Also it checks the the email against the username.

In register template, change field labeled as confirm email like this:

<tr>
              <td>Confirm Email address:*</td>
              <td>
              <input type="text" name="username" class="inputBox" style="width:300px" size="20" value="[+username+]"></td>
            </tr>


The reason for the difference is this snippet has been updated, which fixed ereg deprecation.]]>
nuwebstudios Jul 18, 2012, 09:27 AM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-430378
<![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257374 I had some issues with it and didn’t need the added features so used its daddy.]]> bunk58 May 01, 2008, 02:23 AM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257374 <![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257373 rynoceris Apr 30, 2008, 10:18 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257373 <![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257372
	// check for duplicate email address
	$sql = "SELECT internalKey FROM ".$modx->getFullTableName("web_user_attributes")." WHERE email='$email'";
	if(!$rs = $modx->db->query($sql)){
		$output = webLoginAlert(WL_ERRONCHECKEMAIL.$email).$tpl;
		return;
	} 
	$limit = $modx->db->getRecordCount($rs);
	if($limit>0) {
		$row=$modx->db->getRow($rs);
		if($row['internalKey']!=$id) {
			$output = webLoginAlert(WL_EMAILINUSE).$tpl;
			return;
		}
	}
	
	// verify email
	if($email=='' || !ereg("^[-!#$%&'*+./0-9=?A-Z^_`a-z{|}~]+", $email)){
		$output = webLoginAlert(WL_EMAILNOTVALID).$tpl;
		return;
	}
	//verify email confirm
	if($email != $modx->db->escape($_POST['username'])){
		$output = webLoginAlert(WL_EMAILMISSMATCH).$tpl;
		return;
	}
	// verify password
	if ($_POST['password']!=$_POST['confirmpassword']) {
		$output = webLoginAlert(WL_PASSMISSMATCH).$tpl;
		return;
	}

	// check for duplicate user name
	if($username=="") {
		$output = webLoginAlert(WL_MISSINGUNAME).$tpl;
		return;
	}
	else {
		$sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
		if(!$rs = $modx->db->query($sql)){
			$output = webLoginAlert(WL_ERRONCKECHUNAME.$username).$tpl;
			return;
		} 
		$limit = $modx->db->getRecordCount($rs);
		if($limit>0) {
			$output = webLoginAlert(WL_UNAMEISUSED).$tpl;
			return;
		}		
	}

This changes the order of checking the db records, checking the email before the username.
Also it checks the the email against the username.
In my register template I have the username field labelled as confirm email like this:
        <label class="left" for="username">Confirm email: </label>
<input class="right" type="text" name="username" id="username" tabindex="3" size="40" value="[+username+]" />
]]>
bunk58 Apr 30, 2008, 06:50 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257372
<![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257371 rynoceris Apr 30, 2008, 06:29 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257371 <![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257370 It validates and cross checks the email / confirm email fields,
then uses the confirm email field as the username.
I also added a CC email to the client when someone registers.]]>
bunk58 Apr 30, 2008, 06:28 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257370
<![CDATA[Re: Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257369 sottwell Apr 30, 2008, 06:13 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257369 <![CDATA[Use Email as username for WebLogin?]]> https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257368 rynoceris Apr 30, 2008, 05:19 PM https://forums.modx.com/thread/44731/use-email-as-username-for-weblogin#dis-post-257368