2019-12-08 03:59:58 -05:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
"github.com/p14yground/nezha/model"
|
|
|
|
"github.com/p14yground/nezha/pkg/mygin"
|
|
|
|
"github.com/p14yground/nezha/service/dao"
|
|
|
|
)
|
|
|
|
|
|
|
|
type commonPage struct {
|
|
|
|
r *gin.Engine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cp *commonPage) serve() {
|
|
|
|
cr := cp.r.Group("")
|
|
|
|
cr.Use(mygin.Authorize(mygin.AuthorizeOption{}))
|
|
|
|
cr.GET("/", cp.home)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cp *commonPage) home(c *gin.Context) {
|
|
|
|
var admin *model.User
|
|
|
|
isLogin, ok := c.Get(model.CtxKeyIsUserLogin)
|
|
|
|
if ok && isLogin.(bool) {
|
|
|
|
admin = dao.Admin
|
|
|
|
}
|
2019-12-09 05:14:31 -05:00
|
|
|
dao.ServerLock.RLock()
|
|
|
|
defer dao.ServerLock.RUnlock()
|
2019-12-08 03:59:58 -05:00
|
|
|
c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{
|
2019-12-08 10:18:29 -05:00
|
|
|
"Admin": admin,
|
2019-12-09 05:14:31 -05:00
|
|
|
"Servers": dao.ServerList,
|
2019-12-08 03:59:58 -05:00
|
|
|
}))
|
|
|
|
}
|