From f29c6a5e027ba3505dd8771aa8c55568c80a7f19 Mon Sep 17 00:00:00 2001
From: Harrison Healey <harrisonmhealey@gmail.com>
Date: Sun, 5 Jun 2016 02:36:28 -0400
Subject: Changed noLoginId error message to be specified in i18n (#3239)

---
 webapp/components/login/login_controller.jsx | 34 ++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 10 deletions(-)

(limited to 'webapp/components/login/login_controller.jsx')

diff --git a/webapp/components/login/login_controller.jsx b/webapp/components/login/login_controller.jsx
index dc450dabd..2422db5f7 100644
--- a/webapp/components/login/login_controller.jsx
+++ b/webapp/components/login/login_controller.jsx
@@ -33,6 +33,9 @@ export default class LoginController extends React.Component {
         this.handlePasswordChange = this.handlePasswordChange.bind(this);
 
         this.state = {
+            ldapEnabled: global.window.mm_license.IsLicensed === 'true' && global.window.mm_config.EnableLdap === 'true',
+            usernameSigninEnabled: global.window.mm_config.EnableSignInWithUsername === 'true',
+            emailSigninEnabled: global.window.mm_config.EnableSignInWithEmail === 'true',
             loginId: '', // the browser will set a default for this
             password: '',
             showMfa: false
@@ -68,13 +71,24 @@ export default class LoginController extends React.Component {
         password = password.trim();
 
         if (!loginId) {
+            // it's slightly weird to be constructing the message ID, but it's a bit nicer than triply nested if statements
+            let msgId = 'login.no';
+            if (this.state.emailSigninEnabled) {
+                msgId += 'Email';
+            }
+            if (this.state.usernameSigninEnabled) {
+                msgId += 'Username';
+            }
+            if (this.state.ldapEnabled) {
+                msgId += 'LdapUsername';
+            }
+
             this.setState({
                 serverError: (
                     <FormattedMessage
-                        id='login.noLoginId'
-                        defaultMessage='Please enter your {loginId}'
+                        id={msgId}
                         values={{
-                            loginId: this.createLoginPlaceholder()
+                            ldapUsername: global.window.mm_config.LdapLoginFieldName || Utils.localizeMessage('login.ldapUsernameLower', 'LDAP username')
                         }}
                     />
                 )
@@ -195,9 +209,9 @@ export default class LoginController extends React.Component {
     }
 
     createLoginPlaceholder() {
-        const ldapEnabled = global.window.mm_config.EnableLdap === 'true';
-        const usernameSigninEnabled = global.window.mm_config.EnableSignInWithUsername === 'true';
-        const emailSigninEnabled = global.window.mm_config.EnableSignInWithEmail === 'true';
+        const ldapEnabled = this.state.ldapEnabled;
+        const usernameSigninEnabled = this.state.usernameSigninEnabled;
+        const emailSigninEnabled = this.state.emailSigninEnabled;
 
         const loginPlaceholders = [];
         if (emailSigninEnabled) {
@@ -212,7 +226,7 @@ export default class LoginController extends React.Component {
             if (global.window.mm_config.LdapLoginFieldName) {
                 loginPlaceholders.push(global.window.mm_config.LdapLoginFieldName);
             } else {
-                loginPlaceholders.push(Utils.localizeMessage('login.ldap_username', 'LDAP Username'));
+                loginPlaceholders.push(Utils.localizeMessage('login.ldapUsername', 'LDAP Username'));
             }
         }
 
@@ -276,11 +290,11 @@ export default class LoginController extends React.Component {
 
         const loginControls = [];
 
-        const ldapEnabled = global.window.mm_config.EnableLdap === 'true';
+        const ldapEnabled = this.state.ldapEnabled;
         const gitlabSigninEnabled = global.window.mm_config.EnableSignUpWithGitLab === 'true';
         const googleSigninEnabled = global.window.mm_config.EnableSignUpWithGoogle === 'true';
-        const usernameSigninEnabled = global.window.mm_config.EnableSignInWithUsername === 'true';
-        const emailSigninEnabled = global.window.mm_config.EnableSignInWithEmail === 'true';
+        const usernameSigninEnabled = this.state.usernameSigninEnabled;
+        const emailSigninEnabled = this.state.emailSigninEnabled;
 
         if (emailSigninEnabled || usernameSigninEnabled || ldapEnabled) {
             let errorClass = '';
-- 
cgit v1.2.3-1-g7c22

