// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import SettingItemMin from '../setting_item_min.jsx'; import SettingItemMax from '../setting_item_max.jsx'; import AccessHistoryModal from '../access_history_modal.jsx'; import ActivityLogModal from '../activity_log_modal.jsx'; import ToggleModalButton from '../toggle_modal_button.jsx'; import TeamStore from '../../stores/team_store.jsx'; import * as Client from '../../utils/client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; import Constants from '../../utils/constants.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'mm-intl'; const holders = defineMessages({ currentPasswordError: { id: 'user.settings.security.currentPasswordError', defaultMessage: 'Please enter your current password' }, passwordLengthError: { id: 'user.settings.security.passwordLengthError', defaultMessage: 'New passwords must be at least {chars} characters' }, passwordMatchError: { id: 'user.settings.security.passwordMatchError', defaultMessage: 'The new passwords you entered do not match' }, password: { id: 'user.settings.security.password', defaultMessage: 'Password' }, lastUpdated: { id: 'user.settings.security.lastUpdated', defaultMessage: 'Last updated {date} at {time}' }, method: { id: 'user.settings.security.method', defaultMessage: 'Sign-in Method' }, close: { id: 'user.settings.security.close', defaultMessage: 'Close' } }); class SecurityTab extends React.Component { constructor(props) { super(props); this.submitPassword = this.submitPassword.bind(this); this.updateCurrentPassword = this.updateCurrentPassword.bind(this); this.updateNewPassword = this.updateNewPassword.bind(this); this.updateConfirmPassword = this.updateConfirmPassword.bind(this); this.getDefaultState = this.getDefaultState.bind(this); this.createPasswordSection = this.createPasswordSection.bind(this); this.createSignInSection = this.createSignInSection.bind(this); this.state = this.getDefaultState(); } getDefaultState() { return { currentPassword: '', newPassword: '', confirmPassword: '', authService: this.props.user.auth_service }; } submitPassword(e) { e.preventDefault(); var user = this.props.user; var currentPassword = this.state.currentPassword; var newPassword = this.state.newPassword; var confirmPassword = this.state.confirmPassword; const {formatMessage} = this.props.intl; if (currentPassword === '') { this.setState({passwordError: formatMessage(holders.currentPasswordError), serverError: ''}); return; } if (newPassword.length < Constants.MIN_PASSWORD_LENGTH) { this.setState({passwordError: formatMessage(holders.passwordLengthError, {chars: Constants.MIN_PASSWORD_LENGTH}), serverError: ''}); return; } if (newPassword !== confirmPassword) { var defaultState = Object.assign(this.getDefaultState(), {passwordError: formatMessage(holders.passwordMatchError), serverError: ''}); this.setState(defaultState); return; } var data = {}; data.user_id = user.id; data.current_password = currentPassword; data.new_password = newPassword; Client.updatePassword(data, () => { this.props.updateSection(''); AsyncClient.getMe(); this.setState(this.getDefaultState()); }, (err) => { var state = this.getDefaultState(); if (err.message) { state.serverError = err.message; } else { state.serverError = err; } state.passwordError = ''; this.setState(state); } ); } updateCurrentPassword(e) { this.setState({currentPassword: e.target.value}); } updateNewPassword(e) { this.setState({newPassword: e.target.value}); } updateConfirmPassword(e) { this.setState({confirmPassword: e.target.value}); } createPasswordSection() { let updateSectionStatus; const {formatMessage} = this.props.intl; if (this.props.activeSection === 'password' && this.props.user.auth_service === '') { const inputs = []; inputs.push(