Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
qianqianzyk committed Oct 15, 2024
2 parents ce5df91 + b6f13a2 commit 1760d44
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
10 changes: 3 additions & 7 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,11 +39,9 @@ func AuthByPassword(c *gin.Context) {
return
}

h := sha256.New()
h.Write([]byte(postForm.Password))
pass := hex.EncodeToString(h.Sum(nil))
if user.JHPassword != pass {
_ = c.AbortWithError(200, apiException.NoThatPasswordOrWrong)
err = userServices.CheckLogin(postForm.Username,postForm.Password)
if err != nil {
_ = c.AbortWithError(200, err)
return
}

Expand Down
33 changes: 33 additions & 0 deletions app/services/userCenterServices/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package userCenterServices

import (
"net/url"
"wejh-go/app/apiException"
"wejh-go/config/api/userCenterApi"
)

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 apiException.RequestError
}
if resp.Code == 404 {
return apiException.UserNotFind
} else if resp.Code == 405 {
return apiException.NoThatPasswordOrWrong
} else if resp.Code == 200 {
return nil
}else{
return apiException.ServerError
}
}
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 1760d44

Please sign in to comment.