<commit_before>    zappa = require 'zappajs'
    config = require '/usr/local/etc/proxy.json'
    crypto = require 'crypto'
    create_user_account = require './create_user_account'

    acceptLanguage = require 'accept-language'

    zappa config, ->

      acceptLanguage.codes config.languages

      @use 'logger'

      bodyParser = @express.bodyParser()

      express_store = do =>
        ExpressRedisStore = require('connect-redis') @express
        new ExpressRedisStore()

      @use 'cookieParser'
      @use session:
        store: express_store
        secret: config.session_secret

      @include './connect'

Language
========

      @get '/_app/language', ->
        @json acceptLanguage.parse @req.get 'accept-language'

Session
=======

      @get '/_app/session', ->
        @json
          user: @session.user
          roles: @session.roles

Twitter connect
===============

We authenticate using Twitter; our internal username starts with "twitter:".

      @post '/_app/twitter-connect', [bodyParser], ->

        # pas besoin de mail de validation
        @twitter_connect (ok) =>
          if not ok then return @json error:'failed'

          username = "twitter:#{twitter_userid}"
          create_user_account {username,validated:true}, (error,uuid) =>
            @session.user = uuid
            @session.roles = ['user']
            @session.token = make_token @session

            @json
              ok: true
              uuid: uuid

Facebook connect
================

We authenticate using Facebook; our internal username starts with "facebook:".

      @post '/_app/facebook-connect', [bodyParser], ->

        username = @body.authResponse.userID

        # pas besoin de mail de validation
        @facebook_connect (ok) =>
          if not ok then return @json error:'failed'

          username = "facebook:#{twitter_userid}"
          create_user_account {username,validated:true}, (error,uuid) =>
            @session.user = username
            @session.roles = ['user']
            @session.token = make_token @session

            @json
              ok: true
              uuid: uuid

Local connect
=============

We authenticate using CouchDB; our internal username is an email adress (and identical to the CouchDB username).

      @post '/_app/local-connect', [bodyParser], ->

        @local_connect (ok) =>

          if not ok then return @json error:'failed'

          username = @body.username
          password = @body.password

          create_user_account {username,password}, (error,uuid) =>
            @session.user = username<commit_msg>`user` as sent to the client is the uuid; `name` is only kept internally<commit_after>    zappa = require 'zappajs'
    config = require '/usr/local/etc/proxy.json'
    crypto = require 'crypto'
    create_user_account = require './create_user_account'

    acceptLanguage = require 'accept-language'

    zappa config, ->

      acceptLanguage.codes config.languages

      @use 'logger'

      bodyParser = @express.bodyParser()

      express_store = do =>
        ExpressRedisStore = require('connect-redis') @express
        new ExpressRedisStore()

      @use 'cookieParser'
      @use session:
        store: express_store
        secret: config.session_secret

      @include './connect'

Language
========

      @get '/_app/language', ->
        @json acceptLanguage.parse @req.get 'accept-language'

Session
=======

      @get '/_app/session', ->
        @json
          user: @session.user
          roles: @session.roles

Twitter connect
===============

We authenticate using Twitter; our internal username starts with "twitter:".

      @post '/_app/twitter-connect', [bodyParser], ->

        # pas besoin de mail de validation
        @twitter_connect (ok) =>
          if not ok then return @json error:'failed'

          username = "twitter:#{twitter_userid}"
          create_user_account {username,validated:true}, (error,uuid) =>
            @session.name = username
            @session.user = uuid
            @session.roles = ['user']
            @session.token = make_token @session

            @json
              ok: true
              uuid: uuid

Facebook connect
================

We authenticate using Facebook; our internal username starts with "facebook:".

      @post '/_app/facebook-connect', [bodyParser], ->

        username = @body.authResponse.userID

        # pas besoin de mail de validation
        @facebook_connect (ok) =>
          if not ok then return @json error:'failed'

          username = "facebook:#{twitter_userid}"
          create_user_account {username,validated:true}, (error,uuid) =>
            @session.name = username
            @session.user = uuid
            @session.roles = ['user']
            @session.token = make_token @session

            @json
              ok: true
              uuid: uuid

Local connect
=============

We authenticate using CouchDB; our internal username is an email adress (and identical to the CouchDB username).

      @post '/_app/local-connect', [bodyParser], ->

        @local_connect (ok) =>

          if not ok then return @json error:'failed'

          username = @body.username
          password = <PASSWORD>

          create_user_account {username,password}, (error,uuid) =>
            @session.name = username
            @session.user = uuid
{'fraction_non_alphanumeric': 0.12262392843831532, 'fraction_numerical': 0.0, 'mean_word_length': 2.266585514303104, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2317506', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1404, 'n_words': 402}