diff --git a/apps/photos/src/components/SignUp.tsx b/apps/photos/src/components/SignUp.tsx deleted file mode 100644 index 50cab5df3..000000000 --- a/apps/photos/src/components/SignUp.tsx +++ /dev/null @@ -1,265 +0,0 @@ -import React, { useState } from 'react'; -import { Formik, FormikHelpers } from 'formik'; -import * as Yup from 'yup'; -import { sendOtt } from 'services/userService'; -import { setData, LS_KEYS } from 'utils/storage/localStorage'; -import { useRouter } from 'next/router'; -import SubmitButton from 'components/SubmitButton'; -import { - generateAndSaveIntermediateKeyAttributes, - generateKeyAndSRPAttributes, - isWeakPassword, - saveKeyInSessionStore, -} from 'utils/crypto'; -import { setJustSignedUp } from 'utils/storage'; -import { logError } from 'utils/sentry'; -import { SESSION_KEYS } from 'utils/storage/sessionStorage'; -import { PAGES } from 'constants/pages'; -import { - Box, - Checkbox, - FormControlLabel, - FormGroup, - Link, - TextField, - Typography, -} from '@mui/material'; -import FormPaperTitle from './Form/FormPaper/Title'; -import LinkButton from './pages/gallery/LinkButton'; -import FormPaperFooter from './Form/FormPaper/Footer'; -import { VerticallyCentered } from './Container'; -import { PasswordStrengthHint } from './PasswordStrength'; -import { Trans } from 'react-i18next'; -import { t } from 'i18next'; -import ShowHidePassword from './Form/ShowHidePassword'; - -interface FormValues { - email: string; - passphrase: string; - confirm: string; -} - -interface SignUpProps { - login: () => void; -} - -export default function SignUp(props: SignUpProps) { - const router = useRouter(); - const [acceptTerms, setAcceptTerms] = useState(false); - const [loading, setLoading] = useState(false); - const [showPassword, setShowPassword] = useState(false); - - const handleClickShowPassword = () => { - setShowPassword(!showPassword); - }; - - const handleMouseDownPassword = ( - event: React.MouseEvent - ) => { - event.preventDefault(); - }; - - const registerUser = async ( - { email, passphrase, confirm }: FormValues, - { setFieldError }: FormikHelpers - ) => { - try { - if (passphrase !== confirm) { - setFieldError('confirm', t('PASSPHRASE_MATCH_ERROR')); - return; - } - setLoading(true); - try { - setData(LS_KEYS.USER, { email }); - await sendOtt(email); - } catch (e) { - setFieldError('confirm', `${t('UNKNOWN_ERROR')} ${e.message}`); - throw e; - } - try { - const { keyAttributes, masterKey, srpSetupAttributes } = - await generateKeyAndSRPAttributes(passphrase); - - setData(LS_KEYS.ORIGINAL_KEY_ATTRIBUTES, keyAttributes); - setData(LS_KEYS.SRP_SETUP_ATTRIBUTES, srpSetupAttributes); - await generateAndSaveIntermediateKeyAttributes( - passphrase, - keyAttributes, - masterKey - ); - - await saveKeyInSessionStore( - SESSION_KEYS.ENCRYPTION_KEY, - masterKey - ); - setJustSignedUp(true); - router.push(PAGES.VERIFY); - } catch (e) { - setFieldError('confirm', t('PASSWORD_GENERATION_FAILED')); - throw e; - } - } catch (err) { - logError(err, 'signup failed'); - } - setLoading(false); - }; - - return ( - <> - {t('SIGN_UP')} - - initialValues={{ - email: '', - passphrase: '', - confirm: '', - }} - validationSchema={Yup.object().shape({ - email: Yup.string() - .email(t('EMAIL_ERROR')) - .required(t('REQUIRED')), - passphrase: Yup.string().required(t('REQUIRED')), - confirm: Yup.string().required(t('REQUIRED')), - })} - validateOnChange={false} - validateOnBlur={false} - onSubmit={registerUser}> - {({ - values, - errors, - handleChange, - handleSubmit, - }): JSX.Element => ( -
- - - - - ), - }} - /> - - - - - - setAcceptTerms(e.target.checked) - } - color="accent" - /> - } - label={ - - - ), - b: ( - - ), - }} - /> - - } - /> - - - - - {loading && ( - - {t('KEY_GENERATION_IN_PROGRESS_MESSAGE')} - - )} - -
- )} - - - - - {t('ACCOUNT_EXISTS')} - - - - ); -} diff --git a/apps/photos/src/components/TwoFactor/Modal/Manage.tsx b/apps/photos/src/components/TwoFactor/Modal/Manage.tsx index b94f62988..084ce6730 100644 --- a/apps/photos/src/components/TwoFactor/Modal/Manage.tsx +++ b/apps/photos/src/components/TwoFactor/Modal/Manage.tsx @@ -4,7 +4,7 @@ import { t } from 'i18next'; import { AppContext } from 'pages/_app'; import { PAGES } from 'constants/pages'; import router from 'next/router'; -import { disableTwoFactor } from 'services/userService'; +import { disableTwoFactor } from '@ente/accounts/api/user'; import { setData, LS_KEYS, getData } from 'utils/storage/localStorage'; import { Button, Grid } from '@mui/material'; diff --git a/apps/photos/src/pages/index.tsx b/apps/photos/src/pages/index.tsx index 3a740b6e0..93501dc21 100644 --- a/apps/photos/src/pages/index.tsx +++ b/apps/photos/src/pages/index.tsx @@ -5,8 +5,8 @@ import { AppContext } from './_app'; import Login from '@ente/accounts/components/Login'; import { useRouter } from 'next/router'; import { getData, LS_KEYS } from 'utils/storage/localStorage'; +import SignUp from '@ente/accounts/components/SignUp'; import EnteSpinner from 'components/EnteSpinner'; -import SignUp from 'components/SignUp'; import { t } from 'i18next'; import localForage from 'utils/storage/localForage'; @@ -247,7 +247,11 @@ export default function LandingPage() { {showLogin ? ( ) : ( - + )} diff --git a/apps/photos/src/utils/crypto/index.ts b/apps/photos/src/utils/crypto/index.ts index 80c89a8c0..9bb3da303 100644 --- a/apps/photos/src/utils/crypto/index.ts +++ b/apps/photos/src/utils/crypto/index.ts @@ -2,7 +2,7 @@ import { KeyAttributes, SRPSetupAttributes } from 'types/user'; import { SESSION_KEYS, setKey } from 'utils/storage/sessionStorage'; import { getData, LS_KEYS, setData } from 'utils/storage/localStorage'; import { getActualKey, getToken } from 'utils/common/key'; -import { setRecoveryKey } from 'services/userService'; +import { setRecoveryKey } from '@ente/accounts/api/user'; import { logError } from 'utils/sentry'; import isElectron from 'is-electron'; import safeStorageService from 'services/electron/safeStorage';