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
+24 -8
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)->
logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}"
client.trigger 'change:status', client, oldStatus, newStatus
client.trigger 'change', client
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