Explorar el Código

impl disassociate

Yuki Takei hace 8 años
padre
commit
37cc5177b9
Se han modificado 2 ficheros con 25 adiciones y 4 borrados
  1. 22 2
      lib/routes/me.js
  2. 3 2
      lib/views/me/external-accounts.html

+ 22 - 2
lib/routes/me.js

@@ -178,8 +178,28 @@ module.exports = function(crowi, app) {
   }
 
   actions.externalAccounts.disassociate = function(req, res) {
-    // TODO impl
-    // TODO check password is set
+
+    const redirectWithFlash = (type, msg) => {
+      req.flash(type, msg);
+      return res.redirect('/me/external-accounts');
+    }
+
+    if (req.body == null) {
+      redirectWithFlash('errorMessage', 'Invalid form.');
+    }
+
+    const providerType = req.body.providerType;
+    const accountId = req.body.accountId;
+    const userData = req.user;
+
+    ExternalAccount.deleteOne({providerType, accountId, user: userData})
+      .then(() => {
+        return redirectWithFlash('successMessage', 'Successfully disassociated.');
+      })
+      .catch((err) => {
+        return redirectWithFlash('errorMessage', err.message);
+      });
+
   }
 
   actions.externalAccounts.associateLdap = function(req, res) {

+ 3 - 2
lib/views/me/external-accounts.html

@@ -132,6 +132,7 @@
             <div id="passport-ldap" class="tab-pane active" role="tabpanel" >
               <div id="form-box">
                 <form id="formLdapAssociation" method="post" class="form-horizontal" role="form">
+                  <div class="alert-container"></div>
                   <fieldset>
                     <div class="form-group">
                       <label for="username" class="col-xs-3 control-label">{{ t('Username') }}</label>
@@ -197,12 +198,12 @@
        */
       function testAssociateLdap() {
         function showMessage(formId, msg, status) {
-          $('#' + formId + ' > .alert').remove();
+          $('#' + formId + ' .alert-container .alert').remove();
 
           var $message = $('<p class="alert"></p>');
           $message.addClass('alert-' + status);
           $message.html(msg.replace('\n', '<br>'));
-          $message.insertBefore('#' + formId);
+          $message.appendTo('#' + formId + '> .alert-container');
 
           if (status == 'success') {
             setTimeout(function()