mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-23 00:10:45 +00:00
- Moved API route registration to dedicated init files for better organization. - Introduced event listeners for server initialization to dynamically register routes. - Removed redundant configuration loading in routers.go. - Added new API routes for various functionalities including client management, admin tasks, and notifications. - Implemented a standardized response structure for API responses. - Established WebSocket connections for terminal sessions and improved session management. - Created a new database initialization for default admin account creation. - Enhanced gRPC server setup for Nezha compatibility with dynamic configuration updates.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package update
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/komari-monitor/komari/internal/api_v1/resp"
|
|
"github.com/komari-monitor/komari/internal/database/accounts"
|
|
"github.com/komari-monitor/komari/internal/database/auditlog"
|
|
)
|
|
|
|
func UpdateUser(c *gin.Context) {
|
|
var req struct {
|
|
Uuid string `json:"uuid" binding:"required"`
|
|
Name *string `json:"username"`
|
|
Password *string `json:"password"`
|
|
SsoType *string `json:"sso_type"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
resp.RespondError(c, 400, "Invalid or missing request body: "+err.Error())
|
|
return
|
|
}
|
|
if req.Password == nil && req.Name == nil {
|
|
resp.RespondError(c, 400, "At least one field (username or password) must be provided")
|
|
return
|
|
}
|
|
if req.Name != nil && len(*req.Name) < 3 {
|
|
resp.RespondError(c, 400, "Username must be at least 3 characters long")
|
|
return
|
|
}
|
|
if req.Password != nil && len(*req.Password) < 6 {
|
|
resp.RespondError(c, 400, "Password must be at least 6 characters long")
|
|
return
|
|
}
|
|
if err := accounts.UpdateUser(req.Uuid, req.Name, req.Password, req.SsoType); err != nil {
|
|
resp.RespondError(c, 500, "Failed to update user: "+err.Error())
|
|
return
|
|
}
|
|
uuid, _ := c.Get("uuid")
|
|
auditlog.Log(c.ClientIP(), uuid.(string), "User updated", "warn")
|
|
resp.RespondSuccess(c, gin.H{"uuid": req.Uuid})
|
|
}
|