Răsfoiți Sursa

success to execute password reset

kaori 4 ani în urmă
părinte
comite
de4ac5b44d

+ 1 - 1
src/client/js/components/PasswordResetExecutionForm.jsx

@@ -38,7 +38,7 @@ const PasswordResetExecutionForm = (props) => {
       * the following code is just a reference
       */
 
-      await appContainer.apiPut('/forgot-password', {
+      await appContainer.apiv3Put('/forgot-password', {
         email, newPassword,
       });
 

+ 1 - 1
src/client/js/components/PasswordResetRequestForm.jsx

@@ -23,7 +23,7 @@ const PasswordResetRequestForm = (props) => {
     }
 
     try {
-      await appContainer.apiPost('/forgot-password', { email });
+      await appContainer.apiv3Post('/forgot-password', { email });
       toastSuccess(t('forgot_password.success_to_send_email'));
     }
     catch (err) {

+ 2 - 2
src/server/routes/apiv3/forgot-password.js

@@ -42,7 +42,7 @@ module.exports = (crowi) => {
     });
   }
 
-  router.put('/', async(req, res) => {
+  router.post('/', async(req, res) => {
     const { email } = req.body;
     const grobalLang = configManager.getConfig('crowi', 'app:globalLang');
     const i18n = req.language || grobalLang;
@@ -62,7 +62,7 @@ module.exports = (crowi) => {
     }
   });
 
-  router.put('/', validator.password, async(req, res) => {
+  router.put('/', /* validator.password, */ async(req, res) => {
     const { email, newPassword } = req.body;
 
     const user = await User.findOne({ email });

+ 48 - 48
src/server/routes/forgot-password.js

@@ -1,11 +1,11 @@
-const logger = require('@alias/logger')('growi:routes:forgot-password');
-const ApiResponse = require('../util/apiResponse');
+// const logger = require('@alias/logger')('growi:routes:forgot-password');
+// const ApiResponse = require('../util/apiResponse');
 
 module.exports = function(crowi, app) {
-  const PasswordResetOrder = crowi.model('PasswordResetOrder');
-  const User = crowi.model('User');
-  const { appService, mailService, configManager } = crowi;
-  const path = require('path');
+  // const PasswordResetOrder = crowi.model('PasswordResetOrder');
+  // const User = crowi.model('User');
+  // const { appService, mailService, configManager } = crowi;
+  // const path = require('path');
   const actions = {};
   const api = {};
   actions.api = api;
@@ -20,38 +20,38 @@ module.exports = function(crowi, app) {
     return res.render('reset-password', { email });
   };
 
-  async function sendPasswordResetEmail(email, url, i18n) {
-    return mailService.send({
-      to: email,
-      subject: 'Password Reset',
-      template: path.join(crowi.localeDir, `${i18n}/notifications/passwordReset.txt`),
-      vars: {
-        appTitle: appService.getAppTitle(),
-        email,
-        url,
-      },
-    });
-  }
+  // async function sendPasswordResetEmail(email, url, i18n) {
+  //   return mailService.send({
+  //     to: email,
+  //     subject: 'Password Reset',
+  //     template: path.join(crowi.localeDir, `${i18n}/notifications/passwordReset.txt`),
+  //     vars: {
+  //       appTitle: appService.getAppTitle(),
+  //       email,
+  //       url,
+  //     },
+  //   });
+  // }
 
-  api.post = async function(req, res) {
-    const { email } = req.body;
-    const grobalLang = configManager.getConfig('crowi', 'app:globalLang');
-    const i18n = req.language || grobalLang;
-    const appUrl = appService.getSiteUrl();
+  // api.post = async function(req, res) {
+  //   const { email } = req.body;
+  //   const grobalLang = configManager.getConfig('crowi', 'app:globalLang');
+  //   const i18n = req.language || grobalLang;
+  //   const appUrl = appService.getSiteUrl();
 
-    try {
-      const passwordResetOrderData = await PasswordResetOrder.createPasswordResetOrder(email);
-      const url = new URL(`/forgot-password/${passwordResetOrderData.token}`, appUrl);
-      const oneTimeUrl = url.href;
-      await sendPasswordResetEmail(email, oneTimeUrl, i18n);
-      return res.json(ApiResponse.success());
-    }
-    catch (err) {
-      const msg = 'Error occurred during password reset request procedure';
-      logger.error(err);
-      return res.json(ApiResponse.error(msg));
-    }
-  };
+  //   try {
+  //     const passwordResetOrderData = await PasswordResetOrder.createPasswordResetOrder(email);
+  //     const url = new URL(`/forgot-password/${passwordResetOrderData.token}`, appUrl);
+  //     const oneTimeUrl = url.href;
+  //     await sendPasswordResetEmail(email, oneTimeUrl, i18n);
+  //     return res.json(ApiResponse.success());
+  //   }
+  //   catch (err) {
+  //     const msg = 'Error occurred during password reset request procedure';
+  //     logger.error(err);
+  //     return res.json(ApiResponse.error(msg));
+  //   }
+  // };
 
   actions.error = function(req, res) {
     const { reason } = req.params;
@@ -62,20 +62,20 @@ module.exports = function(crowi, app) {
   };
 
 
-  api.put = async(req, res) => {
-    const { email, newPassword } = req.body;
+  // api.put = async(req, res) => {
+  //   const { email, newPassword } = req.body;
 
-    const user = await User.findOne({ email });
+  //   const user = await User.findOne({ email });
 
-    try {
-      const userData = await user.updatePassword(newPassword);
-      return res.apiv3({ userData });
-    }
-    catch (err) {
-      logger.error(err);
-      return res.json(ApiResponse.error('update-password-failed'));
-    }
-  };
+  //   try {
+  //     const userData = await user.updatePassword(newPassword);
+  //     return res.apiv3({ userData });
+  //   }
+  //   catch (err) {
+  //     logger.error(err);
+  //     return res.json(ApiResponse.error('update-password-failed'));
+  //   }
+  // };
 
 
   return actions;

+ 2 - 2
src/server/routes/index.js

@@ -178,10 +178,10 @@ module.exports = function(crowi, app) {
   app.post('/_api/hackmd.saveOnHackmd'   , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
 
   app.get('/forgot-password', forgotPassword.forgotPassword);
-  app.post('/_api/forgot-password', forgotPassword.api.post);
+  // app.post('/_api/forgot-password', forgotPassword.api.post);
   app.get('/forgot-password/:token'      , passwordReset, forgotPassword.resetPassword);
   app.get('/forgot-password/error/:reason'      , applicationInstalled, forgotPassword.error);
-  app.put('/_api/forgot-password'      , applicationInstalled, forgotPassword.api.put);
+  // app.put('/_api/forgot-password'      , applicationInstalled, forgotPassword.api.put);
 
   app.get('/share/:linkId', page.showSharedPage);