Skip to content

Commit

Permalink
fix:将密码登录接口改成调用用户中心的登录接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Penryn committed Sep 29, 2024
1 parent dde03bf commit 60d4184
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/controllers/userController/auth.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions app/services/userCenterServices/reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions app/services/userServices/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 60d4184

Please sign in to comment.