Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Template.signUp.onRendered(function(){
  2.     // Validation
  3.     var validator=$('form#formSignUp').validate({
  4.         rules:{
  5.             password_confirm:{
  6.                 required:true,
  7.                 equalTo:'[name=password]'
  8.             },
  9.             min_age:{
  10.                 required:true
  11.             }
  12.         },
  13.         messages:{
  14.             password_confirm:{
  15.                 equalTo:'The passwords do not match'
  16.             },
  17.             min_age:{
  18.                 required:'You have to confirm your age'
  19.             }
  20.         },
  21.         submitHandler:function(e){
  22.             var username=$('[name=username]').val(),
  23.                 email=$('[name=email]').val(),
  24.                 password=$('[name=password]').val();
  25.  
  26.             Accounts.createUser({
  27.                 username:username,
  28.                 email:email,
  29.                 password:password
  30.             },function(error){
  31.                 if(error){
  32.                     if(error.reason=='Incorrect password'){
  33.                         validator.showErrors({
  34.                             password:error.reason
  35.                         });
  36.                     }
  37.                 }else{
  38.                     FlowRouter.go('home');
  39.                 }
  40.             });
  41.         }
  42.     });
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement