Skip to content

Commit a64a608

Browse files
committed
refactor: 重构用户注册、登录和注销功能以适配修改后的用户中心接口
1 parent c823d5d commit a64a608

File tree

11 files changed

+29
-22
lines changed

11 files changed

+29
-22
lines changed

app/controllers/userController/reg.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type createStudentUserForm struct {
1717
StudentID string `json:"studentID" binding:"required"`
1818
IDCardNumber string `json:"idCardNumber" binding:"required"`
1919
Email string `json:"email" binding:"required"`
20-
LoginType string `json:"type"`
20+
Type uint `json:"type" ` // 用户类型 0-本科生 1-研究生
2121
}
2222
type createStudentUserWechatForm struct {
2323
Username string `json:"username" binding:"required"`
@@ -26,7 +26,7 @@ type createStudentUserWechatForm struct {
2626
IDCardNumber string `json:"idCardNumber" binding:"required"`
2727
Email string `json:"email" binding:"required"`
2828
Code string `json:"code" binding:"required"`
29-
LoginType string `json:"type"`
29+
Type uint `json:"type" ` // 用户类型 0-本科生 1-研究生
3030
}
3131

3232
func BindOrCreateStudentUserFromWechat(c *gin.Context) {
@@ -52,7 +52,8 @@ func BindOrCreateStudentUserFromWechat(c *gin.Context) {
5252
postForm.StudentID,
5353
postForm.IDCardNumber,
5454
postForm.Email,
55-
session.OpenID)
55+
session.OpenID,
56+
postForm.Type)
5657
if err != nil && err != apiException.ReactiveError {
5758
_ = c.AbortWithError(200, err)
5859
return
@@ -87,7 +88,8 @@ func CreateStudentUser(c *gin.Context) {
8788
postForm.Password,
8889
postForm.StudentID,
8990
postForm.IDCardNumber,
90-
postForm.Email)
91+
postForm.Email,
92+
postForm.Type)
9193
if err != nil && err != apiException.ReactiveError {
9294
_ = c.AbortWithError(200, err)
9395
return

app/services/userCenterServices/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ func Login(stu_id string, pass string) error {
1414
}
1515
Url.RawQuery = params.Encode()
1616
urlPath := Url.String()
17-
regMap := make(map[string]string)
17+
regMap := make(map[string]any)
1818
regMap["stu_id"] = stu_id
1919
regMap["password"] = pass
20+
regMap["bound_system"] = 0
2021
resp, err := FetchHandleOfPost(regMap, userCenterApi.UserCenterApi(urlPath))
2122
if err != nil {
2223
return apiException.RequestError

app/services/userCenterServices/del.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package userCenterServices
22

33
import (
4+
"fmt"
45
"net/url"
56
"wejh-go/app/apiException"
67
"wejh-go/config/api/userCenterApi"
@@ -15,10 +16,12 @@ func DelAccount(stuID, iid string) error {
1516
}
1617
Url.RawQuery = params.Encode()
1718
urlPath := Url.String()
18-
regMap := make(map[string]string)
19+
regMap := make(map[string]any)
1920
regMap["stuid"] = stuID
2021
regMap["iid"] = iid
22+
regMap["bound_system"] = 0
2123
resp, err := FetchHandleOfPost(regMap, userCenterApi.UserCenterApi(urlPath))
24+
fmt.Println(resp)
2225
if err != nil {
2326
return err
2427
}

app/services/userCenterServices/reg.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import (
66
"wejh-go/config/api/userCenterApi"
77
)
88

9-
func RegWithoutVerify(stu_id string, pass string, iid string, email string) error {
9+
func RegWithoutVerify(stu_id string, pass string, iid string, email string, userType uint) error {
1010
params := url.Values{}
1111
Url, err := url.Parse(string(userCenterApi.UCRegWithoutVerify))
1212
if err != nil {
1313
return err
1414
}
1515
Url.RawQuery = params.Encode()
1616
urlPath := Url.String()
17-
regMap := make(map[string]string)
17+
regMap := make(map[string]any)
1818
regMap["stu_id"] = stu_id
1919
regMap["password"] = pass
2020
regMap["iid"] = iid
2121
regMap["email"] = email
22+
regMap["type"] = userType
23+
regMap["bound_system"] = 0
2224
resp, err := FetchHandleOfPost(regMap, userCenterApi.UserCenterApi(urlPath))
2325
if err != nil {
2426
return err

app/services/userCenterServices/repass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func ResetPass(stuID, iid, password string) error {
1515
}
1616
Url.RawQuery = params.Encode()
1717
urlPath := Url.String()
18-
regMap := make(map[string]string)
18+
regMap := make(map[string]any)
1919
regMap["stuid"] = stuID
2020
regMap["iid"] = iid
2121
regMap["pwd"] = password

app/services/userCenterServices/userCenterService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type UserCenterResponse struct {
1313
Data interface{} `json:"data"`
1414
}
1515

16-
func FetchHandleOfPost(form map[string]string, url userCenterApi.UserCenterApi) (*UserCenterResponse, error) {
16+
func FetchHandleOfPost(form map[string]any, url userCenterApi.UserCenterApi) (*UserCenterResponse, error) {
1717
f := fetch.Fetch{}
1818
f.Init()
1919
res, err := f.PostJsonForm(userCenterApi.UserCenterHost+string(url), form)

app/services/userServices/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"wejh-go/config/database"
1111
)
1212

13-
func CreateStudentUser(username, password, studentID, IDCardNumber, email string) (*models.User, error) {
13+
func CreateStudentUser(username, password, studentID, IDCardNumber, email string, userType uint) (*models.User, error) {
1414
if CheckUsername(username) {
1515
return nil, apiException.UserAlreadyExisted
1616
}
17-
err := userCenterServices.RegWithoutVerify(studentID, password, IDCardNumber, email)
17+
err := userCenterServices.RegWithoutVerify(studentID, password, IDCardNumber, email, userType)
1818
if err != nil && err != apiException.ReactiveError {
1919
return nil, err
2020
}
@@ -26,7 +26,7 @@ func CreateStudentUser(username, password, studentID, IDCardNumber, email string
2626
user := &models.User{
2727
JHPassword: pass,
2828
Username: username,
29-
Type: models.Undergraduate,
29+
Type: models.UserType(userType),
3030
StudentID: studentID,
3131
LibPassword: "",
3232
PhoneNum: "",
@@ -41,11 +41,11 @@ func CreateStudentUser(username, password, studentID, IDCardNumber, email string
4141
return user, res.Error
4242
}
4343

44-
func CreateStudentUserWechat(username, password, studentID, IDCardNumber, email, wechatOpenID string) (*models.User, error) {
44+
func CreateStudentUserWechat(username, password, studentID, IDCardNumber, email, wechatOpenID string, userType uint) (*models.User, error) {
4545
if CheckWechatOpenID(wechatOpenID) {
4646
return nil, apiException.OpenIDError
4747
}
48-
user, err := CreateStudentUser(username, password, studentID, IDCardNumber, email)
48+
user, err := CreateStudentUser(username, password, studentID, IDCardNumber, email, userType)
4949
if err != nil && err != apiException.ReactiveError {
5050
return nil, err
5151
}

app/services/userServices/del.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
)
88

99
func DelAccount(user *models.User, iid string) error {
10-
1110
if err := userCenterServices.DelAccount(user.Username, iid); err != nil {
1211
return err
1312
}

app/services/yxyServices/bindService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func GetCaptchaImage(deviceId, securityToken string) (*string, error) {
6767
}
6868

6969
func SendVerificationCode(securityToken, deviceId, phoneNum string) error {
70-
form := make(map[string]string)
70+
form := make(map[string]any)
7171
form["phone_num"] = phoneNum
7272
form["security_token"] = securityToken
7373
form["captcha"] = ""
@@ -95,7 +95,7 @@ func SendVerificationCode(securityToken, deviceId, phoneNum string) error {
9595
}
9696

9797
func LoginByCode(code, deviceId, phoneNum string) (*string, error) {
98-
form := make(map[string]string)
98+
form := make(map[string]any)
9999
form["phone_num"] = phoneNum
100100
form["code"] = code
101101
form["device_id"] = deviceId
@@ -121,7 +121,7 @@ func LoginByCode(code, deviceId, phoneNum string) (*string, error) {
121121
}
122122

123123
func SilentLogin(deviceId, uid, phoneNum string) error {
124-
form := make(map[string]string)
124+
form := make(map[string]any)
125125
form["uid"] = uid
126126
form["device_id"] = deviceId
127127
form["phone_num"] = phoneNum

app/services/yxyServices/yxyService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type YxyResponse struct {
1414
Data interface{} `json:"data"`
1515
}
1616

17-
func FetchHandleOfPost(form map[string]string, url yxyApi.YxyApi) (*YxyResponse, error) {
17+
func FetchHandleOfPost(form map[string]any, url yxyApi.YxyApi) (*YxyResponse, error) {
1818
f := fetch.Fetch{}
1919
f.Init()
2020
res, err := f.PostJsonForm(yxyApi.YxyHost+string(url), form)

0 commit comments

Comments
 (0)