From d1d13b620f161f5998e780c5f04ae47c598e0bef Mon Sep 17 00:00:00 2001 From: Jacky Date: Mon, 3 Mar 2025 03:40:09 +0000 Subject: [PATCH] feat(cli): reset init user password --- api/user/user.go | 7 ++ app/src/components/OTPInput/OTPInput.vue | 4 +- app/src/views/other/Login.vue | 1 - internal/cmd/main.go | 6 ++ internal/user/reset_password.go | 97 ++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 internal/user/reset_password.go diff --git a/api/user/user.go b/api/user/user.go index d36d8c3e..e695ac44 100644 --- a/api/user/user.go +++ b/api/user/user.go @@ -3,6 +3,7 @@ package user import ( "github.com/0xJacky/Nginx-UI/internal/user" "github.com/0xJacky/Nginx-UI/model" + "github.com/0xJacky/Nginx-UI/query" "github.com/0xJacky/Nginx-UI/settings" "github.com/gin-gonic/gin" "github.com/uozi-tech/cosy" @@ -40,6 +41,12 @@ func InitManageUserRouter(g *gin.RouterGroup) { } }) c.BeforeDecodeHook(encryptPassword) + c.ExecutedHook(func(ctx *cosy.Ctx[model.User]) { + if ctx.Payload["password"] != "" { + a := query.AuthToken + _, _ = a.Where(a.UserID.Eq(ctx.ID)).Delete() + } + }) }) c.DestroyHook(func(c *cosy.Ctx[model.User]) { diff --git a/app/src/components/OTPInput/OTPInput.vue b/app/src/components/OTPInput/OTPInput.vue index 6841b052..7f6ffd03 100644 --- a/app/src/components/OTPInput/OTPInput.vue +++ b/app/src/components/OTPInput/OTPInput.vue @@ -3,7 +3,9 @@ import VOtpInput from 'vue3-otp-input' const emit = defineEmits(['onComplete']) -const data = defineModel() +const data = defineModel({ + default: '', +}) // eslint-disable-next-line vue/require-typed-ref const refOtp = ref() diff --git a/app/src/views/other/Login.vue b/app/src/views/other/Login.vue index 9295e2bd..6ff824be 100644 --- a/app/src/views/other/Login.vue +++ b/app/src/views/other/Login.vue @@ -190,7 +190,6 @@ async function handlePasskeyLogin() {