enforce maximum title length for topics and users

This commit is contained in:
or-else
2019-11-06 11:25:07 +03:00
parent c539e5f70d
commit 8c1b926008
4 changed files with 20 additions and 12 deletions
+3
View File
@@ -69,6 +69,9 @@ export const MAX_IMAGE_DIM = 768;
// hidden under "+X more" // hidden under "+X more"
export const MAX_ONLINE_IN_TOPIC = 4; export const MAX_ONLINE_IN_TOPIC = 4;
// Maximum length of topic title (and Private comment) or user name.
export const MAX_TITLE_LENGTH = 40;
// Link for "Contact Us". // Link for "Contact Us".
export const LINK_CONTACT_US = 'email:info@tinode.co'; export const LINK_CONTACT_US = 'email:info@tinode.co';
+3 -2
View File
@@ -9,6 +9,8 @@ import VisiblePassword from '../widgets/visible-password.jsx';
import LocalStorageUtil from '../lib/local-storage.js'; import LocalStorageUtil from '../lib/local-storage.js';
import { vcard } from '../lib/utils.js'; import { vcard } from '../lib/utils.js';
import { MAX_TITLE_LENGTH } from '../config.js';
export default class CreateAccountView extends React.PureComponent { export default class CreateAccountView extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -59,12 +61,11 @@ export default class CreateAccountView extends React.PureComponent {
handleSubmit(e) { handleSubmit(e) {
e.preventDefault(); e.preventDefault();
// TODO: check email for validity
this.setState({errorCleared: false}); this.setState({errorCleared: false});
this.props.onCreateAccount( this.props.onCreateAccount(
this.state.login.trim(), this.state.login.trim(),
this.state.password.trim(), this.state.password.trim(),
vcard(this.state.fn, this.state.imageDataUrl), vcard(this.state.fn.trim().substring(0, MAX_TITLE_LENGTH), this.state.imageDataUrl),
{'meth': 'email', 'val': this.state.email}); {'meth': 'email', 'val': this.state.email});
} }
+7 -6
View File
@@ -15,7 +15,7 @@ import MoreButton from '../widgets/more-button.jsx';
import PermissionsEditor from '../widgets/permissions-editor.jsx'; import PermissionsEditor from '../widgets/permissions-editor.jsx';
import TagManager from '../widgets/tag-manager.jsx'; import TagManager from '../widgets/tag-manager.jsx';
import { NO_ACCESS_MODE } from '../config.js'; import { MAX_TITLE_LENGTH, NO_ACCESS_MODE } from '../config.js';
import { makeImageUrl } from '../lib/blob-helpers.js'; import { makeImageUrl } from '../lib/blob-helpers.js';
import { arrayEqual, vcard } from '../lib/utils.js'; import { arrayEqual, vcard } from '../lib/utils.js';
@@ -277,17 +277,18 @@ class InfoView extends React.Component {
} }
handleFullNameUpdate(fn) { handleFullNameUpdate(fn) {
fn = fn.trim(); fn = fn.trim().substring(0, MAX_TITLE_LENGTH);
if (this.state.fullName !== fn) { if (this.state.fullName !== fn) {
this.setState({fullName: fn}); this.setState({fullName: fn});
this.props.onTopicDescUpdate(this.props.topic, vcard(fn, null), null); this.props.onTopicDescUpdate(this.props.topic, vcard(fn, null), null);
} }
} }
handlePrivateUpdate(priv) { handlePrivateUpdate(comment) {
if (this.state.priv !== priv) { comment = comment.trim().substring(0, MAX_TITLE_LENGTH);
this.setState({private: priv}); if (this.state.private !== comment) {
this.props.onTopicDescUpdate(this.props.topic, null, priv || Tinode.DEL_CHAR); this.setState({private: comment});
this.props.onTopicDescUpdate(this.props.topic, null, comment || Tinode.DEL_CHAR);
} }
} }
+7 -4
View File
@@ -4,6 +4,8 @@ import { FormattedMessage } from 'react-intl';
import AvatarUpload from './avatar-upload.jsx'; import AvatarUpload from './avatar-upload.jsx';
import TagManager from './tag-manager.jsx'; import TagManager from './tag-manager.jsx';
import { MAX_TITLE_LENGTH } from '../config.js';
export default class NewTopicGroup extends React.PureComponent { export default class NewTopicGroup extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -41,10 +43,11 @@ export default class NewTopicGroup extends React.PureComponent {
handleSubmit(e) { handleSubmit(e) {
e.preventDefault(); e.preventDefault();
if (this.state.fn && this.state.fn.trim()) {
this.props.onSubmit(this.state.fn.trim(), const fn = this.state.fn.trim().substring(0, MAX_TITLE_LENGTH);
this.state.imageDataUrl, this.state.private.trim(), const comment = this.state.private.trim().substring(0, MAX_TITLE_LENGTH);
this.state.tags); if (fn) {
this.props.onSubmit(fn, this.state.imageDataUrl, comment, this.state.tags);
} }
} }