wp-go/actions/login.go
2022-09-19 22:25:25 +08:00

29 lines
519 B
Go

package actions
import (
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
func Login(c *gin.Context) {
password := c.PostForm("post_password")
ref := c.Request.Referer()
if ref == "" {
ref = "/"
}
if password == "" || strings.Replace(password, " ", "", -1) == "" {
c.Redirect(http.StatusFound, ref)
return
}
s := sessions.Default(c)
s.Set("post_password", password)
err := s.Save()
if err != nil {
c.Error(err)
return
}
c.Redirect(http.StatusFound, ref)
}