<commit_before>;(function() {  // IIFE
  'use strict';

  angular
    .module('brewKeeper')
    .controller('SignupController', SignupController);

  SignupController.$inject =
    ['$http', '$cookies', '$location', '$rootScope'];
  
  function SignupController($http, $cookies, $location, $rootScope) {
    var signupVm = this;
    signupVm.users = {};
    signupVm.signupButton = signupButton;

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the page.
     */
    function activate() {
      // Hide mismatch error when user acknowledges
      $("button.password-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.register-modal").addClass("inactive");
      });

      // Hide welcome modal when user acknowledges
      $("button.welcome-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.welcome-modal").addClass("inactive");
      });
    }

    /**
     * If passwords match, attempt to create the user.
     *
     * @param {boolean} mismatch Were the two passwords entered different?
     */
    function signupButton(mismatch) {
      if (mismatch) {
        // Show user mismatch error
        $(".wrapper").addClass("openerror");
        $("section.register-modal").removeClass("inactive");
        return;
      }

      $http.post($rootScope.baseUrl + '/api/register/', signupVm.users)
        .then(successCallback, errorCallback);

      function errorCallback(response) {
        // TODO: Replace alert with modal
        if (response.status < 500) {
          alert("Ooh, sorry! That username already exists. " +
            "Please choose a different one.");
        } else {
          alert("Apologies, but we have encountered an error.");
        }
      }

      function successCallback(response) {
        // Set the returned token in the cookies/headers to allow user to remain
        // logged in
        var userInfo = "Token " + response.data.token;
        $cookies.put("Authorization", userInfo);
        $http.defaults.headers.common = {"Authorization": userInfo};

        // Set the new username in the rootScope<commit_msg>Update signup controller to use dataService<commit_after>;(function() {  // IIFE
  'use strict';

  angular
    .module('brewKeeper')
    .controller('SignupController', SignupController);

  SignupController.$inject = ['$location', '$rootScope', 'dataService'];
  
  function SignupController($location, $rootScope, dataService) {
    var signupVm = this;
    signupVm.users = {};
    signupVm.signupButton = signupButton;

    activate();

    ////////////////////////////////////////////////////////////////////////////
    // FUNCTIONS //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////

    /**
     * Prepare the page.
     */
    function activate() {
      // Hide mismatch error when user acknowledges
      $("button.password-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.register-modal").addClass("inactive");
      });

      // Hide welcome modal when user acknowledges
      $("button.welcome-fail").on("click", function() {
        $(".wrapper").removeClass("openerror");
        $("section.welcome-modal").addClass("inactive");
      });
    }

    /**
     * If passwords match, attempt to create the user.
     *
     * @param {boolean} mismatch Were the two passwords entered different?
     */
    function signupButton(mismatch) {
      if (mismatch) {
        // Show user mismatch error
        $(".wrapper").addClass("openerror");
        $("section.register-modal").removeClass("inactive");
        return;
      }

      dataService.post('/api/register/', signupVm.users)
        .then(successCallback, errorCallback);

      function errorCallback(response) {
        // TODO: Replace alert with modal
        if (response.status < 500) {
          alert("Ooh, sorry! That username already exists. " +
            "Please choose a different one.");
        } else {
          alert("Apologies, but we have encountered an error.");
        }
      }

      function successCallback(response) {
        // Set the returned token in the cookies/headers to allow user to remain
        // logged in
        var authToken = "Token " + response.data.token;
        dataService.setCredentials(authToken);

        // Set the new username in the rootScope
{'fraction_non_alphanumeric': 0.21615302869287992, 'fraction_numerical': 0.0012752391073326248, 'mean_word_length': 1.8196524865188737, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5304496', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1149, 'n_words': 287}