This question has been answered by meltingdog. See the first response.
You can use the email address as the username to begin with, but I don't know of any way to use the email address if the user is already set up to have a separate username and email address.
I suppose you could create a plugin using OnBeforeWebLogin to take the email from the login form, get that user's username and replace the form value with the username and complete the login. But unless you need a separate username for some reason, it would be a lot easier to just use the email address for the username in the first place.
if (strpos($username, '@') !== false) { $profile = $modx->getObject('modUserProfile', array('email' => $username)); if ($profile) { $usr = $profile->getOne('User'); if ($usr) { if ($usr->passwordMatches($password)) { return true; } } } } return false;
You shouldn't need Ajax, just a plugin attached to OnWebAuthentication (and/or OnManagerAuthentication).
<div class="loginForm"> <div class="loginMessage">[[+errors]]</div> <div class="loginLogin"> <form class="loginLoginForm" action="[[~[[*id]]]]" method="post"> <fieldset class="loginLoginFieldset"> <legend class="loginLegend">[[+actionMsg]]</legend> <label class="loginEmailLabel">Email Address <input class="loginEmail" type="text" name="useremail" /> </label> <input class="loginUsername" type="hidden" name="username" /> <label class="loginPasswordLabel">[[%login.password]] <input class="loginPassword" type="password" name="password" /> </label> <input class="returnUrl" type="hidden" name="returnUrl" value="[[+request_uri]]" /> [[+login.recaptcha_html]] <input class="loginLoginValue" type="hidden" name="service" value="login" /> <span class="loginLoginButton"><input type="submit" name="Login" value="[[+actionMsg]]" /></span> </fieldset> </form> </div> </div>
<script type="text/javascript"> $(document).ready(function() { $('.loginEmail').focusout(function(e) { var url = 'URL OF PAGE WITH AJAX PHP'; var data = { userEmail: $(".loginEmail").val(), };//DATA var success = function(data) { var username = data.msg; $('.loginUsername').val(username); }//SUCCESS $.ajax(url, { type: 'get', dataType: 'json', data: data, success: success }); });//FOCUS OUT });//READY </script>
<?php $useremail = trim($_GET['userEmail']); //FIND USER NAME $query = "SELECT * FROM `modx_user_attributes` WHERE `email` = '$useremail'"; $result = $modx->query($query); if ($result) { while ($resultrow = $result->fetch(PDO::FETCH_ASSOC)) { $userid = $resultrow['id']; $query2 = "SELECT * FROM `modx_users` WHERE `id` = '$userid'"; $result2 = $modx->query($query2); if ($result2) { while ($result2row = $result2->fetch(PDO::FETCH_ASSOC)) { $username = $result2row['username']; sendSuccess($username); } } } } function sendSuccess($msg) { $result = array('res' => 1, 'msg' => $msg); sendResponse($result); }