Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: JavaScript  |  size: 0.81 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // QUERY À BD
  2.  
  3. UserSchema.statics.validateEmail = function validateEmail (email, callback) {
  4.         this.count({email: email}, function(err, count) {
  5.                 if (count > 0)
  6.                         callback(false);
  7.                 else
  8.                         callbac(true);
  9.         });
  10. };
  11.  
  12.  
  13. // MODEL QUE CHAMA A QUERY À BD
  14.  
  15. module.exports.validateEmail = function(email) {
  16.         var bool;
  17.         UserModel.validateEmail(email, function(b) {
  18.                 bool = b;
  19.                 console.log('BOOL1', bool);
  20.         });
  21.         return bool;
  22.         console.log('BOOL2', bool);
  23. }
  24.  
  25.  
  26. //FUNCAO QUE VALIDA REGISTO
  27.  
  28. .validateRegistration( function (newUserAttrs, errors) {
  29.       var email = newUserAttrs.email;
  30.       //var displayName = newUserAttrs.displayName;
  31.      
  32.       // Validate email
  33.       var bool = User.validateEmail(email);
  34.       if (!bool) errors.push('Email already taken');
  35.      
  36.       return errors;
  37.     })