mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
parent
7e79328a70
commit
d0283aa89c
14 changed files with 134 additions and 65 deletions
|
@ -142,19 +142,16 @@ const UserAddStep = React.memo(
|
|||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.text}>{t('common.password')}</div>
|
||||
<div className={styles.field}>
|
||||
<Input.Password
|
||||
fluid
|
||||
ref={passwordField}
|
||||
name="password"
|
||||
value={data.password}
|
||||
readOnly={isSubmitting}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.note}>
|
||||
{t('common.mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber')}
|
||||
</div>
|
||||
</div>
|
||||
<Input.Password
|
||||
withStrengthBar
|
||||
fluid
|
||||
ref={passwordField}
|
||||
name="password"
|
||||
value={data.password}
|
||||
readOnly={isSubmitting}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.text}>{t('common.name')}</div>
|
||||
<Input
|
||||
fluid
|
||||
|
|
|
@ -113,18 +113,15 @@ const UserPasswordEditStep = React.memo(
|
|||
)}
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<div className={styles.text}>{t('common.newPassword')}</div>
|
||||
<div className={styles.field}>
|
||||
<Input.Password
|
||||
fluid
|
||||
ref={passwordField}
|
||||
name="password"
|
||||
value={data.password}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.note}>
|
||||
{t('common.mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber')}
|
||||
</div>
|
||||
</div>
|
||||
<Input.Password
|
||||
withStrengthBar
|
||||
fluid
|
||||
ref={passwordField}
|
||||
name="password"
|
||||
value={data.password}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
{usePasswordConfirmation && (
|
||||
<>
|
||||
<div className={styles.text}>{t('common.currentPassword')}</div>
|
||||
|
|
|
@ -1,22 +1,74 @@
|
|||
import React, { useCallback } from 'react';
|
||||
import { Icon, Input } from 'semantic-ui-react';
|
||||
import zxcvbn from 'zxcvbn';
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Icon, Input, Progress } from 'semantic-ui-react';
|
||||
import { useToggle } from '../../../hooks';
|
||||
|
||||
const InputPassword = React.forwardRef((props, ref) => {
|
||||
const [isVisible, toggleVisible] = useToggle();
|
||||
import styles from './InputPassword.module.css';
|
||||
|
||||
const handleToggleClick = useCallback(() => {
|
||||
toggleVisible();
|
||||
}, [toggleVisible]);
|
||||
const STRENGTH_SCORE_COLORS = ['red', 'orange', 'yellow', 'olive', 'green'];
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...props} // eslint-disable-line react/jsx-props-no-spreading
|
||||
ref={ref}
|
||||
type={isVisible ? 'text' : 'password'}
|
||||
icon={<Icon link name={isVisible ? 'eye' : 'eye slash'} onClick={handleToggleClick} />}
|
||||
/>
|
||||
);
|
||||
});
|
||||
const InputPassword = React.forwardRef(
|
||||
({ value, withStrengthBar, minStrengthScore, className, ...props }, ref) => {
|
||||
const [isVisible, toggleVisible] = useToggle();
|
||||
|
||||
const strengthScore = useMemo(() => {
|
||||
if (!withStrengthBar) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return zxcvbn(value).score;
|
||||
}, [value, withStrengthBar]);
|
||||
|
||||
const handleToggleClick = useCallback(() => {
|
||||
toggleVisible();
|
||||
}, [toggleVisible]);
|
||||
|
||||
const inputProps = {
|
||||
...props,
|
||||
ref,
|
||||
type: isVisible ? 'text' : 'password',
|
||||
icon: <Icon link name={isVisible ? 'eye' : 'eye slash'} onClick={handleToggleClick} />,
|
||||
};
|
||||
|
||||
if (!withStrengthBar) {
|
||||
return (
|
||||
<Input
|
||||
{...inputProps} // eslint-disable-line react/jsx-props-no-spreading
|
||||
className={className}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<Input
|
||||
{...inputProps} // eslint-disable-line react/jsx-props-no-spreading
|
||||
error={!!value && strengthScore < minStrengthScore}
|
||||
/>
|
||||
<Progress
|
||||
value={value ? strengthScore + 1 : 0}
|
||||
total={5}
|
||||
color={STRENGTH_SCORE_COLORS[strengthScore]}
|
||||
size="tiny"
|
||||
className={styles.strengthBar}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
InputPassword.propTypes = {
|
||||
value: PropTypes.string.isRequired,
|
||||
withStrengthBar: PropTypes.bool,
|
||||
minStrengthScore: PropTypes.number,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
InputPassword.defaultProps = {
|
||||
withStrengthBar: false,
|
||||
minStrengthScore: 2,
|
||||
className: undefined,
|
||||
};
|
||||
|
||||
export default React.memo(InputPassword);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.strengthBar {
|
||||
margin: 4px 0 0 !important;
|
||||
opacity: 0.5;
|
||||
}
|
10
client/src/lib/custom-ui/styles.css
vendored
10
client/src/lib/custom-ui/styles.css
vendored
|
@ -14333,11 +14333,11 @@ img.ui.bordered.image {
|
|||
---------------------*/
|
||||
|
||||
.ui.input.error > input {
|
||||
background-color: #fff6f6;
|
||||
border-color: #e0b4b4;
|
||||
color: #9f3a38;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
background-color: #fff6f6 !important;
|
||||
border-color: #e0b4b4 !important;
|
||||
color: #9f3a38 !important;
|
||||
-webkit-box-shadow: none !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
/* Error Placeholder */
|
||||
|
|
|
@ -105,8 +105,6 @@ export default {
|
|||
members: 'Members',
|
||||
minutes: 'Minutes',
|
||||
moveCard_title: 'Move Card',
|
||||
mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber:
|
||||
'Must be at least 6 characters long and contain at least one letter and number',
|
||||
name: 'Name',
|
||||
newEmail: 'New e-mail',
|
||||
newPassword: 'New password',
|
||||
|
|
|
@ -100,8 +100,6 @@ export default {
|
|||
members: 'Участники',
|
||||
minutes: 'Минуты',
|
||||
moveCard: 'Перемещение карточки',
|
||||
mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber:
|
||||
'Должен быть не менее 6 символов и содержать хотя бы одну букву и цифру',
|
||||
name: 'Имя',
|
||||
newEmail: 'Новый e-mail',
|
||||
newPassword: 'Новый пароль',
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
const PASSWORD_REGEX = /^(?=.*[A-Za-z])(?=.*\d).+$/;
|
||||
import zxcvbn from 'zxcvbn';
|
||||
|
||||
const USERNAME_REGEX = /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/;
|
||||
|
||||
export const isPassword = (string) => {
|
||||
return string.length >= 6 && PASSWORD_REGEX.test(string);
|
||||
};
|
||||
export const isPassword = (string) => zxcvbn(string).score >= 2; // TODO: move to config
|
||||
|
||||
export const isUsername = (string) => {
|
||||
return string.length >= 3 && string.length <= 16 && USERNAME_REGEX.test(string);
|
||||
};
|
||||
export const isUsername = (string) =>
|
||||
string.length >= 3 && string.length <= 16 && USERNAME_REGEX.test(string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue