2022-09-18 04:34:48 +00:00
|
|
|
package actions
|
2022-09-18 03:57:43 +00:00
|
|
|
|
|
|
|
import (
|
2022-10-31 11:47:29 +00:00
|
|
|
"fmt"
|
2022-09-18 03:57:43 +00:00
|
|
|
"github.com/gin-contrib/sessions"
|
|
|
|
"github.com/gin-gonic/gin"
|
2022-11-17 08:29:39 +00:00
|
|
|
"github/fthvgb1/wp-go/config/wpconfig"
|
2022-10-31 11:47:29 +00:00
|
|
|
"github/fthvgb1/wp-go/helper"
|
|
|
|
"github/fthvgb1/wp-go/phpass"
|
2022-09-19 14:25:25 +00:00
|
|
|
"net/http"
|
2022-09-18 03:57:43 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-09-18 04:34:48 +00:00
|
|
|
func Login(c *gin.Context) {
|
2022-09-18 03:57:43 +00:00
|
|
|
password := c.PostForm("post_password")
|
|
|
|
ref := c.Request.Referer()
|
|
|
|
if ref == "" {
|
|
|
|
ref = "/"
|
|
|
|
}
|
|
|
|
if password == "" || strings.Replace(password, " ", "", -1) == "" {
|
2022-09-19 14:25:25 +00:00
|
|
|
c.Redirect(http.StatusFound, ref)
|
2022-09-18 03:57:43 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
s := sessions.Default(c)
|
|
|
|
s.Set("post_password", password)
|
|
|
|
err := s.Save()
|
|
|
|
if err != nil {
|
|
|
|
c.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-31 11:47:29 +00:00
|
|
|
pass, err := phpass.NewPasswordHash(8, true).HashPassword(password)
|
|
|
|
if err != nil {
|
|
|
|
c.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-17 08:29:39 +00:00
|
|
|
cohash := fmt.Sprintf("wp-postpass_%s", helper.StringMd5(wpconfig.Options.Value("siteurl")))
|
2022-10-31 11:47:29 +00:00
|
|
|
c.SetCookie(cohash, pass, 24*3600, "/", "", false, false)
|
|
|
|
|
2022-09-19 14:25:25 +00:00
|
|
|
c.Redirect(http.StatusFound, ref)
|
2022-09-18 03:57:43 +00:00
|
|
|
}
|