mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
chore(config): merge userConfig with defaultConfig and add a lock (#164)
* chore(config): merge userConfig with defaultConfig and add a lock * chore(config): remove lock for LoadConfig
This commit is contained in:
20
web.go
20
web.go
@@ -147,8 +147,6 @@ func handleWebRTCSession(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleLogin(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
if config.LocalAuthMode == "noPassword" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Login is disabled in noPassword mode"})
|
||||
return
|
||||
@@ -161,7 +159,6 @@ func handleLogin(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
LoadConfig()
|
||||
err := bcrypt.CompareHashAndPassword([]byte(config.HashedPassword), []byte(req.Password))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid password"})
|
||||
@@ -177,7 +174,6 @@ func handleLogin(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleLogout(c *gin.Context) {
|
||||
LoadConfig()
|
||||
config.LocalAuthToken = ""
|
||||
if err := SaveConfig(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to save configuration"})
|
||||
@@ -191,8 +187,6 @@ func handleLogout(c *gin.Context) {
|
||||
|
||||
func protectedMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
if config.LocalAuthMode == "noPassword" {
|
||||
c.Next()
|
||||
return
|
||||
@@ -221,8 +215,6 @@ func RunWebServer() {
|
||||
}
|
||||
|
||||
func handleDevice(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
response := LocalDevice{
|
||||
AuthMode: &config.LocalAuthMode,
|
||||
DeviceID: GetDeviceID(),
|
||||
@@ -232,8 +224,6 @@ func handleDevice(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleCreatePassword(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
if config.HashedPassword != "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Password already set"})
|
||||
return
|
||||
@@ -274,8 +264,6 @@ func handleCreatePassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleUpdatePassword(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
if config.HashedPassword == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Password is not set"})
|
||||
return
|
||||
@@ -319,8 +307,6 @@ func handleUpdatePassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleDeletePassword(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
if config.HashedPassword == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Password is not set"})
|
||||
return
|
||||
@@ -357,8 +343,6 @@ func handleDeletePassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleDeviceStatus(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
response := DeviceStatus{
|
||||
IsSetup: config.LocalAuthMode != "",
|
||||
}
|
||||
@@ -367,8 +351,6 @@ func handleDeviceStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleDeviceUIConfig(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
config, _ := json.Marshal(gin.H{
|
||||
"CLOUD_API": config.CloudURL,
|
||||
"DEVICE_VERSION": builtAppVersion,
|
||||
@@ -384,8 +366,6 @@ func handleDeviceUIConfig(c *gin.Context) {
|
||||
}
|
||||
|
||||
func handleSetup(c *gin.Context) {
|
||||
LoadConfig()
|
||||
|
||||
// Check if the device is already set up
|
||||
if config.LocalAuthMode != "" || config.HashedPassword != "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Device is already set up"})
|
||||
|
||||
Reference in New Issue
Block a user