"use strict";
exports.id = 5863;
exports.ids = [5863];
exports.modules = {

/***/ 565863:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ SignIn)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(807772);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var components_landing_contact__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(892771);
/* harmony import */ var components_logo_square__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(961429);
/* harmony import */ var components_misc_A__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(940981);
/* harmony import */ var lib_api_post__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(194184);
/* harmony import */ var lib_use_customize__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(117682);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(616689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var react_google_recaptcha_v3__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(271704);
/* harmony import */ var react_google_recaptcha_v3__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(react_google_recaptcha_v3__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _shared__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(402391);
/* harmony import */ var _sso__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(366009);
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 











function SignIn(props) {
    const { reCaptchaKey  } = (0,lib_use_customize__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z)();
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(react_google_recaptcha_v3__WEBPACK_IMPORTED_MODULE_9__.GoogleReCaptchaProvider, {
        reCaptchaKey: reCaptchaKey,
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(SignIn0, {
            ...props
        })
    });
};
function SignIn0(props) {
    const { minimal =false , onSuccess  } = props;
    const { anonymousSignup , reCaptchaKey , siteName , strategies  } = (0,lib_use_customize__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z)();
    const { 0: email , 1: setEmail  } = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)("");
    const { 0: password , 1: setPassword  } = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)("");
    const { 0: signingIn , 1: setSigningIn  } = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)(false);
    const { 0: error , 1: setError  } = (0,react__WEBPACK_IMPORTED_MODULE_8__.useState)("");
    const { executeRecaptcha  } = (0,react_google_recaptcha_v3__WEBPACK_IMPORTED_MODULE_9__.useGoogleReCaptcha)();
    const haveSSO = strategies != null && strategies.length > 0;
    // based on email: if user has to sign up via SSO, this will tell which strategy to use.
    const requiredSSO = (0,_sso__WEBPACK_IMPORTED_MODULE_11__/* .useRequiredSSO */ .Ke)(strategies, email);
    async function signIn() {
        if (signingIn) return;
        setError("");
        try {
            setSigningIn(true);
            let reCaptchaToken;
            if (reCaptchaKey) {
                if (!executeRecaptcha) {
                    throw Error("Please wait a few seconds, then try again.");
                }
                reCaptchaToken = await executeRecaptcha("signin");
            }
            await (0,lib_api_post__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z)("/auth/sign-in", {
                email,
                password,
                reCaptchaToken
            });
            onSuccess?.();
        } catch (err) {
            setError(`${err}`);
        } finally{
            setSigningIn(false);
        }
    }
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
        style: {
            margin: "30px",
            minHeight: "50vh"
        },
        children: [
            !minimal && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                style: {
                    textAlign: "center",
                    marginBottom: "15px"
                },
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_logo_square__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
                        style: {
                            width: "100px",
                            height: "100px",
                            marginBottom: "15px"
                        },
                        priority: true
                    }),
                    /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h1", {
                        children: [
                            "Sign In to ",
                            siteName
                        ]
                    })
                ]
            }),
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                style: _shared__WEBPACK_IMPORTED_MODULE_10__/* .LOGIN_STYLE */ .E,
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                        style: {
                            margin: "10px 0"
                        },
                        children: strategies == null ? "Sign in" : haveSSO ? requiredSSO != null ? "Sign in using your single-sign-on provider" : "Sign in using your email address or a single-sign-on provider." : "Sign in using your email address."
                    }),
                    /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("form", {
                        children: [
                            haveSSO && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                style: {
                                    textAlign: "center",
                                    margin: "20px 0",
                                    display: requiredSSO == null ? "inherit" : "none"
                                },
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_sso__WEBPACK_IMPORTED_MODULE_11__/* ["default"] */ .ZP, {
                                    size: email ? 24 : undefined,
                                    style: email ? {
                                        textAlign: "right",
                                        marginBottom: "20px"
                                    } : undefined
                                })
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Input, {
                                autoFocus: true,
                                style: {
                                    fontSize: "12pt"
                                },
                                placeholder: "Email address",
                                autoComplete: "username",
                                onChange: (e)=>setEmail(e.target.value)
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_sso__WEBPACK_IMPORTED_MODULE_11__/* .RequiredSSO */ .Ug, {
                                strategy: requiredSSO
                            }),
                            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                                style: {
                                    marginTop: "30px",
                                    display: requiredSSO == null ? "inherit" : "none"
                                },
                                children: [
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                                        children: "Password "
                                    }),
                                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Input.Password, {
                                        style: {
                                            fontSize: "12pt"
                                        },
                                        autoComplete: "current-password",
                                        placeholder: "Password",
                                        onChange: (e)=>setPassword(e.target.value),
                                        onPressEnter: (e)=>{
                                            e.preventDefault();
                                            signIn();
                                        }
                                    })
                                ]
                            }),
                            email && requiredSSO == null && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Button, {
                                disabled: signingIn || !(password?.length >= 6),
                                shape: "round",
                                size: "large",
                                type: "primary",
                                style: {
                                    width: "100%",
                                    marginTop: "20px"
                                },
                                onClick: signIn,
                                children: signingIn ? /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                                    children: [
                                        /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__.Icon, {
                                            name: "spinner",
                                            spin: true
                                        }),
                                        " Signing In..."
                                    ]
                                }) : !password || password.length < 6 ? "Enter your password above." : "Sign In"
                            })
                        ]
                    }),
                    error && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                        children: [
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Alert, {
                                style: {
                                    marginTop: "20px"
                                },
                                message: "Error",
                                description: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                                    children: [
                                        /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                                            children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("b", {
                                                children: error
                                            })
                                        }),
                                        /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("p", {
                                            children: [
                                                "If you can't remember your password,",
                                                " ",
                                                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_misc_A__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                                    href: "/auth/password-reset",
                                                    children: "reset it"
                                                }),
                                                ". If that doesn't work ",
                                                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_landing_contact__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, {}),
                                                "."
                                            ]
                                        })
                                    ]
                                }),
                                type: "error",
                                showIcon: true
                            }),
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                style: {
                                    textAlign: "center",
                                    marginTop: "15px",
                                    fontSize: "14pt"
                                },
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_misc_A__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                    href: "/auth/password-reset",
                                    children: "Forgot password?"
                                })
                            })
                        ]
                    })
                ]
            }),
            !minimal && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                style: {
                    ..._shared__WEBPACK_IMPORTED_MODULE_10__/* .LOGIN_STYLE */ .E,
                    backgroundColor: "white",
                    margin: "30px auto",
                    padding: "15px"
                },
                children: [
                    "New to ",
                    siteName,
                    "? ",
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_misc_A__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                        href: "/auth/sign-up",
                        children: "Sign Up"
                    }),
                    anonymousSignup && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                        style: {
                            marginTop: "15px"
                        },
                        children: [
                            "Don't want to provide any information?",
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("br", {}),
                            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(components_misc_A__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                                href: "/auth/try",
                                children: [
                                    "Try ",
                                    siteName,
                                    " without creating an account."
                                ]
                            })
                        ]
                    })
                ]
            })
        ]
    });
}


/***/ })

};
;