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

Show TBD message if the case that there already exists a user whose username matches ID of the newly created LDAP user

Yuki Takei 8 лет назад
Родитель
Сommit
fe03bcfeb6
3 измененных файлов с 21 добавлено и 1 удалено
  1. 1 1
      lib/models/external-account.js
  2. 6 0
      lib/routes/login-passport.js
  3. 14 0
      lib/views/login.html

+ 1 - 1
lib/models/external-account.js

@@ -70,9 +70,9 @@ class ExternalAccount {
 
           const User = ExternalAccount.crowi.model('User');
 
-          // TODO count and throw error if username is dupricated
           return User.count({username: usernameToBeRegistered})
             .then((count) => {
+              // throw Exception when count is not zero
               if (count > 0) {
                 throw new DuplicatedUsernameException(`username '${usernameToBeRegistered}' has already been existed`);
               }

+ 6 - 0
lib/routes/login-passport.js

@@ -69,6 +69,12 @@ module.exports = function(crowi, app) {
         req.flash('warningMessage', 'LDAP Server Error occured.');
         return next(); // pass and the flash message is displayed when all of authentications are failed.
       }
+      if (info) {
+        if (info.name != null && info.name === 'DuplicatedUsernameException') {
+          req.flash('isDuplicatedUsernameExceptionOccured', true);
+          return next();
+        }
+      }
       if (!user) { return next(); }
       req.logIn(user, (err) => {
         if (err) { return next(); }

+ 14 - 0
lib/views/login.html

@@ -28,6 +28,20 @@
       </div>
       {% endif %}
 
+      {#
+       # The case that there already exists a user whose username matches ID of the newly created LDAP user
+       # https://github.com/weseek/crowi-plus/issues/193
+       #}
+      {% set isDuplicatedUsernameExceptionOccured = req.flash('isDuplicatedUsernameExceptionOccured') %}
+      {% if isDuplicatedUsernameExceptionOccured != null %}
+      <div class="alert alert-warning">
+        <i class="fa fa-fw fa-info-circle"></i>
+        <strong>DuplicatedUsernameException occured</strong>
+        <p>Your LDAP authentication was succeess, but a new user is could not be created.<br>
+        See the issue <a href="https://github.com/weseek/crowi-plus/issues/193">#193</a>.</p>
+      </div>
+      {% endif %}
+
       {% set success = req.flash('successMessage') %}
       {% if success.length %}
       <div class="alert alert-success">