Skip to content

Commit

Permalink
refactor(emails): remove email validation on client and server side
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Jul 30, 2021
1 parent 12b2a97 commit 7c1d1c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
40 changes: 8 additions & 32 deletions public/src/client/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ define('forum/register', [
var successIcon = '';

Register.init = function () {
var email = $('#email');
var username = $('#username');
var password = $('#password');
var password_confirm = $('#password-confirm');
Expand All @@ -19,17 +18,12 @@ define('forum/register', [

$('#content #noscript').val('false');

email.on('blur', function () {
if (email.val().length) {
validateEmail(email.val());
}
});

var query = utils.params();
if (query.email && query.token) {
email.val(decodeURIComponent(query.email));
$('#token').val(query.token);
}
// TODO: #9607
// var query = utils.params();
// if (query.email && query.token) {
// email.val(decodeURIComponent(query.email));
// $('#token').val(query.token);
// }

// Update the "others can mention you via" text
username.on('keyup', function () {
Expand Down Expand Up @@ -58,10 +52,7 @@ define('forum/register', [
validationError = false;
validatePassword(password.val(), password_confirm.val());
validatePasswordConfirm(password.val(), password_confirm.val());

validateEmail(email.val(), function () {
validateUsername(username.val(), callback);
});
validateUsername(username.val(), callback);
}

// Guard against caps lock
Expand Down Expand Up @@ -119,22 +110,9 @@ define('forum/register', [
});

// Set initial focus
$('#email').focus();
$('#username').focus();
};

function validateEmail(email, callback) {
callback = callback || function () {};
var email_notify = $('#email-notify');

if (!utils.isEmailValid(email)) {
showError(email_notify, '[[error:invalid-email]]');
return callback();
}

showSuccess(email_notify, successIcon);
callback();
}

function validateUsername(username, callback) {
callback = callback || function () {};

Expand Down Expand Up @@ -175,8 +153,6 @@ define('forum/register', [
showError(password_notify, '[[user:change_password_error]]');
} else if (password === $('#username').val()) {
showError(password_notify, '[[user:password_same_as_username]]');
} else if (password === $('#email').val()) {
showError(password_notify, '[[user:password_same_as_email]]');
} else if (passwordStrength.score < ajaxify.data.minimumPasswordStrength) {
showError(password_notify, '[[user:weak_password]]');
} else {
Expand Down
15 changes: 6 additions & 9 deletions src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ async function registerAndLoginUser(req, res, userData) {
await authenticationController.doLogin(req, uid);
}

// Distinguish registrations through invites from direct ones
if (userData.token) {
await user.joinGroupsFromInvitation(uid, userData.email);
}
await user.deleteInvitationKey(userData.email);
// TODO: #9607
// // Distinguish registrations through invites from direct ones
// if (userData.token) {
// await user.joinGroupsFromInvitation(uid, userData.email);
// }
// await user.deleteInvitationKey(userData.email);
const next = req.session.returnTo || `${nconf.get('relative_path')}/`;
const complete = await plugins.hooks.fire('filter:register.complete', { uid: uid, next: next });
req.session.returnTo = complete.next;
Expand All @@ -80,10 +81,6 @@ authenticationController.register = async function (req, res) {
await user.verifyInvitation(userData);
}

if (!userData.email) {
throw new Error('[[error:invalid-email]]');
}

if (
!userData.username ||
userData.username.length < meta.config.minimumUsernameLength ||
Expand Down

0 comments on commit 7c1d1c7

Please sign in to comment.