Path: blob/master/src/packages/frontend/client/password-reset.ts
1503 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { QueryParams } from "../misc/query-params";6import { appBasePath } from "@cocalc/frontend/customize/app-base-path";78const NAME = `${encodeURIComponent(appBasePath)}PWRESET`;910import Cookies from "universal-cookie";11const cookies = new Cookies();1213export function reset_password_key(): string | undefined {14// we set a temporary session cookie earlier15const forgot_cookie = cookies.get(NAME);16if (forgot_cookie != null) {17// we immediately get rid of the cookie with the secret token18cookies.remove(NAME, { path: "/" });19return forgot_cookie.toLowerCase();20} else {21// some mail transport agents will uppercase the URL -- see https://github.com/sagemathinc/cocalc/issues/29422const forgot = QueryParams.get("forgot");23if (forgot && typeof forgot == "string") {24return forgot.toLowerCase();25}26}27}282930