From 252d0f3924dd19aa4dd1900c6c00c41c84755d1e Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 12 Jul 2015 23:36:52 -0800 Subject: Fixes mm-1415 adding email bypass flag --- api/team.go | 2 +- api/user.go | 2 +- config/config.json | 3 ++- config/config_docker.json | 3 ++- utils/config.go | 1 + utils/mail.go | 13 +++++------ web/react/components/signup_user_complete.jsx | 33 +++++++++++++-------------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/api/team.go b/api/team.go index c4a0ca181..f9aeecd7e 100644 --- a/api/team.go +++ b/api/team.go @@ -68,7 +68,7 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if utils.Cfg.ServiceSettings.Mode == utils.MODE_DEV { + if utils.Cfg.ServiceSettings.Mode == utils.MODE_DEV || utils.Cfg.EmailSettings.ByPassEmail { m["follow_link"] = bodyPage.Props["Link"] } diff --git a/api/user.go b/api/user.go index 483ae67b5..3d1a2d3ae 100644 --- a/api/user.go +++ b/api/user.go @@ -293,7 +293,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !user.EmailVerified { + if !user.EmailVerified && !utils.Cfg.EmailSettings.ByPassEmail { c.Err = model.NewAppError("login", "Login failed because email address has not been verified", extraInfo) c.Err.StatusCode = http.StatusForbidden return diff --git a/config/config.json b/config/config.json index b0a019e8d..d5bb7e553 100644 --- a/config/config.json +++ b/config/config.json @@ -54,11 +54,12 @@ "ProfileHeight": 128 }, "EmailSettings": { + "ByPassEmail" : true, "SMTPUsername": "", "SMTPPassword": "", "SMTPServer": "", "UseTLS": false, - "FeedbackEmail": "feedback@xxxxxxmustbefilledin.com", + "FeedbackEmail": "", "FeedbackName": "", "ApplePushServer": "", "ApplePushCertPublic": "", diff --git a/config/config_docker.json b/config/config_docker.json index 85f0d9c73..91ed0ef10 100644 --- a/config/config_docker.json +++ b/config/config_docker.json @@ -54,9 +54,10 @@ "ProfileHeight": 128 }, "EmailSettings": { + "ByPassEmail" : true, "SMTPUsername": "", "SMTPPassword": "", - "SMTPServer": "localhost:25", + "SMTPServer": "", "UseTLS": false, "FeedbackEmail": "", "FeedbackName": "", diff --git a/utils/config.go b/utils/config.go index eb2ae3050..97cb99f3e 100644 --- a/utils/config.go +++ b/utils/config.go @@ -77,6 +77,7 @@ type ImageSettings struct { } type EmailSettings struct { + ByPassEmail bool SMTPUsername string SMTPPassword string SMTPServer string diff --git a/utils/mail.go b/utils/mail.go index 3cd37ffef..0fe7042b7 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -8,14 +8,14 @@ import ( "crypto/tls" "fmt" "github.com/mattermost/platform/model" + "html" "net" "net/mail" "net/smtp" - "html" ) func CheckMailSettings() *model.AppError { - if len(Cfg.EmailSettings.SMTPServer) == 0 { + if len(Cfg.EmailSettings.SMTPServer) == 0 || Cfg.EmailSettings.ByPassEmail { return model.NewAppError("CheckMailSettings", "No email settings present, mail will not be sent", "") } conn, err := connectToSMTPServer() @@ -79,6 +79,10 @@ func newSMTPClient(conn net.Conn) (*smtp.Client, *model.AppError) { func SendMail(to, subject, body string) *model.AppError { + if len(Cfg.EmailSettings.SMTPServer) == 0 || Cfg.EmailSettings.ByPassEmail { + return nil + } + fromMail := mail.Address{"", Cfg.EmailSettings.FeedbackEmail} toMail := mail.Address{"", to} @@ -95,11 +99,6 @@ func SendMail(to, subject, body string) *model.AppError { } message += "\r\n" + body + "" - if len(Cfg.EmailSettings.SMTPServer) == 0 { - l4g.Warn("Skipping sending of email because EmailSettings are not configured") - return nil - } - conn, err1 := connectToSMTPServer() if err1 != nil { return err1 diff --git a/web/react/components/signup_user_complete.jsx b/web/react/components/signup_user_complete.jsx index fb96cc99f..ef1eb1c62 100644 --- a/web/react/components/signup_user_complete.jsx +++ b/web/react/components/signup_user_complete.jsx @@ -46,25 +46,24 @@ module.exports = React.createClass({ function(data) { client.track('signup', 'signup_user_02_complete'); - if (data.email_verified) { - client.loginByEmail(this.props.domain, this.state.user.email, this.state.user.password, - function(data) { - UserStore.setLastDomain(this.props.domain); - UserStore.setLastEmail(this.state.user.email); - UserStore.setCurrentUser(data); - if (this.props.hash > 0) - BrowserStore.setGlobalItem(this.props.hash, JSON.stringify({wizard: "finished"})); - window.location.href = '/channels/town-square'; - }.bind(this), - function(err) { + client.loginByEmail(this.props.domain, this.state.user.email, this.state.user.password, + function(data) { + UserStore.setLastDomain(this.props.domain); + UserStore.setLastEmail(this.state.user.email); + UserStore.setCurrentUser(data); + if (this.props.hash > 0) + BrowserStore.setGlobalItem(this.props.hash, JSON.stringify({wizard: "finished"})); + window.location.href = '/channels/town-square'; + }.bind(this), + function(err) { + if (err.message == "Login failed because email address has not been verified") { + window.location.href = "/verify?email="+ encodeURIComponent(this.state.user.email) + "&domain=" + encodeURIComponent(this.props.domain); + } else { this.state.server_error = err.message; this.setState(this.state); - }.bind(this) - ); - } - else { - window.location.href = "/verify?email="+ encodeURIComponent(this.state.user.email) + "&domain=" + encodeURIComponent(this.props.domain); - } + } + }.bind(this) + ); }.bind(this), function(err) { this.state.server_error = err.message; -- cgit v1.2.3-1-g7c22