Kick off old clients

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-04-11 19:11:33 +08:00
parent 64fa24d6ce
commit 569c84175e
5 changed files with 19 additions and 5 deletions
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -8,11 +8,11 @@ func MatchTokenUid(token, uid string) bool {
// fmt.Println(k, v)
// fmt.Println()
// }
res, err := LevelDb.Get([]byte(token))
res, err := LevelDb.Get([]byte(uid))
if err != nil {
fmt.Println(err)
return false
}
return string(res) == uid
return string(res) == token
}
+1 -1
View File
@@ -137,7 +137,7 @@ func LoginHandler(ctx *gin.Context) {
sUserId := strconv.Itoa(userId)
authorizeToken := utils.RandomBase64Token(32)
err = database.LevelDb.Put([]byte(authorizeToken), []byte(sUserId))
err = database.LevelDb.Put([]byte(sUserId), []byte(authorizeToken))
CheckErr(err)
loginResp := model.LoginResp{}
+1 -1
View File
@@ -46,7 +46,7 @@ func main() {
// Private APIs
// Server APIs
m := r.Group("main.php").Use(middleware.KlabHeader)
m := r.Group("main.php").Use(middleware.CommonMid)
{
m.POST("/login/authkey", handler.AuthKeyHandler)
m.POST("/login/login", handler.LoginHandler)
+15 -1
View File
@@ -2,11 +2,25 @@ package middleware
import (
"honoka-chan/config"
"honoka-chan/database"
"honoka-chan/handler"
"honoka-chan/utils"
"net/http"
"github.com/gin-gonic/gin"
)
func KlabHeader(ctx *gin.Context) {
func CommonMid(ctx *gin.Context) {
authorizeStr := ctx.Request.Header["Authorize"]
userId := ctx.Request.Header[http.CanonicalHeaderKey("User-ID")]
if len(userId) > 0 {
authStr, _ := utils.GetAuthorizeToken(authorizeStr)
res, _ := database.LevelDb.Get([]byte(userId[0]))
if authStr != string(res) {
ctx.String(http.StatusForbidden, handler.ErrorMsg)
return
}
}
ctx.Header("Content-Type", "application/json; charset=utf-8")
ctx.Header("X-Powered-By", config.Conf.Server.PoweredBy)
ctx.Header("server_version", config.Conf.Server.VersionDate)