UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

65 lines (57 loc) 1.83 kB
// Generated by CoffeeScript 2.5.1 (function() { //######################################################################## // This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. // License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details //######################################################################## /* A cached function from remember_me cookie to account_id. Cache expires after 60s, to stop accepting requests from user in case they invalidate their cookie. */ var Cache, NOT_SIGNED_IN, auth, remember_me_cache; Cache = require('lru-cache'); auth = require('./auth'); // Do NOT change this - this exact string is assumed in smc-util/client ({NOT_SIGNED_IN} = require("smc-util/consts")); remember_me_cache = new Cache({ max: 5000, maxAge: 60000 }); exports.get_account_id = function(database, remember_me, cb) { var account_id, err, hash, x; if (remember_me == null) { cb(NOT_SIGNED_IN); return; } account_id = remember_me_cache.get(remember_me); if (account_id) { cb(void 0, account_id); return; } x = remember_me.split('$'); try { hash = auth.generate_hash(x[0], x[1], x[2], x[3]); } catch (error) { err = error; cb(NOT_SIGNED_IN); return; } return database.get_remember_me({ hash: hash, cb: function(err, signed_in_mesg) { if (err) { cb(err); return; } remember_me_cache.set(remember_me, signed_in_mesg != null ? signed_in_mesg.account_id : void 0); if (signed_in_mesg == null) { return cb(NOT_SIGNED_IN); } else { return cb(void 0, signed_in_mesg.account_id); } } }); }; }).call(this); //# sourceMappingURL=user-remember-me.js.map