mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
feat: support downloading image from online URL feat: add keyboard shortcut Ctrl+Alt+Del fix: fix the CSRF issue perf: add an option to configure custom ICE servers perf: removed unnecessary modifications to DNS configuration perf: add an SSH enable/disable toggle in the web UI perf: add a Tailscale enable/disable toggle in the web UI perf: download Tailscale installation package from the official source perf: automatic enable/disable GOMEMLIMIT on tailscale start/stop perf: add JWT configuration perf: implement secure password storage using bcrypt hashing perf: implement integrity checks for online updates refactor: refactor HDMI module and remove the dependency libmaixcam_lib.so refactor: web terminal use pty instead of SSH refactor: move Tailscale APIs from the network module to the extensions module
73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package auth
|
|
|
|
import (
|
|
"NanoKVM-Server/config"
|
|
"NanoKVM-Server/middleware"
|
|
"NanoKVM-Server/proto"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (s *Service) Login(c *gin.Context) {
|
|
var req proto.LoginReq
|
|
var rsp proto.Response
|
|
|
|
// authentication disabled
|
|
conf := config.GetInstance()
|
|
if conf.Authentication == "disable" {
|
|
rsp.OkRspWithData(c, &proto.LoginRsp{
|
|
Token: "disabled",
|
|
})
|
|
return
|
|
}
|
|
|
|
if err := proto.ParseFormRequest(c, &req); err != nil {
|
|
rsp.ErrRsp(c, -1, "invalid parameters")
|
|
return
|
|
}
|
|
|
|
if ok := CompareAccount(req.Username, req.Password); !ok {
|
|
rsp.ErrRsp(c, -2, "invalid username or password")
|
|
return
|
|
}
|
|
|
|
token, err := middleware.GenerateJWT(req.Username)
|
|
if err != nil {
|
|
rsp.ErrRsp(c, -3, "generate token failed")
|
|
return
|
|
}
|
|
|
|
rsp.OkRspWithData(c, &proto.LoginRsp{
|
|
Token: token,
|
|
})
|
|
|
|
log.Debugf("login success, username: %s", req.Username)
|
|
}
|
|
|
|
func (s *Service) Logout(c *gin.Context) {
|
|
conf := config.GetInstance()
|
|
|
|
if conf.JWT.RevokeTokensOnLogout {
|
|
config.RegenerateSecretKey()
|
|
}
|
|
|
|
var rsp proto.Response
|
|
rsp.OkRsp(c)
|
|
}
|
|
|
|
func (s *Service) GetAccount(c *gin.Context) {
|
|
var rsp proto.Response
|
|
|
|
account, err := GetAccount()
|
|
if err != nil {
|
|
rsp.ErrRsp(c, -1, "get account failed")
|
|
return
|
|
}
|
|
|
|
rsp.OkRspWithData(c, &proto.GetAccountRsp{
|
|
Username: account.Username,
|
|
})
|
|
log.Debugf("get account successful")
|
|
}
|