|
@@ -3,7 +3,7 @@ package gateway
|
|
|
import (
|
|
|
"confrontation-training/common"
|
|
|
"confrontation-training/constant"
|
|
|
- errmsg "confrontation-training/err"
|
|
|
+ errors "confrontation-training/err"
|
|
|
"confrontation-training/models"
|
|
|
"confrontation-training/response"
|
|
|
"confrontation-training/service"
|
|
@@ -35,18 +35,18 @@ func (u *UserService) UseRegister(c *gin.Context) {
|
|
|
err := c.ShouldBindJSON(¶m)
|
|
|
if err != nil {
|
|
|
fmt.Printf("参数格式化异常:%s", err.Error())
|
|
|
- response.Failed(errmsg.ParamInvalid, c)
|
|
|
+ response.Failed(errors.ParamInvalid, c)
|
|
|
return
|
|
|
}
|
|
|
if _, count := u.FindUserByPhone(param.Phone); count > 0 {
|
|
|
- response.Failed(errmsg.UserAlreadyExists, c)
|
|
|
+ response.Failed(errors.UserAlreadyExists, c)
|
|
|
return
|
|
|
}
|
|
|
if result := u.CreateUser(param); result.Error == nil {
|
|
|
- response.Success(errmsg.UserRegisterSuccess, result.RowsAffected, c)
|
|
|
+ response.Success(errors.UserRegisterSuccess, result.RowsAffected, c)
|
|
|
return
|
|
|
} else {
|
|
|
- response.Failed(errmsg.UserRegisterFailed+"数据库错:"+result.Error.Error(), c)
|
|
|
+ response.Failed(errors.UserRegisterFailed+"数据库错:"+result.Error.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -69,7 +69,7 @@ func (u *UserService) UserLogin(c *gin.Context) {
|
|
|
|
|
|
if err != nil {
|
|
|
fmt.Printf("参数格式化异常:%s", err.Error())
|
|
|
- response.Failed(errmsg.ParamInvalid, c)
|
|
|
+ response.Failed(errors.ParamInvalid, c)
|
|
|
return
|
|
|
}
|
|
|
user := u.Login(param)
|
|
@@ -79,9 +79,9 @@ func (u *UserService) UserLogin(c *gin.Context) {
|
|
|
resultMap := map[string]string{
|
|
|
"token": toke,
|
|
|
}
|
|
|
- response.Success(errmsg.UserLoginSuccess, resultMap, c)
|
|
|
+ response.Success(errors.UserLoginSuccess, resultMap, c)
|
|
|
} else {
|
|
|
- response.Failed(errmsg.UserLoginFailed, c)
|
|
|
+ response.Failed(errors.UserLoginFailed, c)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -101,30 +101,30 @@ func (u *UserService) ResetPassword(c *gin.Context) {
|
|
|
err := c.ShouldBindJSON(¶m)
|
|
|
if err != nil {
|
|
|
fmt.Printf("参数格式化异常:%s", err.Error())
|
|
|
- response.Failed(errmsg.ParamInvalid, c)
|
|
|
+ response.Failed(errors.ParamInvalid, c)
|
|
|
return
|
|
|
}
|
|
|
if admin := u.FindUserByPhoneAndRole(param.Phone, constant.RoleAdmin); admin == nil {
|
|
|
- fmt.Printf("管理员"+errmsg.UserNotExists+"%s", param.Phone)
|
|
|
- response.Failed("管理员"+errmsg.UserNotExists+param.Phone, c)
|
|
|
+ fmt.Printf("管理员"+errors.UserNotExists+"%s", param.Phone)
|
|
|
+ response.Failed("管理员"+errors.UserNotExists+param.Phone, c)
|
|
|
return
|
|
|
}
|
|
|
if normalUser := u.FindUserByPhoneAndRole(param.PhoneInit, constant.RoleNormal); normalUser == nil {
|
|
|
- fmt.Printf(errmsg.UserNotExists+"%s", param.PhoneInit)
|
|
|
- response.Failed(errmsg.UserNotExists+param.PhoneInit, c)
|
|
|
+ fmt.Printf(errors.UserNotExists+"%s", param.PhoneInit)
|
|
|
+ response.Failed(errors.UserNotExists+param.PhoneInit, c)
|
|
|
return
|
|
|
}
|
|
|
result := u.RestPassword(param.PhoneInit)
|
|
|
if result == nil {
|
|
|
- response.Failed(errmsg.UserPasswordResetError, c)
|
|
|
+ response.Failed(errors.UserPasswordResetError, c)
|
|
|
return
|
|
|
}
|
|
|
if result.Error != nil {
|
|
|
- response.Failed(errmsg.UserPasswordResetError+result.Error.Error(), c)
|
|
|
+ response.Failed(errors.UserPasswordResetError+result.Error.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
if result.RowsAffected >= 0 {
|
|
|
- response.Success(errmsg.UserPasswordResetSuccess, result.RowsAffected, c)
|
|
|
+ response.Success(errors.UserPasswordResetSuccess, result.RowsAffected, c)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -144,12 +144,12 @@ func (u *UserService) UserList(c *gin.Context) {
|
|
|
var param models.UserListParam
|
|
|
err := c.ShouldBindJSON(¶m)
|
|
|
if err != nil {
|
|
|
- fmt.Printf(errmsg.ParamInvalid+"%s", err.Error())
|
|
|
- response.Failed(errmsg.ParamInvalid, c)
|
|
|
+ fmt.Printf(errors.ParamInvalid+"%s", err.Error())
|
|
|
+ response.Failed(errors.ParamInvalid, c)
|
|
|
return
|
|
|
}
|
|
|
userList, rows := u.GetUserList(param)
|
|
|
- response.SuccessPage(errmsg.FindSuccess, userList, rows, c)
|
|
|
+ response.SuccessPage(errors.FindSuccess, userList, rows, c)
|
|
|
}
|
|
|
|
|
|
// ModePass
|
|
@@ -167,22 +167,22 @@ func (u *UserService) ModePass(c *gin.Context) {
|
|
|
var param models.ChangePassword
|
|
|
err := c.ShouldBindJSON(¶m)
|
|
|
if err != nil {
|
|
|
- response.Failed(errmsg.ParamInvalid, c)
|
|
|
+ response.Failed(errors.ParamInvalid, c)
|
|
|
return
|
|
|
}
|
|
|
user, count := u.FindUserByPhone(param.Phone)
|
|
|
if count <= 0 {
|
|
|
- response.Failed(errmsg.UserNotExists, c)
|
|
|
+ response.Failed(errors.UserNotExists, c)
|
|
|
return
|
|
|
}
|
|
|
if user.Password != param.Password {
|
|
|
- response.Failed(errmsg.UserOldPasswordError, c)
|
|
|
+ response.Failed(errors.UserOldPasswordError, c)
|
|
|
return
|
|
|
}
|
|
|
count = u.ChangePassword(user.ID, param.NewPassword)
|
|
|
if count <= 0 {
|
|
|
- response.Failed(errmsg.UserPasswordChangeError, c)
|
|
|
+ response.Failed(errors.UserPasswordChangeError, c)
|
|
|
return
|
|
|
}
|
|
|
- response.Success(errmsg.UserPasswordChangeSuccess, count, c)
|
|
|
+ response.Success(errors.UserPasswordChangeSuccess, count, c)
|
|
|
}
|