CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/client/password-reset.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { QueryParams } from "../misc/query-params";
7
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
8
9
const NAME = `${encodeURIComponent(appBasePath)}PWRESET`;
10
11
import Cookies from "universal-cookie";
12
const cookies = new Cookies();
13
14
export function reset_password_key(): string | undefined {
15
// we set a temporary session cookie earlier
16
const forgot_cookie = cookies.get(NAME);
17
if (forgot_cookie != null) {
18
// we immediately get rid of the cookie with the secret token
19
cookies.remove(NAME, { path: "/" });
20
return forgot_cookie.toLowerCase();
21
} else {
22
// some mail transport agents will uppercase the URL -- see https://github.com/sagemathinc/cocalc/issues/294
23
const forgot = QueryParams.get("forgot");
24
if (forgot && typeof forgot == "string") {
25
return forgot.toLowerCase();
26
}
27
}
28
}
29
30