Skip to content

Commit 24410ed

Browse files
Penrynqianqianzyk
Penryn
authored andcommitted
fix:将密码登录接口改成调用用户中心的登录接口
1 parent 9f53d1e commit 24410ed

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

app/controllers/userController/auth.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package userController
22

33
import (
4-
"crypto/sha256"
5-
"encoding/hex"
64
"wejh-go/app/apiException"
75
"wejh-go/app/services/sessionServices"
86
"wejh-go/app/services/userServices"
@@ -41,11 +39,9 @@ func AuthByPassword(c *gin.Context) {
4139
return
4240
}
4341

44-
h := sha256.New()
45-
h.Write([]byte(postForm.Password))
46-
pass := hex.EncodeToString(h.Sum(nil))
47-
if user.JHPassword != pass {
48-
_ = c.AbortWithError(200, apiException.NoThatPasswordOrWrong)
42+
err = userServices.CheckLogin(postForm.Username,postForm.Password)
43+
if err != nil {
44+
_ = c.AbortWithError(200, err)
4945
return
5046
}
5147

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package userCenterServices
2+
3+
import (
4+
"net/url"
5+
"wejh-go/app/apiException"
6+
"wejh-go/config/api/userCenterApi"
7+
)
8+
9+
func Login(stu_id string, pass string) error {
10+
params := url.Values{}
11+
Url, err := url.Parse(string(userCenterApi.Auth))
12+
if err != nil {
13+
return err
14+
}
15+
Url.RawQuery = params.Encode()
16+
urlPath := Url.String()
17+
regMap := make(map[string]string)
18+
regMap["stu_id"] = stu_id
19+
regMap["password"] = pass
20+
resp, err := FetchHandleOfPost(regMap, userCenterApi.UserCenterApi(urlPath))
21+
if err != nil {
22+
return apiException.RequestError
23+
}
24+
if resp.Code == 404 {
25+
return apiException.UserNotFind
26+
} else if resp.Code == 405 {
27+
return apiException.NoThatPasswordOrWrong
28+
} else if resp.Code == 200 {
29+
return nil
30+
}else{
31+
return apiException.ServerError
32+
}
33+
}

app/services/userServices/create.go

+4
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ func CreateAdmin(userName, password string, adminType int) error {
7373
res := database.DB.Create(&admin)
7474
return res.Error
7575
}
76+
77+
func CheckLogin(username, password string) error {
78+
return userCenterServices.Login(username, password)
79+
}

0 commit comments

Comments
 (0)