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/next/components/auth/password-reset.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Button, Input } from "antd";6import { useState } from "react";78import { Icon } from "@cocalc/frontend/components/icon";9import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";10import Contact from "components/landing/contact";11import A from "components/misc/A";12import apiPost from "lib/api/post";13import useCustomize from "lib/use-customize";1415import AuthPageContainer from "./fragments/auth-page-container";1617export default function PasswordReset() {18const { siteName } = useCustomize();19const [email, setEmail] = useState<string>("");20const [resetting, setResetting] = useState<boolean>(false);21const [error, setError] = useState<string>("");22const [success, setSuccess] = useState<string>("");2324async function resetPassword() {25if (resetting) return;26try {27setError("");28setSuccess("");29setResetting(true);30const result = await apiPost("/auth/password-reset", { email });31if (result.success) {32setEmail("");33setSuccess(result.success);34}35} catch (err) {36setError(`${err}`);37} finally {38setResetting(false);39}40}4142function renderFooter() {43return (44<>45<p>46Remember your password? <A href="/auth/sign-in">Sign In</A>47</p>48<p>49Don't have an account? <A href="/auth/sign-up">Sign Up</A>50</p>51You can also {" "}52<A href="/auth/try">try {siteName} without creating an account</A>53</>54);55}5657function renderError() {58return error && (59<div style={{ fontSize: "12pt" }}>60<b>{error}</b>61<br/>62If you are stuck, please <Contact lower/>.63</div>64);65}6667return (68<AuthPageContainer69error={renderError()}70footer={renderFooter()}71title={`Reset Your ${siteName} Password`}72>73<div style={{ margin: "10px 0" }}>74Enter your {siteName} account's email address and we will email a75password reset link to you.76</div>77<form>78<Input79style={{ fontSize: "13pt" }}80autoFocus81placeholder="Enter your email address"82autoComplete="username"83value={email}84onChange={(e) => {85setEmail(e.target.value);86setError("");87setSuccess("");88}}89onPressEnter={(e) => {90e.preventDefault();91if (resetting || !isValidEmailAddress(email)) return;92resetPassword();93}}94/>95<Button96disabled={!email || resetting || !isValidEmailAddress(email) || !!error}97shape="round"98size="large"99type="primary"100style={{ width: "100%", marginTop: "20px" }}101onClick={resetPassword}102>103{resetting ? (104<>105<Icon name="spinner" spin/> Sending password reset email...106</>107) : !email || !isValidEmailAddress(email) || error ? (108"Enter your email address."109) : (110"Send password reset email"111)}112</Button>113</form>114{success && (115<Alert116style={{ marginTop: "20px" }}117message={<b>Success</b>}118description={<div style={{ fontSize: "12pt" }}>{success}</div>}119type="success"120showIcon121/>122)}123</AuthPageContainer>124);125}126127128