fix: 自助修改密码后断开 VPN 连接并登出所有 Web 会话

- auth.go: ChangePassword 失效所有会话(不再排除当前会话),调用 KickUser 断开 VPN 隧道
- ProfileView.vue: 改密成功后 logout 清除 token,跳转登录页并携带 msg 参数
- LoginView.vue: 读取 query.msg 显示"密码已修改,请重新登录"绿色提示
- zh.ts/en.ts: 新增 login.passwordChanged 国际化 key
This commit is contained in:
2026-07-10 13:11:46 +08:00
parent fea3fc62f7
commit b8720f413d
5 changed files with 16 additions and 3 deletions
+1
View File
@@ -45,6 +45,7 @@ export default {
loginFailed: 'Login failed',
loggingIn: 'Logging in...',
loginButton: 'Login',
passwordChanged: 'Password changed, please log in again',
},
profile: {
title: 'Profile',
+1
View File
@@ -45,6 +45,7 @@ export default {
loginFailed: '登录失败',
loggingIn: '登录中...',
loginButton: '登录',
passwordChanged: '密码已修改,请重新登录',
},
profile: {
title: '用户信息',
+4 -1
View File
@@ -1,16 +1,18 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useAuthStore } from '@/stores/auth'
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
const { t } = useI18n()
const username = ref('')
const password = ref('')
const error = ref('')
const successMsg = ref(route.query.msg === 'password_changed' ? t('login.passwordChanged') : '')
const loading = ref(false)
async function handleLogin() {
@@ -71,6 +73,7 @@ async function handleLogin() {
/>
</div>
<p v-if="error" class="text-sm text-red-500">{{ error }}</p>
<p v-if="successMsg" class="text-sm text-green-500">{{ successMsg }}</p>
<button
type="submit"
:disabled="loading"
+4
View File
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useAuthStore } from '@/stores/auth'
const authStore = useAuthStore()
const router = useRouter()
const { t } = useI18n()
onMounted(async () => {
@@ -49,6 +51,8 @@ async function handleChangePassword() {
throw new Error(data.error || t('profile.passwordChangeFailed'))
}
showPasswordModal.value = false
authStore.logout()
router.push({ name: 'login', query: { msg: 'password_changed' } })
} catch (e: any) {
passwordError.value = e.message || t('profile.passwordChangeFailed')
} finally {
+6 -2
View File
@@ -8,6 +8,7 @@ import (
"lmvpn/internal/db"
"lmvpn/internal/middleware"
"lmvpn/internal/model"
"lmvpn/internal/vpn"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
@@ -143,8 +144,11 @@ func ChangePassword(c *gin.Context) {
return
}
sessionID, _ := c.Get("session_id")
db.DB.Model(&model.Session{}).Where("user_id = ? AND session_id != ?", userID, sessionID).Update("invalid", true)
db.DB.Model(&model.Session{}).Where("user_id = ?", userID).Update("invalid", true)
if vpn.VPN != nil && vpn.VPN.Running() {
vpn.VPN.KickUser(user.ID)
}
c.JSON(http.StatusOK, gin.H{"message": "密码修改成功"})
}