...
|
...
|
@@ -2,6 +2,7 @@ package user |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"net/http"
|
|
|
"opp/internal/repository"
|
...
|
...
|
@@ -41,7 +42,6 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
|
user *models.User
|
|
|
result bool
|
|
|
)
|
|
|
//rsp =&protocol.ChangePhoneResponse{}
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
...
|
...
|
@@ -50,39 +50,83 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
//TODO:跟用户中心交换数据
|
|
|
if _, err = repository.User.GetUsersByMobile(request.Phone); err == nil {
|
|
|
//判断库里面是否已经有这个手机号的用户
|
|
|
//if _, err = repository.User.GetUsersByMobile(request.Phone); err == nil {
|
|
|
// err = protocol.NewErrWithMessage(2029)
|
|
|
// return
|
|
|
//}
|
|
|
if !result {
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
return
|
|
|
}
|
|
|
//判断远程库是否已经有这个手机号
|
|
|
if err = agg.UcenterIsUserExists(user.UserCenterId, request.Phone); err != nil {
|
|
|
err = protocol.NewErrWithMessage(2029)
|
|
|
return
|
|
|
}
|
|
|
if !result {
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
if err = utils.UpdateTableByMapWithOrmer(o, &models.User{Id: user.Id}, map[string]interface{}{"Phone": request.Phone}); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{Phone: request.Phone}); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Phone": request.Phone})
|
|
|
o.Commit()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//重置密码
|
|
|
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
|
|
|
var (
|
|
|
user *models.User
|
|
|
user *models.User
|
|
|
message *protocol.Message
|
|
|
getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{}
|
|
|
getUserResponse *protocol.UCenterGetUserResponse
|
|
|
result bool
|
|
|
)
|
|
|
//rsp =&protocol.ResetPasswordResponse{}
|
|
|
if len(request.NewPwd) < 6 {
|
|
|
err = protocol.NewErrWithMessage(2027)
|
|
|
return
|
|
|
}
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if result, err = auth.CheckSmsCode(user.Phone, "", protocol.SmsCode); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if !result {
|
|
|
err = protocol.NewErrWithMessage(1012)
|
|
|
return
|
|
|
}
|
|
|
//从用户中心获取用户信息
|
|
|
if _, err = agg.RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodGetUser, user.UserCenterId), http.MethodGet, getUserRequest, &message); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if message.Errno == 0 && message.Errmsg == "ok" {
|
|
|
if err = message.Unmarshal(&getUserResponse); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if getUserResponse.Id != user.UserCenterId {
|
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
log.Error(fmt.Sprintf("ucenter.id not equal input:%v want:%v", user.UserCenterId, getUserResponse.Id))
|
|
|
return
|
|
|
}
|
|
|
//TODO:未验证 校验码
|
|
|
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
return
|
|
|
}
|
|
|
if len(request.NewPwd) < 6 {
|
|
|
err = protocol.NewErrWithMessage(2027)
|
|
|
return
|
|
|
}
|
|
|
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd})
|
|
|
err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{PassWord: request.NewPwd})
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -92,7 +136,6 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
|
user *models.User
|
|
|
loginResponse *protocol.UserCenterLoginResponse
|
|
|
)
|
|
|
//rsp =&protocol.ChangePasswordResponse{}
|
|
|
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
|
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
return
|
...
|
...
|
@@ -101,18 +144,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
|
err = protocol.NewErrWithMessage(2027)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//old
|
|
|
if user, err = repository.User.GetUsersById(header.Uid); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
//if !strings.EqualFold(request.OldPwd, user.Passwd) {
|
|
|
// err = protocol.NewErrWithMessage(2028)
|
|
|
// return
|
|
|
//}
|
|
|
|
|
|
//new
|
|
|
var message protocol.Message
|
|
|
if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{
|
|
|
PassWord: request.OldPwd,
|
...
|
...
|
@@ -131,19 +166,18 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
|
err = protocol.NewErrWithMessage(1)
|
|
|
return
|
|
|
}
|
|
|
log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd))
|
|
|
//修改密码
|
|
|
if _, err = agg.RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodGetUser, loginResponse.Id), http.MethodPut, &protocol.UCenterPutUserRequest{
|
|
|
PassWord: request.NewPwd,
|
|
|
}, &message); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{PassWord: request.NewPwd})
|
|
|
} else {
|
|
|
if message.Errno == -1 {
|
|
|
err = protocol.NewErrWithMessage(2028)
|
|
|
}
|
|
|
log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId), message.Errno, message.Errmsg)
|
|
|
return
|
|
|
}
|
|
|
//err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//用户公司
|
|
|
func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanysRequest) (rsp *protocol.UserCompanysResponse, err error) {
|
|
|
var ()
|
|
|
rsp = &protocol.UserCompanysResponse{}
|
...
|
...
|
|