<commit_before>    config = require '/usr/local/etc/proxy.json'
    crypto = require 'crypto'
    request = require 'superagent'
    UUID = require 'uuid'
    PouchDB = require 'pouchdb'
    USER_PREFIX = 'org.couchdb.user'

    # TODO find promise-based way of doing the pouch stuff (no error/res stuff.. BUT need yield support in coffeescript)

These access CouchDB with elevated priviledges.

    auth_db = new PouchDB [config.base_url,'_users']
    shared_db = new PouchDB [config.base_url,'public']

    module.exports = create_user_account = (options,next) ->
      {username,password,validated} = options

      auth_id = [USER_PREFIX,username].join ':'

      create_user (error,uuid,created,validated) ->
        if error? then return next {error}
        # Shortcut
        if created then return next null, uuid

        create_user_db username, uuid, (error) ->
          if error? then return next {error}

          mark_created = (auth_id,next) ->
            auth_db.get auth_id, (error,doc) ->
              if error then return next {error}

              doc.created = true

              auth_db.put doc, (error) ->
                if error then return next {error}
                next null, uuid

          if validated or options.validated
            mark_created next
          else
            send_validation_email username, (error) ->
              if error? then return next {error}
              mark_created next


    # Note: properly created record will have a 'created:true' field.
    create_user = (auth_id,next) ->
      auth_db.get auth_id, (error,doc) ->
        # Shortcut the case where the account was created fine.
        if doc?.created
          return next null, doc.user_uuid, true, doc.validated

        if error?
          # FIXME Assumes it is because the document doesn't exist.
          console.dir auth_db_get:error
          uuid = new UUID()
        else
          # Document exists, but creation failed for some reason.
          uuid = doc.user_uuid

        user_record =
          type: user
          _id: auth_id
          _rev: doc?._rev
          user: username
          password: password<commit_msg>corrected typo<commit_after>    config = require '/usr/local/etc/proxy.json'
    crypto = require 'crypto'
    request = require 'superagent'
    UUID = require 'uuid'
    PouchDB = require 'pouchdb'
    USER_PREFIX = 'org.couchdb.user'

    # TODO find promise-based way of doing the pouch stuff (no error/res stuff.. BUT need yield support in coffeescript)

These access CouchDB with elevated priviledges.

    auth_db = new PouchDB [config.base_url,'_users']
    shared_db = new PouchDB [config.base_url,'public']

    module.exports = create_user_account = (options,next) ->
      {username,password,validated} = options

      auth_id = [USER_PREFIX,username].join ':'

      create_user (error,uuid,created,validated) ->
        if error? then return next {error}
        # Shortcut
        if created then return next null, uuid

        create_user_db username, uuid, (error) ->
          if error? then return next {error}

          mark_created = (auth_id,next) ->
            auth_db.get auth_id, (error,doc) ->
              if error then return next {error}

              doc.created = true

              auth_db.put doc, (error) ->
                if error then return next {error}
                next null, uuid

          if validated or options.validated
            mark_created next
          else
            send_validation_email username, (error) ->
              if error? then return next {error}
              mark_created next


    # Note: properly created record will have a 'created:true' field.
    create_user = (auth_id,next) ->
      auth_db.get auth_id, (error,doc) ->
        # Shortcut the case where the account was created fine.
        if doc?.created
          return next null, doc.user_uuid, true, doc.validated

        if error?
          # FIXME Assumes it is because the document doesn't exist.
          console.dir auth_db_get:error
          uuid = new UUID()
        else
          # Document exists, but creation failed for some reason.
          uuid = doc.user_uuid

        user_record =
          type: 'user'
          _id: auth_id
          _rev: doc?._rev
          user: username
          password: password
{'fraction_non_alphanumeric': 0.08204655450564646, 'fraction_numerical': 0.0, 'mean_word_length': 2.034965034965035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '804706', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1188, 'n_words': 390}