<commit_before>var View = require("../view");
var template = require("../tmpl/create-user-form");
var PolisStorage = require("../util/polisStorage");
var $ = require("jquery");

  module.exports = View.extend({
    name: "create-user-form",
    template: template,
    gotoCreate: function() {
      this.model.set("create", true);
    },
    gotoSignIn: function() {
      this.model.set("create", false);
    },
    events: {
      "click .gotoSignIn": "gotoSignIn",
      "click .gotoCreate": "gotoCreate",
      "submit form": function(event){
        if (this.model.get("create")) {
          return this.createUser.call(this, event);
        } else {
          return this.signIn.call(this, event);
        }
      },
      "invalid": function(errors){
        console.log("invalid form input" + errors[0].name);
        console.log(errors);

       //_.each(errors, function(err){
          $("input[name=\""+errors[0].name+"\"]").closest("label").append(errors[0].message); // relationship between each input and error name
        //})
      }
    },
    initialize: function(){
      var urlPrefix = "https://www.polis.io/";
      if (-1 === document.domain.indexOf(".polis.io")) {
        urlPrefix = "http://localhost:5000/";
      }
    },
    createUser: function(event) {
    var that = this;
    event.preventDefault();
    this.serialize(function(attrs, release){
        // Incorporate options, like zinvite.
        var zinvite = that.model.get("zinvite");
        if (zinvite) {
          attrs.zinvite = zinvite;
        }
      $.ajax({
        url: urlPrefix + "v3/auth/new",
        type: "POST",
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        data: attrs
      }).then(function(data) {
        that.trigger("authenticated");
        release();
      }, function(err) {
          alert("login was unsuccessful");
          release();
      });
    });
  },
  signIn: function(event) {
    var that = this;
    event.preventDefault();
    this.serialize(function(attrs, release){
      $.ajax({
        url: urlPrefix + "v3/auth/login",
        type: "POST",
        dataType: "json",
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        data: attrs
      }).then(function(data) {
        release();
        that.trigger("authenticated");
      }, function(err) {
          release();
          alert("login was unsuccessful");
      });
    });
  },
  validateInput: function(attrs){
    var errors = [];
    if(attrs.email === ""){
      errors.push({name: "description",  message: "hey there... you need an email"});
    }
    return errors;
  },
  initialize: function(options) {
    this.model = options.model;
    this.listenTo(this, "rendered", function(){
      this.$("#conductor").anystretch("img/conductor.jpeg");
    });
  }
});<commit_msg>fix create-user-form init after refactor<commit_after>var View = require("../view");
var template = require("../tmpl/create-user-form");
var PolisStorage = require("../util/polisStorage");
var $ = require("jquery");

  module.exports = View.extend({
    name: "create-user-form",
    template: template,
    gotoCreate: function() {
      this.model.set("create", true);
    },
    gotoSignIn: function() {
      this.model.set("create", false);
    },
    events: {
      "click .gotoSignIn": "gotoSignIn",
      "click .gotoCreate": "gotoCreate",
      "submit form": function(event){
        if (this.model.get("create")) {
          return this.createUser.call(this, event);
        } else {
          return this.signIn.call(this, event);
        }
      },
      "invalid": function(errors){
        console.log("invalid form input" + errors[0].name);
        console.log(errors);

       //_.each(errors, function(err){
          $("input[name=\""+errors[0].name+"\"]").closest("label").append(errors[0].message); // relationship between each input and error name
        //})
      }
    },
    createUser: function(event) {
    var that = this;
    event.preventDefault();
    this.serialize(function(attrs, release){
        // Incorporate options, like zinvite.
        var zinvite = that.model.get("zinvite");
        if (zinvite) {
          attrs.zinvite = zinvite;
        }
      $.ajax({
        url: that.urlPrefix + "v3/auth/new",
        type: "POST",
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        data: attrs
      }).then(function(data) {
        that.trigger("authenticated");
        release();
      }, function(err) {
          alert("login was unsuccessful");
          release();
      });
    });
  },
  signIn: function(event) {
    var that = this;
    event.preventDefault();
    this.serialize(function(attrs, release){
      $.ajax({
        url: that.urlPrefix + "v3/auth/login",
        type: "POST",
        dataType: "json",
        xhrFields: {
          withCredentials: true
        },
        crossDomain: true,
        data: attrs
      }).then(function(data) {
        release();
        that.trigger("authenticated");
      }, function(err) {
          release();
          alert("login was unsuccessful");
      });
    });
  },
  validateInput: function(attrs){
    var errors = [];
    if(attrs.email === ""){
      errors.push({name: "description",  message: "hey there... you need an email"});
    }
    return errors;
  },
  initialize: function(options) {
    this.model = options.model;
    this.urlPrefix = "https://www.polis.io/";
    if (-1 === document.domain.indexOf(".polis.io")) {
      this.urlPrefix = "http://localhost:5000/";
    }
  }
});
{'fraction_non_alphanumeric': 0.16904133685136324, 'fraction_numerical': 0.003518029903254178, 'mean_word_length': 2.1747627024008933, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1435792', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1683, 'n_words': 333}