1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 22:01:06 +00:00

Merge pull request #3411 from haiwen/share-module-improve

repair generator password bug
This commit is contained in:
Daniel Pan
2019-05-06 16:49:40 +08:00
committed by GitHub
5 changed files with 29 additions and 8 deletions

View File

@@ -3,8 +3,9 @@ import PropTypes from 'prop-types';
import moment from 'moment'; import moment from 'moment';
import copy from 'copy-to-clipboard'; import copy from 'copy-to-clipboard';
import { Button, Form, FormGroup, Label, Input, InputGroup, InputGroupAddon, Alert } from 'reactstrap'; import { Button, Form, FormGroup, Label, Input, InputGroup, InputGroupAddon, Alert } from 'reactstrap';
import { gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax } from '../../utils/constants'; import { gettext, shareLinkExpireDaysMin, shareLinkExpireDaysMax, shareLinkPasswordMinLength } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import SharedLinkInfo from '../../models/shared-link-info'; import SharedLinkInfo from '../../models/shared-link-info';
import toaster from '../toast'; import toaster from '../toast';
@@ -68,7 +69,7 @@ class GenerateShareLink extends React.Component {
} }
generatePassword = () => { generatePassword = () => {
let val = Math.random().toString(36).substr(5); let val = Utils.generatePassword(shareLinkPasswordMinLength);
this.setState({ this.setState({
password: val, password: val,
passwdnew: val passwdnew: val
@@ -165,7 +166,7 @@ class GenerateShareLink extends React.Component {
this.setState({errorInfo: 'Please enter password'}); this.setState({errorInfo: 'Please enter password'});
return false; return false;
} }
if (password.length < 8) { if (password.length < shareLinkPasswordMinLength) {
this.setState({errorInfo: 'Password is too short'}); this.setState({errorInfo: 'Password is too short'});
return false; return false;
} }
@@ -237,6 +238,10 @@ class GenerateShareLink extends React.Component {
} }
render() { render() {
let passwordLengthTip = gettext('(at least {passwordLength} characters)');
passwordLengthTip = passwordLengthTip.replace('{passwordLength}', shareLinkPasswordMinLength);
if (this.state.sharedLinkInfo) { if (this.state.sharedLinkInfo) {
let sharedLinkInfo = this.state.sharedLinkInfo; let sharedLinkInfo = this.state.sharedLinkInfo;
return ( return (
@@ -293,7 +298,7 @@ class GenerateShareLink extends React.Component {
{this.state.isShowPasswordInput && {this.state.isShowPasswordInput &&
<FormGroup className="link-operation-content"> <FormGroup className="link-operation-content">
{/* todo translate */} {/* todo translate */}
<Label className="font-weight-bold">{gettext('Password')}</Label>{' '}<span className="tip">{gettext('(at least 8 characters)')}</span> <Label className="font-weight-bold">{gettext('Password')}</Label>{' '}<span className="tip">{passwordLengthTip}</span>
<InputGroup className="passwd"> <InputGroup className="passwd">
<Input type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.password || ''} onChange={this.inputPassword}/> <Input type={this.state.isPasswordVisible ? 'text' : 'password'} value={this.state.password || ''} onChange={this.inputPassword}/>
<InputGroupAddon addonType="append"> <InputGroupAddon addonType="append">

View File

@@ -2,8 +2,9 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import copy from 'copy-to-clipboard'; import copy from 'copy-to-clipboard';
import { Button, Form, FormGroup, FormText, Label, Input, InputGroup, InputGroupAddon, Alert } from 'reactstrap'; import { Button, Form, FormGroup, FormText, Label, Input, InputGroup, InputGroupAddon, Alert } from 'reactstrap';
import { gettext } from '../../utils/constants'; import { gettext, shareLinkPasswordMinLength } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import SharedUploadInfo from '../../models/shared-upload-info'; import SharedUploadInfo from '../../models/shared-upload-info';
import toaster from '../toast'; import toaster from '../toast';
@@ -56,7 +57,7 @@ class GenerateUploadLink extends React.Component {
} }
generatePassword = () => { generatePassword = () => {
let val = Math.random().toString(36).substr(5); let val = Utils.generatePassword(shareLinkPasswordMinLength);
this.setState({ this.setState({
password: val, password: val,
passwordnew: val passwordnew: val
@@ -84,7 +85,7 @@ class GenerateUploadLink extends React.Component {
errorInfo: gettext('Please enter password') errorInfo: gettext('Please enter password')
}); });
} }
else if (this.state.showPasswordInput && (this.state.showPasswordInput && this.state.password.length < 8)) { else if (this.state.showPasswordInput && (this.state.showPasswordInput && this.state.password.length < shareLinkPasswordMinLength)) {
this.setState({ this.setState({
errorInfo: gettext('Password is too short') errorInfo: gettext('Password is too short')
}); });
@@ -121,6 +122,10 @@ class GenerateUploadLink extends React.Component {
} }
render() { render() {
let passwordLengthTip = gettext('(at least {passwordLength} characters)');
passwordLengthTip = passwordLengthTip.replace('{passwordLength}', shareLinkPasswordMinLength);
if (this.state.sharedUploadInfo) { if (this.state.sharedUploadInfo) {
let sharedUploadInfo = this.state.sharedUploadInfo; let sharedUploadInfo = this.state.sharedUploadInfo;
return ( return (
@@ -151,7 +156,7 @@ class GenerateUploadLink extends React.Component {
{this.state.showPasswordInput && {this.state.showPasswordInput &&
<FormGroup className="link-operation-content"> <FormGroup className="link-operation-content">
{/* todo translate */} {/* todo translate */}
<Label className="font-weight-bold">{gettext('Password')}</Label>{' '}<span className="tip">{gettext('(at least 8 characters)')}</span> <Label className="font-weight-bold">{gettext('Password')}</Label>{' '}<span className="tip">{passwordLengthTip}</span>
<InputGroup className="passwd"> <InputGroup className="passwd">
<Input type={this.state.passwordVisible ? 'text':'password'} value={this.state.password || ''} onChange={this.inputPassword}/> <Input type={this.state.passwordVisible ? 'text':'password'} value={this.state.password || ''} onChange={this.inputPassword}/>
<InputGroupAddon addonType="append"> <InputGroupAddon addonType="append">

View File

@@ -35,6 +35,7 @@ export const enableUploadFolder = window.app.pageOptions.enableUploadFolder ===
export const enableResumableFileUpload = window.app.pageOptions.enableResumableFileUpload === 'True'; export const enableResumableFileUpload = window.app.pageOptions.enableResumableFileUpload === 'True';
export const storages = window.app.pageOptions.storages; // storage backends export const storages = window.app.pageOptions.storages; // storage backends
export const enableRepoSnapshotLabel = window.app.pageOptions.enableRepoSnapshotLabel; export const enableRepoSnapshotLabel = window.app.pageOptions.enableRepoSnapshotLabel;
export const shareLinkPasswordMinLength = window.app.pageOptions.shareLinkPasswordMinLength;
export const shareLinkExpireDaysMin = window.app.pageOptions.shareLinkExpireDaysMin; export const shareLinkExpireDaysMin = window.app.pageOptions.shareLinkExpireDaysMin;
export const shareLinkExpireDaysMax = window.app.pageOptions.shareLinkExpireDaysMax; export const shareLinkExpireDaysMax = window.app.pageOptions.shareLinkExpireDaysMax;
export const maxFileName = window.app.pageOptions.maxFileName; export const maxFileName = window.app.pageOptions.maxFileName;

View File

@@ -813,4 +813,13 @@ export const Utils = {
} }
}, },
generatePassword: function(passwordLength) {
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789';
let password = '';
for (let i = 0; i < passwordLength; i++) {
password += possible.charAt(Math.floor(Math.random() * possible.length));
}
return password;
}
}; };

View File

@@ -73,6 +73,7 @@
return storages; return storages;
})(), })(),
enableRepoSnapshotLabel: {% if enable_repo_snapshot_label %} true {% else %} false {% endif %}, enableRepoSnapshotLabel: {% if enable_repo_snapshot_label %} true {% else %} false {% endif %},
shareLinkPasswordMinLength: {{ share_link_password_min_length }},
shareLinkExpireDaysMin: "{{ share_link_expire_days_min }}", shareLinkExpireDaysMin: "{{ share_link_expire_days_min }}",
shareLinkExpireDaysMax: "{{ share_link_expire_days_max }}", shareLinkExpireDaysMax: "{{ share_link_expire_days_max }}",
maxFileName: "{{ max_file_name }}", maxFileName: "{{ max_file_name }}",