feat: add compatible Trojan manager image
This commit is contained in:
@@ -123,6 +123,12 @@ func RequestUsername(c *gin.Context) string {
|
||||
return claims[identityKey].(string)
|
||||
}
|
||||
|
||||
func RequireAdmin(c *gin.Context) bool {
|
||||
if RequestUsername(c) == "admin" { return true }
|
||||
c.JSON(403, gin.H{"code": 403, "message": "administrator access required"})
|
||||
return false
|
||||
}
|
||||
|
||||
// Auth 权限router
|
||||
func Auth(r *gin.Engine, timeout int) *jwt.GinJWTMiddleware {
|
||||
jwtInit(timeout)
|
||||
@@ -152,7 +158,10 @@ func Auth(r *gin.Engine, timeout int) *jwt.GinJWTMiddleware {
|
||||
}
|
||||
})
|
||||
r.POST("/auth/login", authMiddleware.LoginHandler)
|
||||
r.POST("/auth/register", updateUser)
|
||||
r.POST("/auth/register", func(c *gin.Context) {
|
||||
if result, _ := core.GetValue("admin_pass"); result != "" { c.JSON(403, gin.H{"code":403,"message":"administrator already initialized"}); return }
|
||||
updateUser(c)
|
||||
})
|
||||
authO := r.Group("/auth")
|
||||
authO.Use(authMiddleware.MiddlewareFunc())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user