Fix cancel button on username setting and other general improvements
Этот коммит содержится в:
@@ -157,7 +157,7 @@ func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreCha
|
|||||||
|
|
||||||
if count, err := us.GetMaster().Update(user); err != nil {
|
if count, err := us.GetMaster().Update(user); err != nil {
|
||||||
if IsUniqueConstraintError(err.Error(), "Email", "users_email_teamid_key") {
|
if IsUniqueConstraintError(err.Error(), "Email", "users_email_teamid_key") {
|
||||||
result.Err = model.NewAppError("SqlUserStore.Update", "This email is already taken. Please choose another", "user_id="+user.Id+", "+err.Error())
|
result.Err = model.NewAppError("SqlUserStore.Update", "This email is already taken. Please choose another.", "user_id="+user.Id+", "+err.Error())
|
||||||
} else if IsUniqueConstraintError(err.Error(), "Username", "users_username_teamid_key") {
|
} else if IsUniqueConstraintError(err.Error(), "Username", "users_username_teamid_key") {
|
||||||
result.Err = model.NewAppError("SqlUserStore.Update", "This username is already taken. Please choose another.", "user_id="+user.Id+", "+err.Error())
|
result.Err = model.NewAppError("SqlUserStore.Update", "This username is already taken. Please choose another.", "user_id="+user.Id+", "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
var UserStore = require('../../stores/user_store.jsx');
|
const SettingItemMin = require('../setting_item_min.jsx');
|
||||||
var ErrorStore = require('../../stores/error_store.jsx');
|
const SettingItemMax = require('../setting_item_max.jsx');
|
||||||
var SettingItemMin = require('../setting_item_min.jsx');
|
const SettingPicture = require('../setting_picture.jsx');
|
||||||
var SettingItemMax = require('../setting_item_max.jsx');
|
|
||||||
var SettingPicture = require('../setting_picture.jsx');
|
const UserStore = require('../../stores/user_store.jsx');
|
||||||
var client = require('../../utils/client.jsx');
|
const ErrorStore = require('../../stores/error_store.jsx');
|
||||||
var AsyncClient = require('../../utils/async_client.jsx');
|
|
||||||
var utils = require('../../utils/utils.jsx');
|
const Client = require('../../utils/client.jsx');
|
||||||
var assign = require('object-assign');
|
const AsyncClient = require('../../utils/async_client.jsx');
|
||||||
|
const Utils = require('../../utils/utils.jsx');
|
||||||
|
|
||||||
export default class UserSettingsGeneralTab extends React.Component {
|
export default class UserSettingsGeneralTab extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -32,17 +33,15 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
this.updatePicture = this.updatePicture.bind(this);
|
this.updatePicture = this.updatePicture.bind(this);
|
||||||
this.updateSection = this.updateSection.bind(this);
|
this.updateSection = this.updateSection.bind(this);
|
||||||
|
|
||||||
this.setupInitialState = this.setupInitialState.bind(this);
|
|
||||||
|
|
||||||
this.state = this.setupInitialState(props);
|
this.state = this.setupInitialState(props);
|
||||||
}
|
}
|
||||||
submitUsername(e) {
|
submitUsername(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var user = this.props.user;
|
const user = Object.assign({}, this.props.user);
|
||||||
var username = this.state.username.trim().toLowerCase();
|
const username = this.state.username.trim().toLowerCase();
|
||||||
|
|
||||||
var usernameError = utils.isValidUsername(username);
|
const usernameError = Utils.isValidUsername(username);
|
||||||
if (usernameError === 'Cannot use a reserved word as a username.') {
|
if (usernameError === 'Cannot use a reserved word as a username.') {
|
||||||
this.setState({clientError: 'This username is reserved, please choose a new one.'});
|
this.setState({clientError: 'This username is reserved, please choose a new one.'});
|
||||||
return;
|
return;
|
||||||
@@ -52,7 +51,7 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.username === username) {
|
if (user.username === username) {
|
||||||
this.setState({clientError: 'You must submit a new username'});
|
this.setState({clientError: 'You must submit a new username.', emailError: '', serverError: ''});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +62,11 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submitNickname(e) {
|
submitNickname(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var user = UserStore.getCurrentUser();
|
const user = Object.assign({}, this.props.user);
|
||||||
var nickname = this.state.nickname.trim();
|
const nickname = this.state.nickname.trim();
|
||||||
|
|
||||||
if (user.nickname === nickname) {
|
if (user.nickname === nickname) {
|
||||||
this.setState({clientError: 'You must submit a new nickname'});
|
this.setState({clientError: 'You must submit a new nickname.', emailError: '', serverError: ''});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +77,12 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submitName(e) {
|
submitName(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var user = UserStore.getCurrentUser();
|
const user = Object.assign({}, this.props.user);
|
||||||
var firstName = this.state.firstName.trim();
|
const firstName = this.state.firstName.trim();
|
||||||
var lastName = this.state.lastName.trim();
|
const lastName = this.state.lastName.trim();
|
||||||
|
|
||||||
if (user.first_name === firstName && user.last_name === lastName) {
|
if (user.first_name === firstName && user.last_name === lastName) {
|
||||||
this.setState({clientError: 'You must submit a new first or last name'});
|
this.setState({clientError: 'You must submit a new first or last name.', emailError: '', serverError: ''});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,21 +94,21 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submitEmail(e) {
|
submitEmail(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var user = UserStore.getCurrentUser();
|
const user = Object.assign({}, this.props.user);
|
||||||
var email = this.state.email.trim().toLowerCase();
|
const email = this.state.email.trim().toLowerCase();
|
||||||
var confirmEmail = this.state.confirmEmail.trim().toLowerCase();
|
const confirmEmail = this.state.confirmEmail.trim().toLowerCase();
|
||||||
|
|
||||||
if (user.email === email) {
|
if (user.email === email) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (email === '' || !utils.isEmail(email)) {
|
if (email === '' || !Utils.isEmail(email)) {
|
||||||
this.setState({emailError: 'Please enter a valid email address'});
|
this.setState({emailError: 'Please enter a valid email address.', clientError: '', serverError: ''});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (email !== confirmEmail) {
|
if (email !== confirmEmail) {
|
||||||
this.setState({emailError: 'The new emails you entered do not match'});
|
this.setState({emailError: 'The new emails you entered do not match.', clientError: '', serverError: ''});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
this.submitUser(user, true);
|
this.submitUser(user, true);
|
||||||
}
|
}
|
||||||
submitUser(user, emailUpdated) {
|
submitUser(user, emailUpdated) {
|
||||||
client.updateUser(user,
|
Client.updateUser(user,
|
||||||
() => {
|
() => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
AsyncClient.getMe();
|
AsyncClient.getMe();
|
||||||
@@ -130,13 +129,13 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
var state = this.setupInitialState(this.props);
|
let serverError;
|
||||||
if (err.message) {
|
if (err.message) {
|
||||||
state.serverError = err.message;
|
serverError = err.message;
|
||||||
} else {
|
} else {
|
||||||
state.serverError = err;
|
serverError = err;
|
||||||
}
|
}
|
||||||
this.setState(state);
|
this.setState({serverError, emailError: '', clientError: ''});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -151,10 +150,10 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var picture = this.state.picture;
|
const picture = this.state.picture;
|
||||||
|
|
||||||
if (picture.type !== 'image/jpeg' && picture.type !== 'image/png') {
|
if (picture.type !== 'image/jpeg' && picture.type !== 'image/png') {
|
||||||
this.setState({clientError: 'Only JPG or PNG images may be used for profile pictures'});
|
this.setState({clientError: 'Only JPG or PNG images may be used for profile pictures.'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,17 +161,17 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
formData.append('image', picture, picture.name);
|
formData.append('image', picture, picture.name);
|
||||||
this.setState({loadingPicture: true});
|
this.setState({loadingPicture: true});
|
||||||
|
|
||||||
client.uploadProfileImage(formData,
|
Client.uploadProfileImage(formData,
|
||||||
function imageUploadSuccess() {
|
() => {
|
||||||
this.submitActive = false;
|
this.submitActive = false;
|
||||||
AsyncClient.getMe();
|
AsyncClient.getMe();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}.bind(this),
|
},
|
||||||
function imageUploadFailure(err) {
|
(err) => {
|
||||||
var state = this.setupInitialState(this.props);
|
var state = this.setupInitialState(this.props);
|
||||||
state.serverError = err.message;
|
state.serverError = err.message;
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
}.bind(this)
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
updateUsername(e) {
|
updateUsername(e) {
|
||||||
@@ -205,34 +204,34 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
}
|
}
|
||||||
updateSection(section) {
|
updateSection(section) {
|
||||||
const emailChangeInProgress = this.state.emailChangeInProgress;
|
const emailChangeInProgress = this.state.emailChangeInProgress;
|
||||||
this.setState(assign({}, this.setupInitialState(this.props), {emailChangeInProgress: emailChangeInProgress, clientError: '', serverError: '', emailError: ''}));
|
this.setState(Object.assign({}, this.setupInitialState(this.props), {emailChangeInProgress, clientError: '', serverError: '', emailError: ''}));
|
||||||
this.submitActive = false;
|
this.submitActive = false;
|
||||||
this.props.updateSection(section);
|
this.props.updateSection(section);
|
||||||
}
|
}
|
||||||
setupInitialState(props) {
|
setupInitialState(props) {
|
||||||
var user = props.user;
|
const user = props.user;
|
||||||
|
|
||||||
return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname,
|
return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname,
|
||||||
email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailChangeInProgress: false};
|
email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailChangeInProgress: false};
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
var user = this.props.user;
|
const user = this.props.user;
|
||||||
|
|
||||||
var clientError = null;
|
let clientError = null;
|
||||||
if (this.state.clientError) {
|
if (this.state.clientError) {
|
||||||
clientError = this.state.clientError;
|
clientError = this.state.clientError;
|
||||||
}
|
}
|
||||||
var serverError = null;
|
let serverError = null;
|
||||||
if (this.state.serverError) {
|
if (this.state.serverError) {
|
||||||
serverError = this.state.serverError;
|
serverError = this.state.serverError;
|
||||||
}
|
}
|
||||||
var emailError = null;
|
let emailError = null;
|
||||||
if (this.state.emailError) {
|
if (this.state.emailError) {
|
||||||
emailError = this.state.emailError;
|
emailError = this.state.emailError;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nameSection;
|
let nameSection;
|
||||||
var inputs = [];
|
const inputs = [];
|
||||||
|
|
||||||
if (this.props.activeSection === 'name') {
|
if (this.props.activeSection === 'name') {
|
||||||
inputs.push(
|
inputs.push(
|
||||||
@@ -298,15 +297,15 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submit={this.submitName}
|
submit={this.submitName}
|
||||||
server_error={serverError}
|
server_error={serverError}
|
||||||
client_error={clientError}
|
client_error={clientError}
|
||||||
updateSection={function clearSection(e) {
|
updateSection={(e) => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this)}
|
}}
|
||||||
extraInfo={extraInfo}
|
extraInfo={extraInfo}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var fullName = '';
|
let fullName = '';
|
||||||
|
|
||||||
if (user.first_name && user.last_name) {
|
if (user.first_name && user.last_name) {
|
||||||
fullName = user.first_name + ' ' + user.last_name;
|
fullName = user.first_name + ' ' + user.last_name;
|
||||||
@@ -320,17 +319,17 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title='Full Name'
|
title='Full Name'
|
||||||
describe={fullName}
|
describe={fullName}
|
||||||
updateSection={function updateNameSection() {
|
updateSection={() => {
|
||||||
this.updateSection('name');
|
this.updateSection('name');
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var nicknameSection;
|
let nicknameSection;
|
||||||
if (this.props.activeSection === 'nickname') {
|
if (this.props.activeSection === 'nickname') {
|
||||||
let nicknameLabel = 'Nickname';
|
let nicknameLabel = 'Nickname';
|
||||||
if (utils.isMobile()) {
|
if (Utils.isMobile()) {
|
||||||
nicknameLabel = '';
|
nicknameLabel = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,10 +363,10 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submit={this.submitNickname}
|
submit={this.submitNickname}
|
||||||
server_error={serverError}
|
server_error={serverError}
|
||||||
client_error={clientError}
|
client_error={clientError}
|
||||||
updateSection={function clearSection(e) {
|
updateSection={(e) => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this)}
|
}}
|
||||||
extraInfo={extraInfo}
|
extraInfo={extraInfo}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -376,17 +375,17 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title='Nickname'
|
title='Nickname'
|
||||||
describe={UserStore.getCurrentUser().nickname}
|
describe={UserStore.getCurrentUser().nickname}
|
||||||
updateSection={function updateNicknameSection() {
|
updateSection={() => {
|
||||||
this.updateSection('nickname');
|
this.updateSection('nickname');
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var usernameSection;
|
let usernameSection;
|
||||||
if (this.props.activeSection === 'username') {
|
if (this.props.activeSection === 'username') {
|
||||||
let usernameLabel = 'Username';
|
let usernameLabel = 'Username';
|
||||||
if (utils.isMobile()) {
|
if (Utils.isMobile()) {
|
||||||
usernameLabel = '';
|
usernameLabel = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,10 +415,10 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submit={this.submitUsername}
|
submit={this.submitUsername}
|
||||||
server_error={serverError}
|
server_error={serverError}
|
||||||
client_error={clientError}
|
client_error={clientError}
|
||||||
updateSection={function clearSection(e) {
|
updateSection={(e) => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this)}
|
}}
|
||||||
extraInfo={extraInfo}
|
extraInfo={extraInfo}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -428,13 +427,14 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title='Username'
|
title='Username'
|
||||||
describe={UserStore.getCurrentUser().username}
|
describe={UserStore.getCurrentUser().username}
|
||||||
updateSection={function updateUsernameSection() {
|
updateSection={() => {
|
||||||
this.updateSection('username');
|
this.updateSection('username');
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var emailSection;
|
|
||||||
|
let emailSection;
|
||||||
if (this.props.activeSection === 'email') {
|
if (this.props.activeSection === 'email') {
|
||||||
const emailEnabled = global.window.mm_config.SendEmailNotifications === 'true';
|
const emailEnabled = global.window.mm_config.SendEmailNotifications === 'true';
|
||||||
const emailVerificationEnabled = global.window.mm_config.RequireEmailVerification === 'true';
|
const emailVerificationEnabled = global.window.mm_config.RequireEmailVerification === 'true';
|
||||||
@@ -507,10 +507,10 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
submit={submit}
|
submit={submit}
|
||||||
server_error={serverError}
|
server_error={serverError}
|
||||||
client_error={emailError}
|
client_error={emailError}
|
||||||
updateSection={function clearSection(e) {
|
updateSection={(e) => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -534,26 +534,26 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title='Email'
|
title='Email'
|
||||||
describe={describe}
|
describe={describe}
|
||||||
updateSection={function updateEmailSection() {
|
updateSection={() => {
|
||||||
this.updateSection('email');
|
this.updateSection('email');
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pictureSection;
|
let pictureSection;
|
||||||
if (this.props.activeSection === 'picture') {
|
if (this.props.activeSection === 'picture') {
|
||||||
pictureSection = (
|
pictureSection = (
|
||||||
<SettingPicture
|
<SettingPicture
|
||||||
title='Profile Picture'
|
title='Profile Picture'
|
||||||
submit={this.submitPicture}
|
submit={this.submitPicture}
|
||||||
src={'/api/v1/users/' + user.id + '/image?time=' + user.last_picture_update + '&' + utils.getSessionIndex()}
|
src={'/api/v1/users/' + user.id + '/image?time=' + user.last_picture_update + '&' + Utils.getSessionIndex()}
|
||||||
server_error={serverError}
|
server_error={serverError}
|
||||||
client_error={clientError}
|
client_error={clientError}
|
||||||
updateSection={function clearSection(e) {
|
updateSection={(e) => {
|
||||||
this.updateSection('');
|
this.updateSection('');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}.bind(this)}
|
}}
|
||||||
picture={this.state.picture}
|
picture={this.state.picture}
|
||||||
pictureChange={this.updatePicture}
|
pictureChange={this.updatePicture}
|
||||||
submitActive={this.submitActive}
|
submitActive={this.submitActive}
|
||||||
@@ -561,17 +561,17 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var minMessage = 'Click \'Edit\' to upload an image.';
|
let minMessage = 'Click \'Edit\' to upload an image.';
|
||||||
if (user.last_picture_update) {
|
if (user.last_picture_update) {
|
||||||
minMessage = 'Image last updated ' + utils.displayDate(user.last_picture_update);
|
minMessage = 'Image last updated ' + Utils.displayDate(user.last_picture_update);
|
||||||
}
|
}
|
||||||
pictureSection = (
|
pictureSection = (
|
||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title='Profile Picture'
|
title='Profile Picture'
|
||||||
describe={minMessage}
|
describe={minMessage}
|
||||||
updateSection={function updatePictureSection() {
|
updateSection={() => {
|
||||||
this.updateSection('picture');
|
this.updateSection('picture');
|
||||||
}.bind(this)}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -619,10 +619,10 @@ export default class UserSettingsGeneralTab extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserSettingsGeneralTab.propTypes = {
|
UserSettingsGeneralTab.propTypes = {
|
||||||
user: React.PropTypes.object,
|
user: React.PropTypes.object.isRequired,
|
||||||
updateSection: React.PropTypes.func,
|
updateSection: React.PropTypes.func.isRequired,
|
||||||
updateTab: React.PropTypes.func,
|
updateTab: React.PropTypes.func.isRequired,
|
||||||
activeSection: React.PropTypes.string,
|
activeSection: React.PropTypes.string.isRequired,
|
||||||
closeModal: React.PropTypes.func.isRequired,
|
closeModal: React.PropTypes.func.isRequired,
|
||||||
collapseModal: React.PropTypes.func.isRequired
|
collapseModal: React.PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user