Просмотр исходного кода

ensure to show alert in login.html when LDAP configuration has something wrong

Yuki Takei 8 лет назад
Родитель
Сommit
203055d9f1
2 измененных файлов с 22 добавлено и 3 удалено
  1. 14 2
      lib/util/swigFunctions.js
  2. 8 1
      lib/views/login.html

+ 14 - 2
lib/util/swigFunctions.js

@@ -3,6 +3,7 @@ module.exports = function(crowi, app, req, locals) {
     , Page = crowi.model('Page')
     , Config = crowi.model('Config')
     , User = crowi.model('User')
+    , passportService = crowi.passportService
   ;
 
   locals.nodeVersion = function() {
@@ -24,9 +25,20 @@ module.exports = function(crowi, app, req, locals) {
     return req.csrfToken;
   };
 
-  locals.isEnabledLdap = function() {
+  /**
+   * return true if enabled and strategy has been setup successfully
+   */
+  locals.isLdapSetup = function() {
     var config = crowi.getConfig()
-    return Config.isEnabledPassport(config) && Config.isEnabledLdap(config);
+    return Config.isEnabledPassport(config) && Config.isEnabledPassportLdap(config) && passportService.isLdapStrategySetup;
+  }
+
+  /**
+   * return true if enabled but strategy has some problem
+   */
+  locals.isLdapSetupFailed = function() {
+    var config = crowi.getConfig()
+    return Config.isEnabledPassport(config) && Config.isEnabledPassportLdap(config) && !passportService.isLdapStrategySetup;
   }
 
   locals.googleLoginEnabled = function() {

+ 8 - 1
lib/views/login.html

@@ -21,6 +21,13 @@
     <h2>{{ t('Sign in') }}</h2>
 
     <div id="login-form-errors">
+      {% if isLdapSetupFailed() %}
+      <div class="alert alert-warning">
+        LDAP is enabled but the configuration has something wrong.<br>
+        <small>(set the environment variables <code>DEBUG=crowi:service:PassportService</code> and get the logs)</small>
+      </div>
+      {% endif %}
+
       {% set success = req.flash('successMessage') %}
       {% if success.length %}
       <div class="alert alert-success">
@@ -49,7 +56,7 @@
       <div class="input-group">
         <span class="input-group-addon"><i class="fa fa-fw fa-user"></i></span>
         <input type="text" class="form-control" placeholder="Username or E-mail" name="loginForm[username]">
-        {% if isEnabledLdap() %}
+        {% if isLdapSetup() %}
         <span class="input-group-addon">
           <small class="text-primary">
             <i class="fa fa-fw fa-check-circle"></i> LDAP