Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/user-remember-me.coffee
Views: 687
#########################################################################1# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2# License: MS-RSL – see LICENSE.md for details3#########################################################################45###6A cached function from remember_me cookie to account_id.7Cache expires after 60s, to stop accepting requests from user8in case they invalidate their cookie.9###1011Cache = require('lru-cache')1213auth = require('./auth')14generateHash =require("@cocalc/server/auth/hash").default;1516# Do NOT change this - this exact string is assumed in @cocalc/util/client17{NOT_SIGNED_IN} = require("@cocalc/util/consts")1819remember_me_cache = new Cache(max:5000, ttl:60000)2021exports.get_account_id = (database, remember_me, cb) ->22if not remember_me?23cb(NOT_SIGNED_IN)24return25account_id = remember_me_cache.get(remember_me)26if account_id27cb(undefined, account_id)28return29x = remember_me.split('$')30try31hash = generateHash(x[0], x[1], x[2], x[3])32catch err33cb(NOT_SIGNED_IN)34return35database.get_remember_me36hash : hash37cb : (err, signed_in_mesg) ->38if err39cb(err)40return41remember_me_cache.set(remember_me, signed_in_mesg?.account_id)42if not signed_in_mesg?43cb(NOT_SIGNED_IN)44else45cb(undefined, signed_in_mesg.account_id)4647