Make token fs based

This commit is contained in:
Juan Cruz Viotti 2014-11-14 14:28:58 -04:00
parent 175e48d8ca
commit 14bacbc4a4

View File

@ -1,18 +1,20 @@
# TODO: Persist token in a secure manner
data = require('../data/data')
token = null
TOKEN_KEY = 'token'
exports.saveToken = (newToken, callback) ->
token = newToken
return callback(null, token)
data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
exports.hasToken = (callback) ->
return callback(token?)
data.has(TOKEN_KEY, callback)
exports.getToken = (callback) ->
return callback(null, token or undefined)
data.get(TOKEN_KEY, encoding: 'utf8', callback)
exports.clearToken = (callback) ->
token = null
return callback?(null)
data.has TOKEN_KEY, (hasToken) ->
if hasToken
return data.remove(TOKEN_KEY, callback)
else
return callback?()