Пример #1
0
Template.signup.onRendered(function () {
    var signup_form = $("#signup_form");
    if(signup_form.length){
        let validator = signup_form.validate({
            submitHandler: function(events){
                let fullname = $('[name=fullname]').val();
                let email = $('[name=email]').val();
                let password = $('[name=password]').val();
                let user = {'email': email, password: password, profile: {name: fullname}};
                Accounts.createUser(user, function(err) {
                    if (!err) {
                        Meteor.loginWithPassword(user.email, user.password, function(errors){
                            if(!errors){                               
                                Router.go("/")
                            }
                        })
                    } else {
                        if (err.reason == "Email already exists.") {
                            validator.showErrors({
                                email: i18n('form.email_exist')
                            });
                        }
                    }
                });
       
            }
        })
    }
});
Пример #2
0
import {Meteor} from 'meteor/meteor';
import {FlowRouter} from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';

import './signup.html';

Template.signup.onRendered( () => {
    console.log("signup");
});

Template.signup.events({
    'submit form': ( event ) => {
        event.preventDefault();
        var email = $('[type=email]').val();
        var password = $('[name=password]').val();

        Meteor.call('users.addUser', {
            email:email, password:password
        }, (error,result) => {
            if(error) {
                Bert.alert(error.reason, 'danger');
            }
            else if(result) {
                Meteor.loginWithPassword(email, password, (error) => {

                    if(error) {
                        Bert.alert(error.reason, 'danger', 'fixed-top', 'fa-frown-o');
                    }
                });
            }
        });