Deferring user creation until after the client app loads, to try and lower the massive number of anonymous users that are created.

This commit is contained in:
Scott Erickson 2015-01-05 14:43:20 -08:00
parent fb29bfa71e
commit ba1ffe194c
2 changed files with 19 additions and 23 deletions

View file

@ -1,5 +1,5 @@
Backbone.Mediator.setValidationEnabled false
app = require 'core/application'
app = null
channelSchemas =
'auth': require 'schemas/subscriptions/auth'
@ -21,6 +21,15 @@ definitionSchemas =
'misc': require 'schemas/definitions/misc'
init = ->
return if app
if not window.userObject._id
$.ajax('/auth/whoami', {success: (res) ->
window.userObject = res
init()
})
return
app = require 'core/application'
setupConsoleLogging()
watchForErrors()
setUpIOSLogging()
@ -34,8 +43,6 @@ init = ->
handleNormalUrls()
setUpMoment() # Set up i18n for moment
module.exports.init = init = _.once init
handleNormalUrls = ->
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
$(document).on 'click', "a[href^='/']", (event) ->

View file

@ -127,26 +127,15 @@ setupJavascript404s = (app) ->
setupFallbackRouteToIndex = (app) ->
app.all '*', (req, res) ->
if req.user
sendMain(req, res)
# Disabling for HoC
# req.user.set('lastIP', req.connection.remoteAddress)
# req.user.save()
else
user = auth.makeNewUser(req)
makeNext = (req, res) -> -> sendMain(req, res)
next = makeNext(req, res)
auth.loginUser(req, res, user, false, next)
sendMain = (req, res) ->
fs.readFile path.join(__dirname, 'public', 'main.html'), 'utf8', (err, data) ->
log.error "Error modifying main.html: #{err}" if err
# insert the user object directly into the html so the application can have it immediately. Sanitize </script>
data = data.replace('"userObjectTag"', JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/'))
res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
res.header 'Pragma', 'no-cache'
res.header 'Expires', 0
res.send 200, data
fs.readFile path.join(__dirname, 'public', 'main.html'), 'utf8', (err, data) ->
log.error "Error modifying main.html: #{err}" if err
# insert the user object directly into the html so the application can have it immediately. Sanitize </script>
user = if req.user then JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/') else '{}'
data = data.replace('"userObjectTag"', user)
res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
res.header 'Pragma', 'no-cache'
res.header 'Expires', 0
res.send 200, data
setupFacebookCrossDomainCommunicationRoute = (app) ->
app.get '/channel.html', (req, res) ->