From 60d418430ef849d36ed9dc949ecbf98d9ebaad91 Mon Sep 17 00:00:00 2001 From: Penryn <1515805213@163.com> Date: Mon, 30 Sep 2024 00:15:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=B0=86=E5=AF=86=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=8E=A5=E5=8F=A3=E6=94=B9=E6=88=90=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=AD=E5=BF=83=E7=9A=84=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/userController/auth.go | 8 ++------ app/services/userCenterServices/reg.go | 24 ++++++++++++++++++++++++ app/services/userServices/create.go | 4 ++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/controllers/userController/auth.go b/app/controllers/userController/auth.go index 87025cd..a689112 100644 --- a/app/controllers/userController/auth.go +++ b/app/controllers/userController/auth.go @@ -1,8 +1,6 @@ package userController import ( - "crypto/sha256" - "encoding/hex" "wejh-go/app/apiException" "wejh-go/app/services/sessionServices" "wejh-go/app/services/userServices" @@ -41,10 +39,8 @@ func AuthByPassword(c *gin.Context) { return } - h := sha256.New() - h.Write([]byte(postForm.Password)) - pass := hex.EncodeToString(h.Sum(nil)) - if user.JHPassword != pass { + err = userServices.CheckLogin(postForm.Username,postForm.Password) + if err != nil { _ = c.AbortWithError(200, apiException.NoThatPasswordOrWrong) return } diff --git a/app/services/userCenterServices/reg.go b/app/services/userCenterServices/reg.go index 3919373..5441a02 100644 --- a/app/services/userCenterServices/reg.go +++ b/app/services/userCenterServices/reg.go @@ -32,3 +32,27 @@ func RegWithoutVerify(stu_id string, pass string, iid string, email string) erro } return nil } + + +func Login(stu_id string, pass string) error { + params := url.Values{} + Url, err := url.Parse(string(userCenterApi.Auth)) + if err != nil { + return err + } + Url.RawQuery = params.Encode() + urlPath := Url.String() + regMap := make(map[string]string) + regMap["stu_id"] = stu_id + regMap["password"] = pass + resp, err := FetchHandleOfPost(regMap, userCenterApi.UserCenterApi(urlPath)) + if err != nil { + return err + } + if resp.Code == 404 { + return apiException.UserNotFind + } else if resp.Code == 405 { + return apiException.NoThatPasswordOrWrong + } + return nil +} \ No newline at end of file diff --git a/app/services/userServices/create.go b/app/services/userServices/create.go index 2147407..514699a 100755 --- a/app/services/userServices/create.go +++ b/app/services/userServices/create.go @@ -73,3 +73,7 @@ func CreateAdmin(userName, password string, adminType int) error { res := database.DB.Create(&admin) return res.Error } + +func CheckLogin(username, password string) error { + return userCenterServices.Login(username, password) +} \ No newline at end of file