-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
react/CozyDialogs/SpecificDialogs/AuthentificationDialog.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { useMemo, useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import PermissionDialog from '../PermissionDialog' | ||
import Buttons from '../../Buttons' | ||
import { useI18n } from '../../I18n' | ||
import Typography from '../../Typography' | ||
import { useClient } from 'cozy-client' | ||
import CozyAuthentificationIcon from '../../Icons/CozyAuthentification' | ||
import PasswordField from '../../PasswordField' | ||
|
||
import withSpecificDialogsLocales from './withSpecificDialogsLocales' | ||
|
||
/** | ||
* Dialog used to authenticate a user in the cozy system. | ||
* The authentication logic is implemented in the applications. | ||
*/ | ||
const AuthentificationDialog = ({ | ||
onClose, | ||
onSubmit, | ||
isLoading, | ||
isOIDC, | ||
error | ||
}) => { | ||
const { t } = useI18n() | ||
const client = useClient() | ||
const [password, setPassword] = useState('') | ||
|
||
const handleSubmit = e => { | ||
e.preventDefault() | ||
onSubmit(password) | ||
} | ||
|
||
const onPasswordChange = e => { | ||
setPassword(e.currentTarget.value) | ||
} | ||
|
||
const passphraseResetUrl = useMemo(() => { | ||
const url = new URL('/auth/passphrase_reset', client.getStackClient().uri) | ||
return url.href | ||
}, [client]) | ||
|
||
return ( | ||
<PermissionDialog | ||
open | ||
onClose={onClose} | ||
title={t(`authentification-dialog.${isOIDC ? 'title-oidc' : 'title'}`)} | ||
icon={CozyAuthentificationIcon} | ||
content={ | ||
<form onSubmit={handleSubmit}> | ||
<Typography variant="body1" className="u-ta-center"> | ||
{t('authentification-dialog.subtitle')} | ||
</Typography> | ||
<PasswordField | ||
autoFocus | ||
disabled={isLoading} | ||
value={password} | ||
onChange={onPasswordChange} | ||
className="u-mv-1" | ||
label={t( | ||
`authentification-dialog.${isOIDC ? 'label-oidc' : 'label'}` | ||
)} | ||
error={Boolean(error)} | ||
helperText={error && t(`authentification-dialog.errors.${error}`)} | ||
fullWidth | ||
required | ||
/> | ||
<Typography | ||
variant="body1" | ||
component="a" | ||
color="primary" | ||
href={passphraseResetUrl} | ||
className="u-link" | ||
> | ||
{t('authentification-dialog.forgotten-password')} | ||
</Typography> | ||
</form> | ||
} | ||
actions={ | ||
<Buttons | ||
busy={isLoading} | ||
disabled={isLoading || password.length === 0} | ||
onClick={handleSubmit} | ||
label={t('authentification-dialog.unlock')} | ||
fullWidth | ||
/> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
AuthentificationDialog.defaultProps = { | ||
isOIDC: false | ||
} | ||
|
||
AuthentificationDialog.propTypes = { | ||
/** A function call on clicking the close button */ | ||
onClose: PropTypes.func, | ||
/** A function call on submitting the form with the password entered */ | ||
onSubmit: PropTypes.func, | ||
/** Waiting status, e.g. processing of form submission */ | ||
isLoading: PropTypes.bool, | ||
/** Show specific wording for OIDC */ | ||
isOIDC: PropTypes.bool, | ||
/** Error key to display a message */ | ||
error: PropTypes.string | ||
} | ||
|
||
export default withSpecificDialogsLocales(AuthentificationDialog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as InstallFlagshipAppDialog } from './InstallFlagshipAppDialog' | ||
export { default as AuthentificationDialog } from './AuthentificationDialog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters