This commit is contained in:
Andrey Savihin 2019-10-02 10:25:50 +03:00
commit cc91f7aa31
6 changed files with 107 additions and 114 deletions

View File

@ -30,7 +30,7 @@ const BodyStyle = styled.div`
content: "";
height: 2px;
margin-top: 9px;
width: 36%;
width: 26%;
float: right;
}
@ -39,7 +39,7 @@ const BodyStyle = styled.div`
content: "";
height: 2px;
margin-top: 9px;
width: 36%;
width: 26%;
float: left;
}
}

View File

@ -17,6 +17,7 @@
"PasswordCustomMode": "Password",
"ImportContactsOkButton": "OK",
"LoadingProcessing": "Loading...",
"ChangePasswordSuccess": "Password has been successfully changed",
"CustomWelcomePageTitle": "{{welcomePageTitle}}"

View File

@ -13,10 +13,11 @@
"ErrorPasswordNoUpperCase": "заглавные буквы",
"ErrorPasswordNoSpecialSymbols": "специальные символы",
"EmailAndPasswordCopiedToClipboard": "Email и пароль скопированы",
"PassworResetTitle": "Теперь вы можете создать новый пароль.", "_comment":"SYNTAX ERROR 'Passwor' Reset Title",
"PassworResetTitle": "Теперь вы можете создать новый пароль.",
"PasswordCustomMode": "Пароль",
"ImportContactsOkButton": "OK",
"LoadingProcessing": "Загрузка...",
"ChangePasswordSuccess": "Пароль был успешно изменен",
"CustomWelcomePageTitle": "{{welcomePageTitle}}"

View File

@ -42,8 +42,14 @@ const ConfirmContainer = styled.div`
word-break: break-word;
}
.display-none {
display: none;
}
`;
const emailInputName = 'email';
class Confirm extends React.PureComponent {
constructor(props) {
@ -51,9 +57,9 @@ class Confirm extends React.PureComponent {
this.state = {
email: props.linkData.email,
firstName: props.linkData.firstname,
firstName: props.linkData.firstname,
firstNameValid: true,
lastName: props.linkData.lastname,
lastName: props.linkData.lastname,
lastNameValid: true,
password: '',
passwordValid: true,
@ -95,7 +101,7 @@ class Confirm extends React.PureComponent {
this.setState({ isLoading: false });
return false;
}
const loginData = {
userName: this.state.email,
password: this.state.password
@ -225,13 +231,24 @@ class Confirm extends React.PureComponent {
onChange={this.onChangeSurname}
onKeyDown={this.onKeyPress}
/>
<TextInput
className='confirm-row display-none'
id='email'
name={emailInputName}
value={this.state.email}
size='huge'
scale={true}
isReadOnly={true}
/>
</div>
<PasswordInput
className='confirm-row'
id='password'
inputName='password'
emailInputName='surname'
emailInputName={emailInputName}
inputValue={this.state.password}
placeholder={t('InvitePassword')}
size='huge'

View File

@ -4,15 +4,7 @@ import { withTranslation } from "react-i18next";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import styled from "styled-components";
import {
Container,
Collapse,
Row,
Col,
Card,
CardTitle,
CardImg
} from "reactstrap";
import { Container, Row, Col, Card, CardTitle, CardImg } from "reactstrap";
import {
Button,
PageLayout,
@ -33,9 +25,9 @@ const BodyStyle = styled(Container)`
p {
margin-bottom: 5px;
}
.button-style{
margin-top: 20px;
}
.button-style {
margin-top: 20px;
}
.password-row {
margin: 23px 0 0;
@ -65,7 +57,6 @@ class Form extends React.PureComponent {
password: "",
passwordValid: true,
isValidConfirmLink: false,
errorText: "",
isLoading: false,
passwordEmpty: false,
key: linkData.confirmHeader,
@ -83,15 +74,13 @@ class Form extends React.PureComponent {
this.setState({ password: event.target.value });
!this.state.passwordValid && this.setState({ passwordValid: true });
event.target.value.trim() && this.setState({ passwordEmpty: false });
this.state.errorText && this.setState({ errorText: "" });
this.onKeyPress(event);
};
onSubmit = e => {
this.setState({ isLoading: true }, function () {
this.setState({ isLoading: true }, function() {
const { userId, password, key } = this.state;
const { history, changePassword, logout } = this.props;
this.setState({ errorText: "" });
let hasError = false;
if (!this.state.passwordValid) {
@ -108,14 +97,12 @@ class Form extends React.PureComponent {
changePassword(userId, { password }, key)
.then(() => {
console.log("UPDATE PASSWORD");
logout();
toastr.success(this.props.t("ChangePasswordSuccess"));
history.push("/");
})
.catch(e => {
history.push("/");
console.log("ERROR UPDATE PASSWORD:", e.message);
this.setState({ errorText: e.message });
toastr.error(this.props.t(`${e.message}`));
this.setState({ isLoading: false });
});
});
@ -123,14 +110,10 @@ class Form extends React.PureComponent {
componentDidMount() {
const { getConfirmationInfo, history } = this.props;
getConfirmationInfo(this.state.key)
.then(() => {
console.log("GET PASSWORD SETTINGS SUCCESS");
})
.catch(e => {
console.log("ERROR GET PASSWORD SETTINGS", e);
history.push(`/login/error=${e}`);
});
getConfirmationInfo(this.state.key).catch(e => {
toastr.error(this.props.t(`${e.message}`));
history.push("/");
});
window.addEventListener("keydown", this.onKeyPress);
window.addEventListener("keyup", this.onKeyPress);
@ -141,95 +124,84 @@ class Form extends React.PureComponent {
window.removeEventListener("keyup", this.onKeyPress);
}
onCopyToClipboard = () =>
toastr.success(this.props.t("EmailAndPasswordCopiedToClipboard"));
validatePassword = value => this.setState({ passwordValid: value });
render() {
const { settings, isConfirmLoaded, t } = this.props;
const { isLoading, password, passwordEmpty, errorText } = this.state;
const { isLoading, password, passwordEmpty } = this.state;
const mdOptions = { size: 6, offset: 3 };
return !isConfirmLoaded ? (
<Loader className="pageLoader" type="rombs" size={40} />
) : (
<BodyStyle>
<Row className="password-row">
<Col sm="12" md={mdOptions}>
<Card className="password-card">
<CardImg
className="card-img"
src="images/dark_general.png"
alt="Logo"
top
/>
<CardTitle className="card-title">
{t("CustomWelcomePageTitle", { welcomePageTitle })}
</CardTitle>
</Card>
<Text.Body fontSize={14}>{t("PassworResetTitle")}</Text.Body>
<BodyStyle>
<Row className="password-row">
<Col sm="12" md={mdOptions}>
<Card className="password-card">
<CardImg
className="card-img"
src="images/dark_general.png"
alt="Logo"
top
/>
<CardTitle className="card-title">
{t("CustomWelcomePageTitle", { welcomePageTitle })}
</CardTitle>
</Card>
<Text.Body fontSize={14}>{t("PassworResetTitle")}</Text.Body>
<PasswordInput
id="password"
name="password"
inputName="password"
inputValue={password}
size="huge"
scale={true}
type="password"
isDisabled={isLoading}
hasError={passwordEmpty}
onCopyToClipboard={this.onCopyToClipboard}
onValidateInput={this.validatePassword}
generatorSpecial="!@#$%^&*"
tabIndex={1}
value={password}
onChange={this.onChange}
emailInputName="E-mail"
passwordSettings={settings}
tooltipPasswordTitle="Password must contain:"
tooltipPasswordLength={`${t("ErrorPasswordLength", {
fromNumber: 6,
toNumber: 30
})}:`}
placeholder={t("PasswordCustomMode")}
maxLength={30}
onKeyDown={this.onKeyPress}
isAutoFocussed={true}
inputWidth="490px"
/>
<Button
className="button-style"
primary
size="big"
tabIndex={3}
label={
isLoading ? t("LoadingProcessing") : t("ImportContactsOkButton")
}
isDisabled={isLoading}
isLoading={isLoading}
onClick={this.onSubmit}
/>
</Col>
</Row>
<Collapse isOpen={!!errorText}>
<Row className="login-row">
<Col sm="12" md={mdOptions}>
<div className="alert alert-danger">{errorText}</div>
</Col>
</Row>
</Collapse>
</BodyStyle>
);
<PasswordInput
id="password"
name="password"
inputName="password"
inputValue={password}
size="huge"
scale={true}
type="password"
isDisabled={isLoading}
hasError={passwordEmpty}
onValidateInput={this.validatePassword}
generatorSpecial="!@#$%^&*"
tabIndex={1}
value={password}
onChange={this.onChange}
emailInputName="E-mail"
passwordSettings={settings}
tooltipPasswordTitle="Password must contain:"
tooltipPasswordLength={`${t("ErrorPasswordLength", {
fromNumber: 6,
toNumber: 30
})}:`}
placeholder={t("PasswordCustomMode")}
maxLength={30}
onKeyDown={this.onKeyPress}
isAutoFocussed={true}
inputWidth="490px"
/>
<Button
className="button-style"
primary
size="big"
tabIndex={2}
label={
isLoading ? t("LoadingProcessing") : t("ImportContactsOkButton")
}
isDisabled={isLoading}
isLoading={isLoading}
onClick={this.onSubmit}
/>
</Col>
</Row>
</BodyStyle>
);
}
}
Form.propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
changePassword: PropTypes.func.isRequired
changePassword: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
linkData: PropTypes.object.isRequired
};
Form.defaultProps = {
@ -240,11 +212,12 @@ const ChangePasswordForm = props => (
<PageLayout sectionBodyContent={<Form {...props} />} />
);
function mapStateToProps(state) {
function mapStateToProps(store) {
return {
isValidConfirmLink: state.auth.isValidConfirmLink,
isConfirmLoaded: state.auth.isConfirmLoaded,
settings: state.auth.password
isValidConfirmLink: store.auth.isValidConfirmLink,
isConfirmLoaded: store.auth.isConfirmLoaded,
settings: store.auth.password,
isAuthenticated: store.auth.isAuthenticated
};
}

View File

@ -40,7 +40,8 @@
"ErrorPasswordNoUpperCase",
"ErrorPasswordNoSpecialSymbols",
"EmailAndPasswordCopiedToClipboard",
"LastName"
"LastName",
"ChangePasswordSuccess"
]
}
},