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

fix: 修复未输入新密码时提示修改成功

creamlike1024 7 месяцев назад
Родитель
Сommit
d859e3fa64
2 измененных файлов с 29 добавлено и 12 удалено
  1. 3 3
      controller/user.go
  2. 26 9
      web/src/components/PersonalSetting.js

+ 3 - 3
controller/user.go

@@ -616,9 +616,6 @@ func UpdateSelf(c *gin.Context) {
 }
 
 func checkUpdatePassword(originalPassword string, newPassword string, userId int) (updatePassword bool, err error) {
-	if newPassword == "" {
-		return
-	}
 	var currentUser *model.User
 	currentUser, err = model.GetUserById(userId, true)
 	if err != nil {
@@ -628,6 +625,9 @@ func checkUpdatePassword(originalPassword string, newPassword string, userId int
 		err = fmt.Errorf("原密码错误")
 		return
 	}
+	if newPassword == "" {
+		return
+	}
 	updatePassword = true
 	return
 }

+ 26 - 9
web/src/components/PersonalSetting.js

@@ -244,6 +244,10 @@ const PersonalSetting = () => {
       showError(t('请输入原密码!'));
       return;
     }
+    if (inputs.set_new_password === '') {
+      showError(t('请输入新密码!'));
+      return;
+    }
     if (inputs.original_password === inputs.set_new_password) {
       showError(t('新密码需要和原密码不一致!'));
       return;
@@ -826,8 +830,8 @@ const PersonalSetting = () => {
               </div>
             </Card>
             <Card style={{ marginTop: 10 }}>
-              <Tabs type="line" defaultActiveKey="notification">
-                <TabPane tab={t('通知设置')} itemKey="notification">
+              <Tabs type='line' defaultActiveKey='notification'>
+                <TabPane tab={t('通知设置')} itemKey='notification'>
                   <div style={{ marginTop: 20 }}>
                     <Typography.Text strong>{t('通知方式')}</Typography.Text>
                     <div style={{ marginTop: 10 }}>
@@ -1003,23 +1007,36 @@ const PersonalSetting = () => {
                     </Typography.Text>
                   </div>
                 </TabPane>
-                <TabPane tab={t('价格设置')} itemKey="price">
+                <TabPane tab={t('价格设置')} itemKey='price'>
                   <div style={{ marginTop: 20 }}>
-                    <Typography.Text strong>{t('接受未设置价格模型')}</Typography.Text>
+                    <Typography.Text strong>
+                      {t('接受未设置价格模型')}
+                    </Typography.Text>
                     <div style={{ marginTop: 10 }}>
                       <Checkbox
-                        checked={notificationSettings.acceptUnsetModelRatioModel}
-                        onChange={e => handleNotificationSettingChange('acceptUnsetModelRatioModel', e.target.checked)}
+                        checked={
+                          notificationSettings.acceptUnsetModelRatioModel
+                        }
+                        onChange={(e) =>
+                          handleNotificationSettingChange(
+                            'acceptUnsetModelRatioModel',
+                            e.target.checked,
+                          )
+                        }
                       >
                         {t('接受未设置价格模型')}
                       </Checkbox>
-                      <Typography.Text type="secondary" style={{ marginTop: 8, display: 'block' }}>
-                        {t('当模型没有设置价格时仍接受调用,仅当您信任该网站时使用,可能会产生高额费用')}
+                      <Typography.Text
+                        type='secondary'
+                        style={{ marginTop: 8, display: 'block' }}
+                      >
+                        {t(
+                          '当模型没有设置价格时仍接受调用,仅当您信任该网站时使用,可能会产生高额费用',
+                        )}
                       </Typography.Text>
                     </div>
                   </div>
                 </TabPane>
-
               </Tabs>
               <div style={{ marginTop: 20 }}>
                 <Button type='primary' onClick={saveNotificationSettings}>