2014-11-26 16:56:52 +00:00
|
|
|
data = require('../data/data')
|
2014-10-31 19:19:16 +00:00
|
|
|
|
2014-11-14 18:28:58 +00:00
|
|
|
TOKEN_KEY = 'token'
|
2014-10-31 19:19:16 +00:00
|
|
|
|
2014-11-07 18:51:54 +00:00
|
|
|
exports.saveToken = (newToken, callback) ->
|
2014-11-14 18:28:58 +00:00
|
|
|
data.set(TOKEN_KEY, newToken, encoding: 'utf8', callback)
|
2014-10-31 19:19:16 +00:00
|
|
|
|
2014-11-07 18:51:54 +00:00
|
|
|
exports.hasToken = (callback) ->
|
2014-11-14 18:28:58 +00:00
|
|
|
data.has(TOKEN_KEY, callback)
|
2014-10-31 19:19:16 +00:00
|
|
|
|
2014-11-07 18:51:54 +00:00
|
|
|
exports.getToken = (callback) ->
|
2014-11-14 18:28:58 +00:00
|
|
|
data.get(TOKEN_KEY, encoding: 'utf8', callback)
|
2014-10-31 19:19:16 +00:00
|
|
|
|
2014-11-07 18:51:54 +00:00
|
|
|
exports.clearToken = (callback) ->
|
2014-11-14 18:28:58 +00:00
|
|
|
data.has TOKEN_KEY, (hasToken) ->
|
|
|
|
if hasToken
|
|
|
|
return data.remove(TOKEN_KEY, callback)
|
|
|
|
else
|
2014-11-14 19:50:29 +00:00
|
|
|
return callback?(null)
|