mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
33 lines
982 B
Go
33 lines
982 B
Go
package router
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"NanoKVM-Server/authn"
|
|
"NanoKVM-Server/middleware"
|
|
"NanoKVM-Server/service/auth"
|
|
)
|
|
|
|
func authRouter(r *gin.Engine) {
|
|
service := auth.NewService()
|
|
|
|
r.POST("/api/auth/login", service.Login) // login
|
|
|
|
api := r.Group("/api").Use(middleware.CheckToken())
|
|
|
|
api.GET("/auth/password", service.IsPasswordUpdated) // is password updated
|
|
api.GET("/auth/account", service.GetAccount) // get account
|
|
api.POST("/auth/password", service.ChangePassword) // change password
|
|
api.POST("/auth/logout", service.Logout) // logout
|
|
|
|
admin := r.Group("/api").Use(
|
|
middleware.CheckToken(),
|
|
middleware.RequireRole(authn.RoleAdmin),
|
|
)
|
|
admin.GET("/auth/users", service.ListUsers)
|
|
admin.POST("/auth/users", service.CreateUser)
|
|
admin.PUT("/auth/users/:username", service.UpdateUser)
|
|
admin.DELETE("/auth/users/:username", service.DeleteUser)
|
|
admin.POST("/auth/users/:username/password", service.ChangeUserPassword)
|
|
}
|