<commit_before>define(function(require) {
  'use strict';

  var q = require('q');
  var validator = require('validator');

  var PF = require('js/app/obj');
  var logger = PF.logger.get('root/js/apps/user/entities');

  PF.module('UserApp.Entities', function(Entities, PF, Backbone, Marionette, $, _) {
    require('js/common/base_entities');

    Entities.User = PF.Entities.PFDatabaseModel.extend({
      __name: 'User',
      urlRoot: '/api/user/user',
      validate: function(attrs, options) {
        var errors = {};
        if(!validator.isEmail(attrs.email)) {
          attrs['email'] = "'" + attrs.email + "' - invalid email address format";
        }

        if(attrs.password && !validators.isAlphanumeric(attrs.password)) {
          attrs["password"] = "Passwords must be letters and numbers only";
        }

        return errors;
      }
    });

    var API = {
      get_promise: function(user_id) {
        logger.trace('API.get_promise -- enter');
        var deferred = q.defer();
        var user = new Entities.User({ id: user_id });
        user.fetch({
          success: function(user_model) { deferred.resolve(user_model); },
          error: function() { deferred.resolve(undefined); }
        });
        return deferred.promise;
      }
    };

    PF.reqres.setHandler('userapp:entities:user', function() {
      return API.get_promise();
    });
  });
});<commit_msg>client/js/apps/user/entities.js - tweaked validators, return PF.UserApp.Entities from module define call<commit_after>define(function(require) {
  'use strict';

  var q = require('q');
  var validator = require('validator');

  var PF = require('js/app/obj');
  var logger = PF.logger.get('root/js/apps/user/entities');

  PF.module('UserApp.Entities', function(Entities, PF, Backbone, Marionette, $, _) {
    require('js/common/base_entities');

    Entities.User = PF.Entities.PFDatabaseModel.extend({
      __name: 'User',
      urlRoot: '/api/user/user',
      validate: function(attrs, options) {
        var errors = {};
        if(!validator.isEmail(attrs.email)) {
          attrs['email'] = '"' + attrs.email + '" - invalid email address format';
        }

        if(attrs.password && !validator.isAlphanumeric(attrs.password)) {
          attrs['password'] = 'Passwords must be letters and numbers only (and at least 8 characters long)';
        }
        else if(attrs.password && !validator.isLength(attrs.password, 8)) {
          attrs['password'] = 'Passwords must be at least 8 characters long (letters and numbers only)';
        }

        return errors;
      }
    });

    var API = {
      get_promise: function(user_id) {
        logger.trace('API.get_promise -- enter');
        var deferred = q.defer();
        var user = new Entities.User({ id: user_id });
        user.fetch({
          success: function(user_model) { deferred.resolve(user_model); },
          error: function() { deferred.resolve(undefined); }
        });
        return deferred.promise;
      }
    };

    PF.reqres.setHandler('userapp:entities:user', function() {
      return API.get_promise();
    });
  });

  return PF.UserApp.Entities;
});
{'fraction_non_alphanumeric': 0.15328467153284672, 'fraction_numerical': 0.000952078705172961, 'mean_word_length': 2.669383003492433, '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': '506206', 'n_tokens_mistral': 967, 'n_tokens_neox': 950, 'n_words': 191}