身份验证事件监听器

时间:2016-03-29 22:49:50

标签: jquery ajax sequelize.js

我目前正在尝试制作两个事件处理程序:一个用于用户注册并创建一个新帐户,另一个用于用户尝试登录时。在撰写本文时,如果实现了无效凭据并创建了新用户,但未将其存储在数据库中,则不会发生任何事情。有人能解释一下signUp()和auth()方法在做什么吗?

'use strict';
var userService = window.skilly.userService;
const _ = require('lodash');

$(document).ready(function(event) {
    $('#signup').on('click', function(event) {
        /* stop form from submitting normally */
                // event.preventDefault();

            /* get some values from elements on the page: */
            // var $form = $(this),
            //     term = $form.find('input[name="s"]').val(),
            //     url = $form.attr('action');
             var user = _.object($("#myForm").serializeArray().map(function (v) {
                return [v.name, v.value];
            }));



            /* Send the data using post */
             var signUp = $.ajax({
                type: "POST",
                url: 'https://skilly-rayman504.c9users.io/user',
                success: function(user) {
                    console.log(user);
                }
            })
            userService.signUp(user);
    })
    $('#login').on('click', function(event) {
    /* stop form from submitting normally */
            // event.preventDefault();

            /* get some values from elements on the page: */
    event.preventDefault();
    var creds = _.object($("#form-signin").serializeArray().map(function (v) {
        return [v.name, v.value];
    }));
    $('#btn-close-auth').trigger('click');

            // /* Send the data using post */
             var auth = $.ajax({
                type: "POST",
                url: 'https://skilly-rayman504.c9users.io/user/auth',
                success: function(user) {
                    console.log(user);
                }
            })
        userService.auth(creds);
   })
})

0 个答案:

没有答案