mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 07:38:20 -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
|
||||
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) ->
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue