1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

update webdav secret

add WEBDAV_SECRET_MIN_LENGTH and WEBDAV_SECRET_STRENGTH_LEVEL
This commit is contained in:
lian
2022-02-11 13:48:18 +08:00
parent 1500afb2ff
commit 7ff103f69c
7 changed files with 55 additions and 12 deletions

View File

@@ -1,7 +1,9 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Input, InputGroup, InputGroupAddon } from 'reactstrap';
import { Modal, ModalHeader, ModalBody, ModalFooter, Alert, Button, Input, InputGroup, InputGroupAddon } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
const { webdavSecretMinLength, webdavSecretStrengthLevel } = window.app.pageOptions;
const propTypes = {
password: PropTypes.string.isRequired,
@@ -14,6 +16,7 @@ class UpdateWebdavPassword extends Component {
constructor(props) {
super(props);
this.state = {
errorInfo: '',
password: this.props.password,
isPasswordVisible: false,
btnDisabled: false
@@ -21,9 +24,25 @@ class UpdateWebdavPassword extends Component {
}
submit = () => {
if (this.state.password.length === 0) {
this.setState({errorInfo: 'Please enter password'});
return false;
}
if (this.state.password.length < webdavSecretMinLength) {
this.setState({errorInfo: 'Password is too short'});
return false;
}
if (Utils.getStrengthLevel(this.state.password) < webdavSecretStrengthLevel) {
this.setState({errorInfo: gettext('Password is too weak, should have at least {webdavSecretStrengthLevel} of the following: num, upper letter, lower letter and other symbols'.replace('{webdavSecretStrengthLevel}', webdavSecretStrengthLevel))});
return false;
}
this.setState({
btnDisabled: true
});
this.props.updatePassword(this.state.password);
}
@@ -39,11 +58,7 @@ class UpdateWebdavPassword extends Component {
}
generatePassword = () => {
let randomPassword = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 8; i++) {
randomPassword += possible.charAt(Math.floor(Math.random() * possible.length));
}
let randomPassword = Utils.generatePassword(webdavSecretMinLength);
this.setState({
password: randomPassword,
isPasswordVisible: true
@@ -52,9 +67,13 @@ class UpdateWebdavPassword extends Component {
render() {
const { toggle } = this.props;
let passwordLengthTip = gettext('(at least {passwordLength} characters and has {shareLinkPasswordStrengthLevel} of the following: num, upper letter, lower letter and other symbols)');
passwordLengthTip = passwordLengthTip.replace('{passwordLength}', webdavSecretMinLength)
.replace('{shareLinkPasswordStrengthLevel}', webdavSecretStrengthLevel);
return (
<Modal centered={true} isOpen={true} toggle={toggle}>
<ModalHeader toggle={toggle}>{gettext('WebDav Password')}</ModalHeader>
<span className="tip">{passwordLengthTip}</span>
<ModalBody>
<InputGroup className="">
<Input type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.password} onChange={this.handleInputChange} autoComplete="new-password"/>
@@ -65,6 +84,7 @@ class UpdateWebdavPassword extends Component {
</InputGroup>
</ModalBody>
<ModalFooter>
{this.state.errorInfo && <Alert color="danger" className="mt-2">{gettext(this.state.errorInfo)}</Alert>}
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.submit} disabled={this.state.btnDisabled}>{gettext('Submit')}</Button>
</ModalFooter>