Files
AdGuardHome/client/src/install/Setup/Auth.js
Eugene Burkov 0ef8344178 Pull request: 3503 password policy
Merge in DNS/adguard-home from 3503-password-policy to master

Closes #3503.

Squashed commit of the following:

commit 1f03cd9ef6e76a691ae383d6ba4b7f851eabddb8
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 10 18:24:59 2022 +0300

    client: imp msg

commit e164ae2544284cf9a1d3333c50b68e361f78ce2a
Merge: b7efd764 f53f48cc
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Thu Feb 10 16:52:01 2022 +0300

    Merge branch 'master' into 3503-password-policy

commit b7efd7640ec0fa3deac5290f8306ce5142428718
Author: Ildar Kamalov <ik@adguard.com>
Date:   Thu Feb 10 16:17:59 2022 +0300

    client: remove empty line

commit f19aba6cb579d2c4681675c881000c8f16257ab9
Author: Ildar Kamalov <ik@adguard.com>
Date:   Thu Feb 10 16:09:14 2022 +0300

    client: validate password length

commit a6943c94483306ecfc0d1431d576d42053823b61
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Feb 4 18:57:02 2022 +0300

    all: fix docs again

commit 9346bb6c393af0799a79b228285acdd8f8799b83
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Feb 4 18:54:15 2022 +0300

    openapi: fix docs

commit a8016443237c130f69108970ddfc77ef71126be6
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Feb 4 18:25:55 2022 +0300

    all: validate passwd runes count
2022-02-10 18:30:41 +03:00

111 lines
3.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Field, reduxForm } from 'redux-form';
import { withTranslation, Trans } from 'react-i18next';
import flow from 'lodash/flow';
import i18n from '../../i18n';
import Controls from './Controls';
import { renderInputField } from '../../helpers/form';
import { FORM_NAME } from '../../helpers/constants';
import { validatePasswordLength } from '../../helpers/validators';
const required = (value) => {
if (value || value === 0) {
return false;
}
return <Trans>form_error_required</Trans>;
};
const validate = (values) => {
const errors = {};
if (values.confirm_password !== values.password) {
errors.confirm_password = i18n.t('form_error_password');
}
return errors;
};
const Auth = (props) => {
const {
handleSubmit,
pristine,
invalid,
t,
} = props;
return (
<form className="setup__step" onSubmit={handleSubmit}>
<div className="setup__group">
<div className="setup__subtitle">
<Trans>install_auth_title</Trans>
</div>
<p className="setup__desc">
<Trans>install_auth_desc</Trans>
</p>
<div className="form-group">
<label>
<Trans>install_auth_username</Trans>
</label>
<Field
name="username"
component={renderInputField}
type="text"
className="form-control"
placeholder={ t('install_auth_username_enter') }
validate={[required]}
autoComplete="username"
/>
</div>
<div className="form-group">
<label>
<Trans>install_auth_password</Trans>
</label>
<Field
name="password"
component={renderInputField}
type="password"
className="form-control"
placeholder={ t('install_auth_password_enter') }
validate={[required, validatePasswordLength]}
autoComplete="new-password"
/>
</div>
<div className="form-group">
<label>
<Trans>install_auth_confirm</Trans>
</label>
<Field
name="confirm_password"
component={renderInputField}
type="password"
className="form-control"
placeholder={ t('install_auth_confirm') }
validate={[required]}
autoComplete="new-password"
/>
</div>
</div>
<Controls pristine={pristine} invalid={invalid} />
</form>
);
};
Auth.propTypes = {
handleSubmit: PropTypes.func.isRequired,
pristine: PropTypes.bool.isRequired,
invalid: PropTypes.bool.isRequired,
t: PropTypes.func.isRequired,
};
export default flow([
withTranslation(),
reduxForm({
form: FORM_NAME.INSTALL,
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
validate,
}),
])(Auth);