mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
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:
parent
fb29bfa71e
commit
ba1ffe194c
2 changed files with 19 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
Backbone.Mediator.setValidationEnabled false
|
Backbone.Mediator.setValidationEnabled false
|
||||||
app = require 'core/application'
|
app = null
|
||||||
|
|
||||||
channelSchemas =
|
channelSchemas =
|
||||||
'auth': require 'schemas/subscriptions/auth'
|
'auth': require 'schemas/subscriptions/auth'
|
||||||
|
@ -21,6 +21,15 @@ definitionSchemas =
|
||||||
'misc': require 'schemas/definitions/misc'
|
'misc': require 'schemas/definitions/misc'
|
||||||
|
|
||||||
init = ->
|
init = ->
|
||||||
|
return if app
|
||||||
|
if not window.userObject._id
|
||||||
|
$.ajax('/auth/whoami', {success: (res) ->
|
||||||
|
window.userObject = res
|
||||||
|
init()
|
||||||
|
})
|
||||||
|
return
|
||||||
|
|
||||||
|
app = require 'core/application'
|
||||||
setupConsoleLogging()
|
setupConsoleLogging()
|
||||||
watchForErrors()
|
watchForErrors()
|
||||||
setUpIOSLogging()
|
setUpIOSLogging()
|
||||||
|
@ -34,8 +43,6 @@ init = ->
|
||||||
handleNormalUrls()
|
handleNormalUrls()
|
||||||
setUpMoment() # Set up i18n for moment
|
setUpMoment() # Set up i18n for moment
|
||||||
|
|
||||||
module.exports.init = init = _.once init
|
|
||||||
|
|
||||||
handleNormalUrls = ->
|
handleNormalUrls = ->
|
||||||
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
|
# http://artsy.github.com/blog/2012/06/25/replacing-hashbang-routes-with-pushstate/
|
||||||
$(document).on 'click', "a[href^='/']", (event) ->
|
$(document).on 'click', "a[href^='/']", (event) ->
|
||||||
|
|
|
@ -127,22 +127,11 @@ setupJavascript404s = (app) ->
|
||||||
|
|
||||||
setupFallbackRouteToIndex = (app) ->
|
setupFallbackRouteToIndex = (app) ->
|
||||||
app.all '*', (req, res) ->
|
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) ->
|
fs.readFile path.join(__dirname, 'public', 'main.html'), 'utf8', (err, data) ->
|
||||||
log.error "Error modifying main.html: #{err}" if err
|
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>
|
# 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, '\\/'))
|
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 'Cache-Control', 'no-cache, no-store, must-revalidate'
|
||||||
res.header 'Pragma', 'no-cache'
|
res.header 'Pragma', 'no-cache'
|
||||||
res.header 'Expires', 0
|
res.header 'Expires', 0
|
||||||
|
|
Loading…
Reference in a new issue