mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-12 01:12:27 +08:00
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
// Package page provides ...
|
|
package page
|
|
|
|
import (
|
|
"bytes"
|
|
htemplate "html/template"
|
|
"net/http"
|
|
|
|
"github.com/eiblog/eiblog/pkg/cache"
|
|
"github.com/eiblog/eiblog/pkg/config"
|
|
"github.com/eiblog/eiblog/pkg/core/blog"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// baseBEParams 基础参数
|
|
func baseBEParams(c *gin.Context) gin.H {
|
|
return gin.H{
|
|
"Author": cache.Ei.Account.Username,
|
|
"Qiniu": config.Conf.BlogApp.Qiniu.Domain,
|
|
}
|
|
}
|
|
|
|
// handleLoginPage 登录页面
|
|
func handleLoginPage(c *gin.Context) {
|
|
logout := c.Query("logout")
|
|
if logout == "true" {
|
|
blog.SetLogout(c)
|
|
} else if blog.IsLogined(c) {
|
|
c.Redirect(http.StatusFound, "/admin/profile")
|
|
return
|
|
}
|
|
params := gin.H{"BTitle": cache.Ei.Blogger.BTitle}
|
|
renderHTMLAdminLayout(c, "login.html", params)
|
|
}
|
|
|
|
// renderHTMLAdminLayout 渲染admin页面
|
|
func renderHTMLAdminLayout(c *gin.Context, name string, data gin.H) {
|
|
c.Header("Content-Type", "text/html; charset=utf-8")
|
|
// special page
|
|
if name == "login.html" {
|
|
err := htmlTmpl.ExecuteTemplate(c.Writer, name, data)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return
|
|
}
|
|
buf := bytes.Buffer{}
|
|
err := htmlTmpl.ExecuteTemplate(&buf, name, data)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
data["LayoutContent"] = htemplate.HTML(buf.String())
|
|
err = htmlTmpl.ExecuteTemplate(c.Writer, "adminLayout.html", data)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if c.Writer.Status() == 0 {
|
|
c.Status(http.StatusOK)
|
|
}
|
|
}
|