Skip to content

Commit

Permalink
fix: key user does not exist #483
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Aug 2, 2024
1 parent b0d64e4 commit 2cce784
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions api/user/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/crypto"
"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"
Expand Down Expand Up @@ -165,14 +166,19 @@ func ResetOTP(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{
"status": len(api.CurrentUser(c).OTPSecret) > 0,
"status": status,
})
}

func SecureSessionStatus(c *gin.Context) {
cUser := api.CurrentUser(c)
if !cUser.EnabledOTP() {
u, ok := c.Get("user")
if !ok || !u.(*model.Auth).EnabledOTP() {
c.JSON(http.StatusOK, gin.H{
"status": false,
})
Expand All @@ -189,12 +195,13 @@ func SecureSessionStatus(c *gin.Context) {
return
}

if user.VerifySecureSessionID(ssid, cUser.ID) {
if user.VerifySecureSessionID(ssid, u.(*model.Auth).ID) {
c.JSON(http.StatusOK, gin.H{
"status": true,
})
return
}

c.JSON(http.StatusOK, gin.H{
"status": false,
})
Expand Down
2 changes: 1 addition & 1 deletion app/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AAlert: typeof import('ant-design-vue/es')['Alert']
Expand Down

0 comments on commit 2cce784

Please sign in to comment.