Edgar
Edgar

Reputation: 927

Meteor - return false

In this code what does the last return false; do?

Template.register.events({
  'submit #register-form': function(event, template) {
    event.preventDefault();
    // Get input values
    var email = template.find('#account-email').value,
      password = template.find('#account-password').value;

    // Trim and validate Email
    var trimInput = function(val) {
      return val.replace(/^\s*|\s*$/g, "");
    }
    var email = trimInput(email);

    // Validate Password
    var isValidPassword = function(value) {
      if (value.length >= 6) {
        return true;
      } else {
        sAlert.error('Your password must be at least 6 characters long');
        return false;
      }
    }

    // If Password ok -> Register user
    if (isValidPassword(password)) {
      Accounts.createUser({
        email: email,
        password: password
      }, function(error) {
        if (error) {
          // Inform the user that account creation failed
          sAlert.error('Account creation failed for unknown reasons');
        } else {
          // Success. Account has been created and the user
          // has logged in successfully.
          sAlert.success('Account created successfully');
        }
      });
    }
    return false;
  }
});

Upvotes: 0

Views: 289

Answers (2)

grymlord
grymlord

Reputation: 42

isValidPassword() is a function which returns a Boolean value (true or false). This script allows the user to continue with account creation if it returns true

Upvotes: 0

Christine
Christine

Reputation: 640

From the looks of it, it looks like it was intended to provide a false response should the code make it all the way to the bottom.

Upvotes: 1

Related Questions