作者 yangfu

用户中心修改

... ... @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/astaxie/beego/plugins/cors"
"strconv"
"strings"
... ... @@ -224,3 +225,36 @@ func CheckUuid(ctx *context.Context) (result bool) {
}
return
}
//AllowOption 允许跨域请求
var AllowOption = func(ctx *context.Context) {
if ctx.Request.Method != "OPTIONS" {
return
}
f := cors.Allow(&cors.Options{
AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization",
"x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息
ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
AllowCredentials: false, //不允许共享AuthTuffic证书
AllowAllOrigins: true, //允许的请求来源
})
f(ctx)
ctx.Output.Body([]byte("{}"))
ctx.Output.SetStatus(204)
return
}
//LogRequestData Before Router
var LogRequestData = func(ctx *context.Context) {
log.Info("====>Recv Request:%s", ctx.Input.URI())
hmap := map[string]string{
//protocol.HeaderAccessToken: ctx.Input.Header(protocol.HeaderAccessToken),
//protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken),
}
if ctx.Input.RequestBody != nil {
log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody))
} else {
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
}
}
... ...
... ... @@ -251,3 +251,24 @@ func (this *ChanceController) ChanceStatistics() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceStatistics(header, request))
}
//MyChance 我的机会
//@router /myChance [post]
func (this *ChanceController) MyChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyChanceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyChance(header, request))
}
... ...
... ... @@ -149,7 +149,7 @@ type AuditConfig struct {
NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】
}
/*ChanceStatistics */
/*ChanceStatistics 首页-机会池统计*/
type ChanceStatisticsRequest struct {
}
type ChanceStatisticsResponse struct {
... ... @@ -162,3 +162,10 @@ type ChanceTotalItem struct {
Name string `json:"name"` //总数
Total int `json:"total"`
}
/*MyChance 我的机会*/
type MyChanceRequest struct {
Xxx string `json:"xxx" valid:"Required"`
}
type MyChanceResponse struct {
}
... ...
... ... @@ -33,6 +33,6 @@ const (
MyCommitChancePass //我提交的机会-已通过
MyAuditChance //我审核的机会
MyAuditChanceWait //我审核的机会-待我审批
MyAuditChancePass //我审核的机会-待我审批
MyAuditChancePass //我审核的机会-已通过
MyAuditChanceReturn //我审核的机会-已退回
)
... ...
... ... @@ -8,6 +8,7 @@ var errmessge ErrorMap = map[int]string{
0: "成功",
1: "系统异常",
2: "参数错误",
3: "统一用户中心操作异常",
101: "clientId或clientSecret无效",
113: "签名验证失败",
1009: "验证码已失效",
... ...
... ... @@ -25,7 +25,7 @@ func init() {
)
beego.AddNamespace(nsV1)
nsH5 := beego.NewNamespace("h5", beego.NSInclude(&controllers.H5Controller{}))
nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{}))
beego.AddNamespace(nsH5)
beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
... ...
... ... @@ -74,7 +74,7 @@ func getUserCenterCheckSum(curTime, nonce, appKey, salt string) string {
//修改统一用户中心 用户信息
func ChangeUcenterUserInfo(uid int64, phone string, user *protocol.UCenterPutUserRequest) (err error) {
var message protocol.Message
log.Info(fmt.Sprintf("统一用户中心-修改密码 simnum:%v ucenter_id:%v user:%v", phone, uid, user))
log.Info(fmt.Sprintf("统一用户中心-修改密码 simnum:%vucenter_id:%vuser:%v", phone, uid, user))
//修改密码
if _, err = RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodPutUser, uid), http.MethodPut, user, &message); err != nil {
log.Error(err)
... ...
... ... @@ -51,11 +51,17 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
err = protocol.NewErrWithMessage(2002, err) //账号不存在
return
}
//获取最后一次公司编号给统一用户中心
if userAuth, err = models.GetUserAuthByUserId(user.Id, protocol.DeviceType); err == nil {
if company, err = models.GetCompanyById(userAuth.CurrentCompanyId); err == nil {
getUserRequest.CompanyId = company.UserCenterId
}
}
//else{
// log.Error(err)
// err = protocol.NewErrWithMessage(4139) //authCode无效或过期
// return
//}
//TODO:验证模块权限
//从用户中心获取用户信息
... ... @@ -92,6 +98,7 @@ Success:
userAuth, err = models.GetUserAuthByUserId(user.Id, 1)
if err != nil {
if err == orm.ErrNoRows {
err = nil
userAuth = &models.UserAuth{
UserId: user.Id,
DeviceType: 1, //int8(header.DeviceType),
... ... @@ -329,7 +336,7 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e
smsInfo.Count = 0
smsInfo.CreateTime = time.Now().Unix()
}
if smsInfo.Count >= protocol.SmscodeDayLimitTime { //TODO:limit send time
if beego.BConfig.RunMode != "prod" && smsInfo.Count >= protocol.SmscodeDayLimitTime { //TODO:limit send time
err = protocol.NewErrWithMessage(1011)
return
}
... ... @@ -340,7 +347,7 @@ Send:
smsInfo.Code = common.RandomStringWithChars(6, string(protocol.Nums))
smsInfo.LastTime = time.Now().Unix()
smsInfo.ErrorCount = 0
//Todo Lock
smsInfo.Checked = 0
smsInfo.Count += 1
if err = redis.Hset(key, request.Phone, common.AssertJson(smsInfo), -1); err != nil {
return
... ... @@ -371,7 +378,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
)
result = false
if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
log.Error(fmt.Sprintf("%v smscode not exists", phone))
log.Error(fmt.Sprintf("%vsmscode not exists", phone))
err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire"))
return
}
... ... @@ -385,7 +392,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
return
}
if (smsInfo.LastTime + 60*5) < time.Now().Unix() {
log.Error(fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime + 60*5), time.Now().Unix()))
log.Error(fmt.Sprintf("smscode phone:%v expire %v < %v", phone, (smsInfo.LastTime + 60*5), time.Now().Unix()))
err = protocol.NewErrWithMessage(1009)
goto Fail
}
... ...
... ... @@ -395,6 +395,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
company *models.Company
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
... ... @@ -425,8 +429,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
}
if groupId == 0 {
err = fmt.Errorf("group_id=0 template_id:%v", templateId)
log.Error(err)
log.Error(fmt.Sprintf("group_id=0 template_id:%v", templateId))
//log.Error(err)
return
}
... ... @@ -582,3 +586,10 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
}
return
}
//我的机会
func MyChance(header *protocol.RequestHeader, request *protocol.MyChanceRequest) (rsp *protocol.MyChanceResponse, err error) {
var ()
rsp = &protocol.MyChanceResponse{}
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"net/http"
"opp/internal/utils"
"opp/models"
"opp/protocol"
... ... @@ -46,7 +47,11 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
log.Error(err)
return
}
if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil {
if result, err = auth.CheckSmsCode(strings.TrimSpace(user.Phone), "", protocol.SmsCode); err != nil {
log.Error(err)
return
}
if result, err = auth.CheckSmsCode(request.Phone, request.Captcha, protocol.SmsCode); err != nil {
log.Error(err)
return
}
... ... @@ -142,8 +147,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
//修改密码
func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
var (
user *models.User
//loginResponse *protocol.UserCenterLoginResponse
user *models.User
loginResponse *protocol.UCenterGetUserResponse //UserCenterLoginResponse
)
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
err = protocol.NewErrWithMessage(2026)
... ... @@ -161,49 +166,54 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
log.Error(err)
return
}
err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
PassWord: request.NewPwd,
//Phone:user.Phone,
})
log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd))
if err != nil {
err = protocol.NewErrWithMessage(1)
log.Error(err)
return
}
//var message protocol.Message
//if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{
// PassWord: request.OldPwd,
// Phone: user.Phone,
// Type: 1,
// GrantType: protocol.LoginTypePassPord,
//}, &message); err != nil {
//err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
// PassWord: request.NewPwd,
// //Phone:user.Phone,
//})
//log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd))
//if err != nil {
// err = protocol.NewErrWithMessage(1)
// log.Error(err)
// return
//}
//if message.Errno == 0 && message.Errmsg == "ok" {
// if err = message.Unmarshal(&loginResponse); err != nil {
// log.Error(err)
// return
// }
// if loginResponse.Id != user.UserCenterId {
// log.Error(fmt.Sprintf("用户中心uid不一致 input:%v want:%v", loginResponse.Id, user.UserCenterId))
// err = protocol.NewErrWithMessage(1)
// return
// }
// err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
// PassWord: request.NewPwd,
// //Phone:user.Phone,
// })
//} else {
// if message.Errno == -1 {
// err = protocol.NewErrWithMessage(2028)
// } else {
// err = protocol.NewErrWithMessage(2028)
// }
// log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd), message.Errno, message.Errmsg)
// return
//}
var message protocol.Message
if _, err = agg.RequestUserCenter(protocol.MethodServerLogin, http.MethodPost, &protocol.UCenterLoginRequest{
PassWord: request.OldPwd,
Phone: user.Phone,
Type: 1,
GrantType: protocol.LoginTypePassPord,
}, &message); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(3)
return
}
if message.Errno == 0 && message.Errmsg == "ok" {
if err = message.Unmarshal(&loginResponse); err != nil {
log.Error(err)
return
}
if loginResponse.Id != user.UserCenterId {
log.Error(fmt.Sprintf("用户中心uid不一致 input:%v want:%v", loginResponse.Id, user.UserCenterId))
err = protocol.NewErrWithMessage(1)
return
}
if err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
PassWord: request.NewPwd,
//Phone:user.Phone,
}); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(3)
return
}
} else {
if message.Errno == -1 {
err = protocol.NewErrWithMessage(2028)
} else {
err = protocol.NewErrWithMessage(3)
}
log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd), message.Errno, message.Errmsg)
return
}
return
}
... ...