mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 07:55:36 +00:00
Merge pull request #5123 from haiwen/webdav-secret
update webdav secret
This commit is contained in:
@@ -269,19 +269,19 @@ class GenerateShareLink extends React.Component {
|
||||
// validate password
|
||||
if (isShowPasswordInput) {
|
||||
if (password.length === 0) {
|
||||
this.setState({errorInfo: 'Please enter password'});
|
||||
this.setState({errorInfo: gettext('Please enter a password.')});
|
||||
return false;
|
||||
}
|
||||
if (password.length < shareLinkPasswordMinLength) {
|
||||
this.setState({errorInfo: 'Password is too short'});
|
||||
this.setState({errorInfo: gettext('The password is too short.')});
|
||||
return false;
|
||||
}
|
||||
if (password !== passwdnew) {
|
||||
this.setState({errorInfo: 'Passwords don\'t match'});
|
||||
this.setState({errorInfo: gettext('Passwords don\'t match')});
|
||||
return false;
|
||||
}
|
||||
if (Utils.getStrengthLevel(password) < shareLinkPasswordStrengthLevel) {
|
||||
this.setState({errorInfo: gettext('Password is too weak, should have at least {shareLinkPasswordStrengthLevel} of the following: num, upper letter, lower letter and other symbols'.replace('{shareLinkPasswordStrengthLevel}', shareLinkPasswordStrengthLevel))});
|
||||
this.setState({errorInfo: gettext('The password is too weak. It should include at least {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols.').replace('{passwordStrengthLevel}', shareLinkPasswordStrengthLevel)});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -289,7 +289,7 @@ class GenerateShareLink extends React.Component {
|
||||
if (isExpireChecked) {
|
||||
if (setExp == 'by-date') {
|
||||
if (!expDate) {
|
||||
this.setState({errorInfo: 'Please select an expiration time'});
|
||||
this.setState({errorInfo: gettext('Please select an expiration time')});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -298,11 +298,11 @@ class GenerateShareLink extends React.Component {
|
||||
// by days
|
||||
let reg = /^\d+$/;
|
||||
if (!expireDays) {
|
||||
this.setState({errorInfo: 'Please enter days'});
|
||||
this.setState({errorInfo: gettext('Please enter days')});
|
||||
return false;
|
||||
}
|
||||
if (!reg.test(expireDays)) {
|
||||
this.setState({errorInfo: 'Please enter a non-negative integer'});
|
||||
this.setState({errorInfo: gettext('Please enter a non-negative integer')});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -371,9 +371,9 @@ class GenerateShareLink extends React.Component {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
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}', shareLinkPasswordMinLength)
|
||||
.replace('{shareLinkPasswordStrengthLevel}', shareLinkPasswordStrengthLevel);
|
||||
let passwordLengthTip = gettext('(at least {passwordMinLength} characters and includes {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols)');
|
||||
passwordLengthTip = passwordLengthTip.replace('{passwordMinLength}', shareLinkPasswordMinLength)
|
||||
.replace('{passwordStrengthLevel}', shareLinkPasswordStrengthLevel);
|
||||
|
||||
const { userPerm } = this.props;
|
||||
const { isCustomPermission } = Utils.getUserPermission(userPerm);
|
||||
|
@@ -151,11 +151,11 @@ class GenerateUploadLink extends React.Component {
|
||||
// check password params
|
||||
if (showPasswordInput) {
|
||||
if (password.length === 0) {
|
||||
this.setState({errorInfo: gettext('Please enter password')});
|
||||
this.setState({errorInfo: gettext('Please enter a password.')});
|
||||
return false;
|
||||
}
|
||||
if (password.length < shareLinkPasswordMinLength) {
|
||||
this.setState({errorInfo: gettext('Password is too short')});
|
||||
this.setState({errorInfo: gettext('The password is too short.')});
|
||||
return false;
|
||||
}
|
||||
if (password !== passwordnew) {
|
||||
@@ -163,7 +163,7 @@ class GenerateUploadLink extends React.Component {
|
||||
return false;
|
||||
}
|
||||
if (Utils.getStrengthLevel(password) < shareLinkPasswordStrengthLevel) {
|
||||
this.setState({errorInfo: gettext('Password is too weak, should have at least {shareLinkPasswordStrengthLevel} of the following: num, upper letter, lower letter and other symbols'.replace('{shareLinkPasswordStrengthLevel}', shareLinkPasswordStrengthLevel))});
|
||||
this.setState({errorInfo: gettext('The password is too weak. It should include at least {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols.').replace('{passwordStrengthLevel}', shareLinkPasswordStrengthLevel)});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class GenerateUploadLink extends React.Component {
|
||||
if (isExpireChecked) {
|
||||
if (setExp == 'by-date') {
|
||||
if (!expDate) {
|
||||
this.setState({errorInfo: 'Please select an expiration time'});
|
||||
this.setState({errorInfo: gettext('Please select an expiration time')});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -267,9 +267,9 @@ class GenerateUploadLink extends React.Component {
|
||||
|
||||
const { isSendLinkShown } = this.state;
|
||||
|
||||
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}', shareLinkPasswordMinLength)
|
||||
.replace('{shareLinkPasswordStrengthLevel}', shareLinkPasswordStrengthLevel);
|
||||
let passwordLengthTip = gettext('(at least {passwordMinLength} characters and includes {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols)');
|
||||
passwordLengthTip = passwordLengthTip.replace('{passwordMinLength}', shareLinkPasswordMinLength)
|
||||
.replace('{passwordStrengthLevel}', shareLinkPasswordStrengthLevel);
|
||||
|
||||
if (this.state.sharedUploadInfo) {
|
||||
let sharedUploadInfo = this.state.sharedUploadInfo;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
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 propTypes = {
|
||||
password: PropTypes.string.isRequired,
|
||||
@@ -9,6 +10,8 @@ const propTypes = {
|
||||
toggle: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
const { webdavSecretMinLength, webdavSecretStrengthLevel } = window.app.pageOptions;
|
||||
|
||||
class UpdateWebdavPassword extends Component {
|
||||
|
||||
constructor(props) {
|
||||
@@ -16,20 +19,36 @@ class UpdateWebdavPassword extends Component {
|
||||
this.state = {
|
||||
password: this.props.password,
|
||||
isPasswordVisible: false,
|
||||
btnDisabled: false
|
||||
btnDisabled: false,
|
||||
errMsg: ''
|
||||
};
|
||||
}
|
||||
|
||||
submit = () => {
|
||||
|
||||
if (this.state.password.length === 0) {
|
||||
this.setState({errMsg: gettext('Please enter a password.')});
|
||||
return false;
|
||||
}
|
||||
if (this.state.password.length < webdavSecretMinLength) {
|
||||
this.setState({errMsg: gettext('The password is too short.')});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Utils.getStrengthLevel(this.state.password) < webdavSecretStrengthLevel) {
|
||||
this.setState({errMsg: gettext('The password is too weak. It should include at least {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols.').replace('{passwordStrengthLevel}', webdavSecretStrengthLevel)});
|
||||
return false;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
btnDisabled: true
|
||||
});
|
||||
this.props.updatePassword(this.state.password);
|
||||
|
||||
this.props.updatePassword(this.state.password.trim());
|
||||
}
|
||||
|
||||
handleInputChange = (e) => {
|
||||
let passwd = e.target.value.trim();
|
||||
this.setState({password: passwd});
|
||||
this.setState({password: e.target.value});
|
||||
}
|
||||
|
||||
togglePasswordVisible = () => {
|
||||
@@ -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,17 +67,21 @@ class UpdateWebdavPassword extends Component {
|
||||
|
||||
render() {
|
||||
const { toggle } = this.props;
|
||||
const passwordTip = gettext('(at least {passwordMinLength} characters and includes {passwordStrengthLevel} of the following: number, upper letter, lower letter and other symbols)').replace('{passwordMinLength}', webdavSecretMinLength).replace('{passwordStrengthLevel}', webdavSecretStrengthLevel);
|
||||
|
||||
return (
|
||||
<Modal centered={true} isOpen={true} toggle={toggle}>
|
||||
<ModalHeader toggle={toggle}>{gettext('WebDav Password')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<InputGroup className="">
|
||||
<InputGroup>
|
||||
<Input type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.password} onChange={this.handleInputChange} autoComplete="new-password"/>
|
||||
<InputGroupAddon addonType="append">
|
||||
<Button onClick={this.togglePasswordVisible}><i className={`fas ${this.state.isPasswordVisible ? 'fa-eye': 'fa-eye-slash'}`}></i></Button>
|
||||
<Button onClick={this.generatePassword}><i className="fas fa-magic"></i></Button>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<p className="form-text text-muted m-0">{passwordTip}</p>
|
||||
{this.state.errMsg && <Alert color="danger" className="m-0 mt-2">{gettext(this.state.errMsg)}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
|
||||
|
Reference in New Issue
Block a user