refactor: remove update mail api
This commit is contained in:
@@ -70,17 +70,6 @@ func (u *UserApi) ForgotPass(context *gin.Context) {
|
||||
response.Result(errCode, nil, context)
|
||||
}
|
||||
|
||||
// 修改邮箱
|
||||
func (u *UserApi) UpdateMail(context *gin.Context) {
|
||||
var param models.UserMailParam
|
||||
if err := context.ShouldBind(¶m); err != nil {
|
||||
response.Result(response.ErrCodeParamInvalid, nil, context)
|
||||
return
|
||||
}
|
||||
errCode := u.userService.UpdateMail(¶m)
|
||||
response.Result(errCode, nil, context)
|
||||
}
|
||||
|
||||
// 注销账号
|
||||
func (u *UserApi) Delete(context *gin.Context) {
|
||||
var param models.UserDeleteParam
|
||||
|
||||
@@ -21,7 +21,6 @@ func Router() {
|
||||
// 用户模块,订阅模块
|
||||
route.GET("/user/verifycode", api.NewUserApi().GetVerifyCode)
|
||||
route.GET("/user/info", api.NewUserApi().GetInfo)
|
||||
route.PUT("/user/mail", api.NewUserApi().UpdateMail)
|
||||
route.POST("/user/login", api.NewUserApi().Login)
|
||||
route.POST("/user/register", api.NewUserApi().Register)
|
||||
route.POST("/user/pass", api.NewUserApi().ForgotPass)
|
||||
|
||||
@@ -37,18 +37,13 @@ type UserPassParam struct {
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
type UserMailParam struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Code string `json:"code" binding:"required,len=6"`
|
||||
NewEmail string `json:"newEmail" binding:"required,email"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Uid int64 `json:"uid"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type UserPersonInfo struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Version int `json:"version"`
|
||||
}
|
||||
|
||||
+12
-20
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -159,25 +160,6 @@ func (u *UserService) ForgotPass(param *models.UserPassParam) int {
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 修改邮箱
|
||||
func (u *UserService) UpdateMail(param *models.UserMailParam) int {
|
||||
// 校验验证码是否正确
|
||||
key := fmt.Sprintf("user:%s:code", param.Email)
|
||||
code := global.Rdb.Get(ctx, key).Val()
|
||||
if code != param.Code {
|
||||
return response.ErrCodeVerityCodeInvalid
|
||||
}
|
||||
user := models.User{
|
||||
Email: param.NewEmail,
|
||||
Updated: time.Now().Unix(),
|
||||
}
|
||||
err := global.Db.Table(USER).Where("email = ?", param.Email).Updates(&user).Error
|
||||
if err != nil {
|
||||
return response.ErrCodeFailed
|
||||
}
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 注销账号
|
||||
func (u *UserService) Delete(param models.UserDeleteParam) int {
|
||||
// 校验验证码是否正确
|
||||
@@ -196,7 +178,17 @@ func (u *UserService) Delete(param models.UserDeleteParam) int {
|
||||
// 获取用户信息
|
||||
func (u *UserService) GetInfo(uid int64) (*models.UserPersonInfo, int) {
|
||||
var user models.UserPersonInfo
|
||||
err := global.Db.Table(USER).Where("id = ?", uid).First(&user).Error
|
||||
err := global.Db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := global.Db.Table(USER).Where("id = ?", uid).First(&user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var subscribe models.Subscribe
|
||||
if err := global.Db.Table(SUBSCRIBE).Select("version").Where("uid = ?", uid).First(&subscribe).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
user.Version = subscribe.Version
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, response.ErrCodeFailed
|
||||
}
|
||||
|
||||
+1
-19
@@ -36,15 +36,6 @@ export function userForgotPass(param) {
|
||||
})
|
||||
}
|
||||
|
||||
// 修改邮箱
|
||||
export function updateMail(param) {
|
||||
return request({
|
||||
url: '/user/mail',
|
||||
method: 'put',
|
||||
data: param,
|
||||
})
|
||||
}
|
||||
|
||||
// 注销账号
|
||||
export function userDelete(param) {
|
||||
return request({
|
||||
@@ -61,13 +52,4 @@ export function getUserInfo(param) {
|
||||
method: 'get',
|
||||
params: param,
|
||||
})
|
||||
}
|
||||
|
||||
// 订阅个人版
|
||||
export function userBuy(param) {
|
||||
return request({
|
||||
url: '/user/buy',
|
||||
method: 'put',
|
||||
data: param,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user