<commit_before>'use strict';

/**
 * User service. Wraps fetch to/from server and local storage to deal
 * with information about the user/player.
 * 
 * @ngdoc service
 * @name playerApp.user
 * @description
 * # user
 * Factory in the playerApp.
 */
angular.module('playerApp')
  .factory('user',
  [          '$log','$state','API','$http',
    function ($log,  $state,  API,  $http) {

    var user = {};
    
    user.profile = {};
    
    user.rules = {}
    user.rules.nameRule = "At least 3 characters, no spaces.";
    user.rules.namePattern = /^\w{3,}$/;
    user.rules.colorRule = "At least 3 characters, no spaces.";
    user.rules.colorPattern = /^\w{3,}$/;
    
    user.load = function(id,name) {
    	
      $log.debug('quering token %o',localStorage.token);	
    	
	  //we're using the id from the token introspect as our player db id.
	  user.profile.id = id;
	
      // Load the user's information from the DB and/or session
      // Load needs to come from the Auth token
      var playerURL = API.PROFILE_URL + user.profile.id;
      var parameters = {};
      var q;

      // Fetch data about the user
      $log.debug('fetch data from %o', playerURL);
      q = $http({
          method : 'GET',
          url : playerURL,
          cache : false,
          params : parameters
      }).then(function(response) {
          $log.debug(response.status + ' ' + response.statusText + ' ' + playerURL);

          var tmp = angular.fromJson(response.data);
          user.profile.name = tmp.name;
          user.profile.favoriteColor = tmp.favoriteColor;
          
          return true;          
      }, function(response) {
        $log.debug(response.status + ' ' + response.statusText + ' ' + playerURL);

        // go to the sad room.. (Can't find the player information)
        // or back to the login/registration screen? or.. 
        user.profile.name = name;
        return false;
      });
      
      return q;<commit_msg>Convert usernames with spaces from fb/twttr into _ names<commit_after>'use strict';

/**
 * User service. Wraps fetch to/from server and local storage to deal
 * with information about the user/player.
 * 
 * @ngdoc service
 * @name playerApp.user
 * @description
 * # user
 * Factory in the playerApp.
 */
angular.module('playerApp')
  .factory('user',
  [          '$log','$state','API','$http',
    function ($log,  $state,  API,  $http) {

    var user = {};
    
    user.profile = {};
    
    user.rules = {}
    user.rules.nameRule = "At least 3 characters, no spaces.";
    user.rules.namePattern = /^\w{3,}$/;
    user.rules.colorRule = "At least 3 characters, no spaces.";
    user.rules.colorPattern = /^\w{3,}$/;
    
    user.load = function(id,name) {
    	
      $log.debug('quering token %o',localStorage.token);	
    	
	  //we're using the id from the token introspect as our player db id.
	  user.profile.id = id;
	
      // Load the user's information from the DB and/or session
      // Load needs to come from the Auth token
      var playerURL = API.PROFILE_URL + user.profile.id;
      var parameters = {};
      var q;

      // Fetch data about the user
      $log.debug('fetch data from %o', playerURL);
      q = $http({
          method : 'GET',
          url : playerURL,
          cache : false,
          params : parameters
      }).then(function(response) {
          $log.debug(response.status + ' ' + response.statusText + ' ' + playerURL);

          var tmp = angular.fromJson(response.data);
          user.profile.name = tmp.name;
          user.profile.favoriteColor = tmp.favoriteColor;
          
          return true;          
      }, function(response) {
        $log.debug(response.status + ' ' + response.statusText + ' ' + playerURL);

        // go to the sad room.. (Can't find the player information)
        // or back to the login/registration screen? or.. 
        user.profile.name = name.replace(/ /g , '_');
        return false;
      });
      
      return q;
{'fraction_non_alphanumeric': 0.13438834463702587, 'fraction_numerical': 0.002009545340366742, 'mean_word_length': 2.0772797527047913, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7144950', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1174, 'n_words': 333}