mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-08 07:42:27 +08:00
update
This commit is contained in:
16
api.go
16
api.go
@@ -152,20 +152,18 @@ func apiPostAdd(c *gin.Context) {
|
||||
var cid int
|
||||
defer func() {
|
||||
if !publish {
|
||||
// TODO 返回cid, success改为0
|
||||
// {"success":1,"time":"10:40:46 AM","cid":"4"}
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
} else {
|
||||
if err == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
}
|
||||
logd.Error(err)
|
||||
}
|
||||
if err == nil {
|
||||
c.Redirect(http.StatusFound, "/admin/manage-posts")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/admin/posts")
|
||||
}
|
||||
logd.Error(err)
|
||||
}()
|
||||
do := c.PostForm("do") // save or publish
|
||||
slug := c.PostForm("slug")
|
||||
|
||||
22
back.go
22
back.go
@@ -14,17 +14,18 @@ import (
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
func isLogin(c *gin.Context) bool {
|
||||
session := sessions.Default(c)
|
||||
v := session.Get("username")
|
||||
if v == nil || v.(string) != Ei.Username {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func AuthFilter() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// TODO 过滤登录
|
||||
session := sessions.Default(c)
|
||||
v := session.Get("username")
|
||||
if v == nil {
|
||||
c.Abort()
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
if v.(string) != Ei.Username {
|
||||
if !isLogin(c) {
|
||||
c.Abort()
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
@@ -40,6 +41,9 @@ func HandleLogin(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
session.Delete("username")
|
||||
session.Save()
|
||||
} else if isLogin(c) {
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, "login.html", gin.H{
|
||||
"BTitle": Ei.BTitle,
|
||||
|
||||
2
check.go
2
check.go
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func CheckEmail(e string) bool {
|
||||
reg := regexp.MustCompile(`^(\w)+([\.\-]\w+)*#(\w)+((\.\w+)+)$`)
|
||||
reg := regexp.MustCompile(`^(\w)+([\.\-]\w+)*@(\w)+((\.\w+)+)$`)
|
||||
return reg.MatchString(e)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ account:
|
||||
username: deepzz
|
||||
# *登录明文密码
|
||||
password: deepzz
|
||||
# 邮箱,用于通知: chenqijing2#163.com
|
||||
email: chenqijing2#163.com
|
||||
# 邮箱,用于通知: chenqijing2@163.com
|
||||
email: chenqijing2@163.com
|
||||
# 手机号, "+8615100000000"
|
||||
phonenumber: "+8615100000000"
|
||||
# 家庭住址
|
||||
|
||||
1
db.go
1
db.go
@@ -159,7 +159,6 @@ func loadArticles() (artcs SortArticles) {
|
||||
// generate series,archive markdown
|
||||
func generateMarkdown() {
|
||||
for {
|
||||
|
||||
switch typ := <-Ei.CH; typ {
|
||||
case SERIES_MD:
|
||||
sort.Sort(Ei.Series)
|
||||
|
||||
13
front.go
13
front.go
@@ -29,7 +29,7 @@ func Filter() gin.HandlerFunc {
|
||||
func UserCookie(c *gin.Context) {
|
||||
cookie, err := c.Request.Cookie("u")
|
||||
if err != nil || cookie.Value == "" {
|
||||
|
||||
// TODO cookie操作
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,14 +144,6 @@ func HandleArticlePage(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "homeLayout.html", h)
|
||||
}
|
||||
|
||||
type temp struct {
|
||||
Title string
|
||||
Slug string
|
||||
URL string
|
||||
Img string
|
||||
CreateTime time.Time
|
||||
}
|
||||
|
||||
func HandleSearchPage(c *gin.Context) {
|
||||
h := GetBase()
|
||||
h["Version"] = StaticVersion(c)
|
||||
@@ -167,7 +159,6 @@ func HandleSearchPage(c *gin.Context) {
|
||||
}
|
||||
if q != "" {
|
||||
h["Word"] = q
|
||||
// TODO search
|
||||
var result *ESSearchResult
|
||||
vals := c.Request.URL.Query()
|
||||
reg := regexp.MustCompile(`^[a-z]+:\w+$`)
|
||||
@@ -198,6 +189,7 @@ func HandleSearchPage(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "homeLayout.html", h)
|
||||
}
|
||||
|
||||
// 服务端推送谷歌统计
|
||||
func HandleBeacon(c *gin.Context) {}
|
||||
|
||||
func HandleFeed(c *gin.Context) {
|
||||
@@ -216,6 +208,7 @@ func HandleSitemap(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, "static/sitemap.xml")
|
||||
}
|
||||
|
||||
// 服务端获取评论
|
||||
func HandleComments(c *gin.Context) {
|
||||
// TODO comments
|
||||
var ss = map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user