fix: key user does not exist #483

This commit is contained in:
Jacky 2024-08-02 20:14:45 +08:00
parent b0d64e41e0
commit 2cce7849f2
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
2 changed files with 12 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/0xJacky/Nginx-UI/api" "github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/crypto" "github.com/0xJacky/Nginx-UI/internal/crypto"
"github.com/0xJacky/Nginx-UI/internal/user" "github.com/0xJacky/Nginx-UI/internal/user"
"github.com/0xJacky/Nginx-UI/model"
"github.com/0xJacky/Nginx-UI/query" "github.com/0xJacky/Nginx-UI/query"
"github.com/0xJacky/Nginx-UI/settings" "github.com/0xJacky/Nginx-UI/settings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -165,14 +166,19 @@ func ResetOTP(c *gin.Context) {
} }
func OTPStatus(c *gin.Context) { func OTPStatus(c *gin.Context) {
status := false
u, ok := c.Get("user")
if ok {
status = u.(*model.Auth).EnabledOTP()
}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": len(api.CurrentUser(c).OTPSecret) > 0, "status": status,
}) })
} }
func SecureSessionStatus(c *gin.Context) { func SecureSessionStatus(c *gin.Context) {
cUser := api.CurrentUser(c) u, ok := c.Get("user")
if !cUser.EnabledOTP() { if !ok || !u.(*model.Auth).EnabledOTP() {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": false, "status": false,
}) })
@ -189,12 +195,13 @@ func SecureSessionStatus(c *gin.Context) {
return return
} }
if user.VerifySecureSessionID(ssid, cUser.ID) { if user.VerifySecureSessionID(ssid, u.(*model.Auth).ID) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": true, "status": true,
}) })
return return
} }
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"status": false, "status": false,
}) })

2
app/components.d.ts vendored
View file

@ -1,10 +1,10 @@
/* eslint-disable */ /* eslint-disable */
/* prettier-ignore */
// @ts-nocheck // @ts-nocheck
// Generated by unplugin-vue-components // Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399 // Read more: https://github.com/vuejs/core/pull/3399
export {} export {}
/* prettier-ignore */
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
AAlert: typeof import('ant-design-vue/es')['Alert'] AAlert: typeof import('ant-design-vue/es')['Alert']