+16
-14
@@ -1,11 +1,9 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"honoka-chan/internal/model"
|
||||
"honoka-chan/internal/utils"
|
||||
"honoka-chan/internal/session"
|
||||
"honoka-chan/pkg/db"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -13,6 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func AuthKey(ctx *gin.Context) {
|
||||
ss := session.New(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
authResp := model.AuthKeyResp{
|
||||
ResponseData: model.AuthKeyRes{
|
||||
AuthorizeToken: ctx.GetString("authorize_token"),
|
||||
@@ -21,18 +22,20 @@ func AuthKey(ctx *gin.Context) {
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
}
|
||||
resp, err := json.Marshal(authResp)
|
||||
utils.CheckErr(err)
|
||||
|
||||
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
|
||||
ctx.JSON(http.StatusOK, authResp)
|
||||
ss.Respond(authResp)
|
||||
}
|
||||
|
||||
func Login(ctx *gin.Context) {
|
||||
ss := session.New(ctx)
|
||||
defer ss.Finalize()
|
||||
|
||||
loginKey := ctx.GetString("login_key")
|
||||
var userId int
|
||||
exists, err := UserEng.Table("user_key").Where("key = ?", loginKey).Cols("userid").Get(&userId)
|
||||
utils.CheckErr(err)
|
||||
exists, err := ss.UserEng.Table("user_key").Where("key = ?", loginKey).Cols("userid").Get(&userId)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
if !exists || userId == 0 {
|
||||
userId = 9999999
|
||||
@@ -40,7 +43,9 @@ func Login(ctx *gin.Context) {
|
||||
ctx.Set("userid", userId)
|
||||
|
||||
err = db.DB.Set([]byte(strconv.Itoa(userId)), []byte(ctx.GetString("authorize_token")))
|
||||
utils.CheckErr(err)
|
||||
if ss.CheckErr(err) {
|
||||
return
|
||||
}
|
||||
|
||||
loginResp := model.LoginResp{
|
||||
ResponseData: model.LoginRes{
|
||||
@@ -52,9 +57,6 @@ func Login(ctx *gin.Context) {
|
||||
ReleaseInfo: []any{},
|
||||
StatusCode: 200,
|
||||
}
|
||||
resp, err := json.Marshal(loginResp)
|
||||
utils.CheckErr(err)
|
||||
|
||||
ctx.Header("X-Message-Sign", utils.GenXMS(resp))
|
||||
ctx.JSON(http.StatusOK, loginResp)
|
||||
ss.Respond(loginResp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user