Browse Source

Merge pull request #1640 from weseek/reactify-admin/fix-LDAP-test-log

Reactify admin/fix ldap test log
Yuki Takei 6 years ago
parent
commit
f03b245b93

+ 15 - 1
src/client/js/components/Admin/Security/LdapAuthTestModal.jsx

@@ -6,7 +6,7 @@ import loggerFactory from '@alias/logger';
 import Modal from 'react-bootstrap/es/Modal';
 import Modal from 'react-bootstrap/es/Modal';
 
 
 import { createSubscribedElement } from '../../UnstatedUtils';
 import { createSubscribedElement } from '../../UnstatedUtils';
-import { toastError } from '../../../util/apiNotification';
+import { toastSuccess, toastError } from '../../../util/apiNotification';
 
 
 import AppContainer from '../../../services/AppContainer';
 import AppContainer from '../../../services/AppContainer';
 import AdminLdapSecurityContainer from '../../../services/AdminLdapSecurityContainer';
 import AdminLdapSecurityContainer from '../../../services/AdminLdapSecurityContainer';
@@ -22,6 +22,7 @@ class LdapAuthTestModal extends React.Component {
       username: '',
       username: '',
       password: '',
       password: '',
       logs: '',
       logs: '',
+      errorMessage: null,
     };
     };
 
 
     this.onChangeUsername = this.onChangeUsername.bind(this);
     this.onChangeUsername = this.onChangeUsername.bind(this);
@@ -68,8 +69,20 @@ class LdapAuthTestModal extends React.Component {
 
 
       // add logs
       // add logs
       if (response.err) {
       if (response.err) {
+        toastError(response.err);
         this.addLogs(response.err);
         this.addLogs(response.err);
       }
       }
+
+      if (response.status === 'warning') {
+        this.addLogs(response.message);
+        this.setState({ errorMessage: response.message });
+      }
+
+      if (response.status === 'success') {
+        toastSuccess(response.message);
+        this.setState({ errorMessage: null });
+      }
+
       if (response.ldapConfiguration) {
       if (response.ldapConfiguration) {
         const prettified = JSON.stringify(response.ldapConfiguration.server, undefined, 4);
         const prettified = JSON.stringify(response.ldapConfiguration.server, undefined, 4);
         this.addLogs(`LDAP Configuration : ${prettified}`);
         this.addLogs(`LDAP Configuration : ${prettified}`);
@@ -98,6 +111,7 @@ class LdapAuthTestModal extends React.Component {
           </Modal.Title>
           </Modal.Title>
         </Modal.Header>
         </Modal.Header>
         <Modal.Body>
         <Modal.Body>
+          {this.state.errorMessage != null && <div className="alert alert-warning">{this.state.errorMessage}</div>}
           <div className="row p-3">
           <div className="row p-3">
             <label htmlFor="username" className="col-xs-3 text-right">{t('username')}</label>
             <label htmlFor="username" className="col-xs-3 text-right">{t('username')}</label>
             <div className="col-xs-6">
             <div className="col-xs-6">

+ 11 - 10
src/server/routes/login-passport.js

@@ -7,6 +7,7 @@ module.exports = function(crowi, app) {
   const { URL } = require('url');
   const { URL } = require('url');
   const ExternalAccount = crowi.model('ExternalAccount');
   const ExternalAccount = crowi.model('ExternalAccount');
   const passportService = crowi.passportService;
   const passportService = crowi.passportService;
+  const ApiResponse = require('../util/apiResponse');
 
 
   /**
   /**
    * success handler
    * success handler
@@ -145,10 +146,10 @@ module.exports = function(crowi, app) {
   const testLdapCredentials = (req, res) => {
   const testLdapCredentials = (req, res) => {
     if (!passportService.isLdapStrategySetup) {
     if (!passportService.isLdapStrategySetup) {
       debug('LdapStrategy has not been set up');
       debug('LdapStrategy has not been set up');
-      return res.json({
+      return res.json(ApiResponse.success({
         status: 'warning',
         status: 'warning',
         message: 'LdapStrategy has not been set up',
         message: 'LdapStrategy has not been set up',
-      });
+      }));
     }
     }
 
 
     passport.authenticate('ldapauth', (err, user, info) => {
     passport.authenticate('ldapauth', (err, user, info) => {
@@ -158,36 +159,36 @@ module.exports = function(crowi, app) {
 
 
       if (err) { // DB Error
       if (err) { // DB Error
         logger.error('LDAP Server Error: ', err);
         logger.error('LDAP Server Error: ', err);
-        return res.json({
+        return res.json(ApiResponse.success({
           status: 'warning',
           status: 'warning',
           message: 'LDAP Server Error occured.',
           message: 'LDAP Server Error occured.',
           err,
           err,
-        });
+        }));
       }
       }
       if (info && info.message) {
       if (info && info.message) {
-        return res.json({
+        return res.json(ApiResponse.success({
           status: 'warning',
           status: 'warning',
           message: info.message,
           message: info.message,
           ldapConfiguration: req.ldapConfiguration,
           ldapConfiguration: req.ldapConfiguration,
           ldapAccountInfo: req.ldapAccountInfo,
           ldapAccountInfo: req.ldapAccountInfo,
-        });
+        }));
       }
       }
       if (user) {
       if (user) {
         // check groups
         // check groups
         if (!isValidLdapUserByGroupFilter(user)) {
         if (!isValidLdapUserByGroupFilter(user)) {
-          return res.json({
+          return res.json(ApiResponse.success({
             status: 'warning',
             status: 'warning',
             message: 'This user does not belong to any groups designated by the group search filter.',
             message: 'This user does not belong to any groups designated by the group search filter.',
             ldapConfiguration: req.ldapConfiguration,
             ldapConfiguration: req.ldapConfiguration,
             ldapAccountInfo: req.ldapAccountInfo,
             ldapAccountInfo: req.ldapAccountInfo,
-          });
+          }));
         }
         }
-        return res.json({
+        return res.json(ApiResponse.success({
           status: 'success',
           status: 'success',
           message: 'Successfully authenticated.',
           message: 'Successfully authenticated.',
           ldapConfiguration: req.ldapConfiguration,
           ldapConfiguration: req.ldapConfiguration,
           ldapAccountInfo: req.ldapAccountInfo,
           ldapAccountInfo: req.ldapAccountInfo,
-        });
+        }));
       }
       }
     })(req, res, () => {});
     })(req, res, () => {});
   };
   };