浏览代码

get password

itizawa 6 年之前
父节点
当前提交
825131c65a
共有 2 个文件被更改,包括 40 次插入17 次删除
  1. 21 14
      src/client/js/components/Me/PasswordSettings.jsx
  2. 19 3
      src/server/routes/apiv3/personal-setting.js

+ 21 - 14
src/client/js/components/Me/PasswordSettings.jsx

@@ -20,21 +20,28 @@ class PasswordSettings extends React.Component {
 
 
     this.state = {
     this.state = {
       retrieveError: null,
       retrieveError: null,
+      password: '',
       oldPassword: '',
       oldPassword: '',
       newPassword: '',
       newPassword: '',
       newPasswordConfirm: '',
       newPasswordConfirm: '',
     };
     };
 
 
-    this.retrievePassword();
-
     this.retrievePassword = this.retrievePassword.bind(this);
     this.retrievePassword = this.retrievePassword.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
     this.onClickSubmit = this.onClickSubmit.bind(this);
     this.onChangeOldPassword = this.onChangeOldPassword.bind(this);
     this.onChangeOldPassword = this.onChangeOldPassword.bind(this);
   }
   }
 
 
+  componentDidMount() {
+    this.retrievePassword();
+  }
+
   async retrievePassword() {
   async retrievePassword() {
+    const { appContainer } = this.props;
+
     try {
     try {
-    // TODO GW-1136 create apiV3 for updating password
+      const res = await appContainer.apiv3Get('/personal-setting/password');
+      const { password } = res.data;
+      this.setState({ password });
     }
     }
     catch (err) {
     catch (err) {
       this.setState({ retrieveError: err });
       this.setState({ retrieveError: err });
@@ -80,18 +87,18 @@ class PasswordSettings extends React.Component {
         </div>
         </div>
         {(this.state.password != null)
         {(this.state.password != null)
         && (
         && (
-        <div className="row mb-3">
-          <label htmlFor="oldPassword" className="col-xs-3 text-right">{ t('personal_settings.current_password') }</label>
-          <div className="col-xs-6">
-            <input
-              className="form-control"
-              type="password"
-              name="oldPassword"
-              value={this.state.oldPassword}
-              onChange={(e) => { this.onChangeOldPassword(e.target.value) }}
-            />
+          <div className="row mb-3">
+            <label htmlFor="oldPassword" className="col-xs-3 text-right">{ t('personal_settings.current_password') }</label>
+            <div className="col-xs-6">
+              <input
+                className="form-control"
+                type="password"
+                name="oldPassword"
+                value={this.state.oldPassword}
+                onChange={(e) => { this.onChangeOldPassword(e.target.value) }}
+              />
+            </div>
           </div>
           </div>
-        </div>
         )}
         )}
         <div className="row mb-3">
         <div className="row mb-3">
           <label htmlFor="newPassword" className="col-xs-3 text-right">{t('personal_settings.new_password') }</label>
           <label htmlFor="newPassword" className="col-xs-3 text-right">{t('personal_settings.new_password') }</label>

+ 19 - 3
src/server/routes/apiv3/personal-setting.js

@@ -35,6 +35,7 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *            type: boolean
  *            type: boolean
  */
  */
 module.exports = (crowi) => {
 module.exports = (crowi) => {
+  const accessTokenParser = require('../../middleware/access-token-parser')(crowi);
   const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
   const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
   const csrf = require('../../middleware/csrf')(crowi);
   const csrf = require('../../middleware/csrf')(crowi);
 
 
@@ -72,7 +73,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: personal params
    *                      description: personal params
    */
    */
-  router.get('/', loginRequiredStrictly, async(req, res) => {
+  router.get('/', accessTokenParser, loginRequiredStrictly, async(req, res) => {
     const currentUser = await User.findUserByUsername(req.user.username);
     const currentUser = await User.findUserByUsername(req.user.username);
     return res.apiv3({ currentUser });
     return res.apiv3({ currentUser });
   });
   });
@@ -103,7 +104,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: personal params
    *                      description: personal params
    */
    */
-  router.put('/', loginRequiredStrictly, csrf, validator.personal, ApiV3FormValidator, async(req, res) => {
+  router.put('/', accessTokenParser, loginRequiredStrictly, csrf, validator.personal, ApiV3FormValidator, async(req, res) => {
 
 
     try {
     try {
       const user = await User.findOne({ _id: req.user.id });
       const user = await User.findOne({ _id: req.user.id });
@@ -143,7 +144,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      type: object
    *                      description: array of external accounts
    *                      description: array of external accounts
    */
    */
-  router.get('/external-accounts', loginRequiredStrictly, async(req, res) => {
+  router.get('/external-accounts', accessTokenParser, loginRequiredStrictly, async(req, res) => {
     const userData = req.user;
     const userData = req.user;
 
 
     try {
     try {
@@ -157,5 +158,20 @@ module.exports = (crowi) => {
 
 
   });
   });
 
 
+  // TODO swagger
+  router.get('/password', accessTokenParser, loginRequiredStrictly, async(req, res) => {
+
+    try {
+      const user = await User.findOne({ _id: req.user.id });
+      const { password } = user;
+      return res.apiv3({ password });
+    }
+    catch (err) {
+      logger.error(err);
+      return res.apiv3Err('get-accounts-password');
+    }
+  });
+
+
   return router;
   return router;
 };
 };