// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var Client = require('../../utils/client.jsx'); var AsyncClient = require('../../utils/async_client.jsx'); var crypto = require('crypto'); export default class EmailSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleTestConnection = this.handleTestConnection.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.buildConfig = this.buildConfig.bind(this); this.handleGenerateInvite = this.handleGenerateInvite.bind(this); this.handleGenerateReset = this.handleGenerateReset.bind(this); this.state = { sendEmailNotifications: this.props.config.EmailSettings.SendEmailNotifications, saveNeeded: false, serverError: null, emailSuccess: null, emailFail: null }; } handleChange(action) { var s = {saveNeeded: true, serverError: this.state.serverError}; if (action === 'sendEmailNotifications_true') { s.sendEmailNotifications = true; } if (action === 'sendEmailNotifications_false') { s.sendEmailNotifications = false; } this.setState(s); } buildConfig() { var config = this.props.config; config.EmailSettings.EnableSignUpWithEmail = React.findDOMNode(this.refs.allowSignUpWithEmail).checked; config.EmailSettings.SendEmailNotifications = React.findDOMNode(this.refs.sendEmailNotifications).checked; config.EmailSettings.RequireEmailVerification = React.findDOMNode(this.refs.requireEmailVerification).checked; config.EmailSettings.SendEmailNotifications = React.findDOMNode(this.refs.sendEmailNotifications).checked; config.EmailSettings.FeedbackName = React.findDOMNode(this.refs.feedbackName).value.trim(); config.EmailSettings.FeedbackEmail = React.findDOMNode(this.refs.feedbackEmail).value.trim(); config.EmailSettings.SMTPServer = React.findDOMNode(this.refs.SMTPServer).value.trim(); config.EmailSettings.SMTPPort = React.findDOMNode(this.refs.SMTPPort).value.trim(); config.EmailSettings.SMTPUsername = React.findDOMNode(this.refs.SMTPUsername).value.trim(); config.EmailSettings.SMTPPassword = React.findDOMNode(this.refs.SMTPPassword).value.trim(); config.EmailSettings.ConnectionSecurity = React.findDOMNode(this.refs.ConnectionSecurity).value.trim(); config.EmailSettings.InviteSalt = React.findDOMNode(this.refs.InviteSalt).value.trim(); if (config.EmailSettings.InviteSalt === '') { config.EmailSettings.InviteSalt = crypto.randomBytes(256).toString('base64').substring(0, 31); React.findDOMNode(this.refs.InviteSalt).value = config.EmailSettings.InviteSalt; } config.EmailSettings.PasswordResetSalt = React.findDOMNode(this.refs.PasswordResetSalt).value.trim(); if (config.EmailSettings.PasswordResetSalt === '') { config.EmailSettings.PasswordResetSalt = crypto.randomBytes(256).toString('base64').substring(0, 31); React.findDOMNode(this.refs.PasswordResetSalt).value = config.EmailSettings.PasswordResetSalt; } return config; } handleGenerateInvite(e) { e.preventDefault(); React.findDOMNode(this.refs.InviteSalt).value = crypto.randomBytes(256).toString('base64').substring(0, 31); var s = {saveNeeded: true, serverError: this.state.serverError}; this.setState(s); } handleGenerateReset(e) { e.preventDefault(); React.findDOMNode(this.refs.PasswordResetSalt).value = crypto.randomBytes(256).toString('base64').substring(0, 31); var s = {saveNeeded: true, serverError: this.state.serverError}; this.setState(s); } handleTestConnection(e) { e.preventDefault(); $('#connection-button').button('loading'); var config = this.buildConfig(); Client.testEmail( config, () => { this.setState({ sendEmailNotifications: config.EmailSettings.SendEmailNotifications, serverError: null, saveNeeded: true, emailSuccess: true, emailFail: null }); $('#connection-button').button('reset'); }, (err) => { this.setState({ sendEmailNotifications: config.EmailSettings.SendEmailNotifications, serverError: null, saveNeeded: true, emailSuccess: null, emailFail: err.message + ' - ' + err.detailed_error }); $('#connection-button').button('reset'); } ); } handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); var config = this.buildConfig(); Client.saveConfig( config, () => { AsyncClient.getConfig(); this.setState({ sendEmailNotifications: config.EmailSettings.SendEmailNotifications, serverError: null, saveNeeded: false, emailSuccess: null, emailFail: null }); $('#save-button').button('reset'); }, (err) => { this.setState({ sendEmailNotifications: config.EmailSettings.SendEmailNotifications, serverError: err.message, saveNeeded: true, emailSuccess: null, emailFail: null }); $('#save-button').button('reset'); } ); } render() { var serverError = ''; if (this.state.serverError) { serverError =
; } var saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } var emailSuccess = ''; if (this.state.emailSuccess) { emailSuccess = (
{'No errors were reported while sending an email. Please check your inbox to make sure.'}
); } var emailFail = ''; if (this.state.emailFail) { emailSuccess = (
{'Connection unsuccessful: ' + this.state.emailFail}
); } return (

{'Email Settings'}

{'Typically set to true in production. When true Mattermost will allow team creation and account signup utilizing email and password. You would set this to false if you only wanted to allow signup from a service like OAuth or LDAP.'}

{'Typically set to true in production. When true Mattermost will attempt to send email notifications. Developers may set this field to false skipping sending emails for faster development.'}

{'Typically set to true in production. When true Mattermost will not allow a user to login without first having recieved an email with a verification link. Developers may set this field to false so skip sending verification emails for faster development.'}

{'Name displayed on email account used when sending notification emails from Mattermost.'}

{'Email displayed on email account used when sending notification emails from Mattermost.'}

{' Obtain this credential from administrator setting up your email server.'}

{' Obtain this credential from administrator setting up your email server.'}

{'Location of SMTP email server.'}

{'Port of SMTP email server.'}

{'None'}{'Mattermost will send email over an unsecure connection.'}
{'TLS'}{'Encrypts the communication between Mattermost and your email server.'}
{'STARTTLS'}{'Takes an existing insecure connection and attempts to upgrade it to a secure connection using TLS.'}
{emailSuccess} {emailFail}

{'32-character salt added to signing of email invites.'}

{'32-character salt added to signing of password reset emails.'}

{serverError}
); } } EmailSettings.propTypes = { config: React.PropTypes.object };