2014-05-15 12:16:20 -04:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
redis = require('redis')
|
|
|
|
rclient = redis.createClient(Settings.redis.web.port, Settings.redis.web.host)
|
|
|
|
rclient.auth(Settings.redis.web.password)
|
|
|
|
uuid = require("node-uuid")
|
|
|
|
|
2014-05-15 12:58:25 -04:00
|
|
|
ONE_HOUR_IN_S = 60 * 60
|
|
|
|
|
|
|
|
buildKey = (token)-> return "password_token:#{token}"
|
2014-05-15 12:16:20 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getNewToken: (user_id, callback)->
|
|
|
|
token = uuid.v4()
|
|
|
|
multi = rclient.multi()
|
2014-05-15 12:58:25 -04:00
|
|
|
multi.set buildKey(token), user_id
|
|
|
|
multi.expire buildKey(token), ONE_HOUR_IN_S
|
2014-05-15 12:16:20 -04:00
|
|
|
multi.exec (err)->
|
|
|
|
callback(err, token)
|
|
|
|
|
|
|
|
getUserIdFromToken: (token, callback)->
|
2014-05-15 12:20:42 -04:00
|
|
|
multi = rclient.multi()
|
2014-05-15 12:58:25 -04:00
|
|
|
multi.get buildKey(token)
|
|
|
|
multi.del buildKey(token)
|
2014-05-15 12:20:42 -04:00
|
|
|
multi.exec (err, results)->
|
|
|
|
callback err, results[0]
|
|
|
|
|