Store session cookie in local storage

This commit is contained in:
Andrew Miner
2016-04-06 18:29:08 -07:00
parent 76ae358878
commit cdb2989c0a
5 changed files with 44 additions and 15 deletions
+9 -5
View File
@@ -5,6 +5,8 @@
# All rights reserved.
#
fs = require 'fs'
EXTERNAL_LIBS = [
'backbone'
'jquery'
@@ -223,6 +225,9 @@ module.exports = (grunt)->
grunt.registerTask 'upload:staging', 'upload the project the staging Amazon S3 environment',
['dist', 'script:s3_upload:staging']
grunt.registerTask 'useLocalDeps', 'use local dependencies instead of NPM dependencies',
['script:use_local_deps']
# Code Tasks #######################################################################################################
grunt.registerTask 'browserify:external', "Bundle 3rd-party libraries used in the app", ->
@@ -259,11 +264,6 @@ module.exports = (grunt)->
console.log error if error?
done()
grunt.registerTask 'use-local-deps', ->
grunt.file.mkdir './node_modules'
grunt.file.delete './node_modules/crafting-guide-common', force:true
fs.symlinkSync '../../crafting-guide-common/', './node_modules/crafting-guide-common'
# Script Tasks #####################################################################################################
grunt.registerTask 'script:deploy:prod', "deploy code by copying to the production branch", ->
@@ -290,6 +290,10 @@ module.exports = (grunt)->
done = this.async()
grunt.util.spawn cmd:'./scripts/start', opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:use_local_deps', "use local dependencies instead of NPM dependencies", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/use_local_deps', opts:{stdio:'inherit'}, (error)-> done(error)
# Command-Line Argument Processing #################################################################################
args = process.argv[..]
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
if [[ -d "../crafting-guide-common" ]]; then
rm -rf ./node_modules/crafting-guide-common &>/dev/null
mkdir -p node_modules
cd node_modules
ln -s ../../crafting-guide-common
fi
+21 -5
View File
@@ -25,8 +25,7 @@ Backbone.$ = $
global.logger = new Logger
marked = require 'marked'
marked.setOptions
sanitize: true
marked.setOptions sanitize: true
########################################################################################################################
@@ -53,18 +52,35 @@ switch global.hostName
########################################################################################################################
Storage = require './storage'
storage = new Storage storage:global.localStorage
########################################################################################################################
{CraftingGuideClient} = require 'crafting-guide-common'
client = _.extend new CraftingGuideClient(baseUrl:apiBaseUrl), Backbone.Events
client.onStatusChanged = (c, oldStatus, newStatus)->
client = new CraftingGuideClient(
baseUrl: apiBaseUrl
session: storage.load CraftingGuideClient.SESSION
onSessionChanged: (client, oldSession, newSession)->
logger.info "Updated server session data"
storage.store CraftingGuideClient.SESSION, session
client.trigger 'change:session', client, oldSession, newSession
client.trigger 'change', client
onStatusChanged: (client, oldStatus, newStatus)->
logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}"
client.trigger 'change:status', client, oldStatus, newStatus
client.trigger 'change', client
)
_(client).extend Backbone.Events
client.checkStatus()
########################################################################################################################
SiteController = require './site/site_controller'
global.site = site = new SiteController client: client
global.site = site = new SiteController client:client, storage:storage
site.render()
site.loadDefaultModPack()
site.loadCurrentUser()
+3 -2
View File
@@ -14,13 +14,14 @@ ImageLoader = require './image_loader'
Mod = require '../models/game/mod'
ModPack = require '../models/game/mod_pack'
Router = require './router'
Storage = require './storage'
########################################################################################################################
module.exports = class SiteController extends BaseController
constructor: (options={})->
if not options.client? then throw new Error 'options.client is required'
if not options.storage? then throw new Error 'options.storage is required'
options.el = 'html'
super options
@@ -28,7 +29,7 @@ module.exports = class SiteController extends BaseController
@imageLoader = new ImageLoader defaultUrl:'/images/unknown.png'
@modPack = new ModPack
@router = new Router this
@storage = new Storage storage:global.localStorage
@storage = options.storage
@_currentPage = null
@_currentPageController = null