作者 yangfu

用户中心修改

@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "crypto/sha256" 4 "crypto/sha256"
5 "encoding/hex" 5 "encoding/hex"
6 "fmt" 6 "fmt"
  7 + "github.com/astaxie/beego/plugins/cors"
7 "strconv" 8 "strconv"
8 "strings" 9 "strings"
9 10
@@ -224,3 +225,36 @@ func CheckUuid(ctx *context.Context) (result bool) { @@ -224,3 +225,36 @@ func CheckUuid(ctx *context.Context) (result bool) {
224 } 225 }
225 return 226 return
226 } 227 }
  228 +
  229 +//AllowOption 允许跨域请求
  230 +var AllowOption = func(ctx *context.Context) {
  231 + if ctx.Request.Method != "OPTIONS" {
  232 + return
  233 + }
  234 + f := cors.Allow(&cors.Options{
  235 + AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
  236 + AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization",
  237 + "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息
  238 + ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
  239 + AllowCredentials: false, //不允许共享AuthTuffic证书
  240 + AllowAllOrigins: true, //允许的请求来源
  241 + })
  242 + f(ctx)
  243 + ctx.Output.Body([]byte("{}"))
  244 + ctx.Output.SetStatus(204)
  245 + return
  246 +}
  247 +
  248 +//LogRequestData Before Router
  249 +var LogRequestData = func(ctx *context.Context) {
  250 + log.Info("====>Recv Request:%s", ctx.Input.URI())
  251 + hmap := map[string]string{
  252 + //protocol.HeaderAccessToken: ctx.Input.Header(protocol.HeaderAccessToken),
  253 + //protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken),
  254 + }
  255 + if ctx.Input.RequestBody != nil {
  256 + log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody))
  257 + } else {
  258 + log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
  259 + }
  260 +}
@@ -251,3 +251,24 @@ func (this *ChanceController) ChanceStatistics() { @@ -251,3 +251,24 @@ func (this *ChanceController) ChanceStatistics() {
251 header := controllers.GetRequestHeader(this.Ctx) 251 header := controllers.GetRequestHeader(this.Ctx)
252 msg = protocol.NewReturnResponse(chance.ChanceStatistics(header, request)) 252 msg = protocol.NewReturnResponse(chance.ChanceStatistics(header, request))
253 } 253 }
  254 +
  255 +//MyChance 我的机会
  256 +//@router /myChance [post]
  257 +func (this *ChanceController) MyChance() {
  258 + var msg *protocol.ResponseMessage
  259 + defer func() {
  260 + this.Resp(msg)
  261 + }()
  262 + var request *protocol.MyChanceRequest
  263 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  264 + log.Error(err)
  265 + msg = protocol.BadRequestParam(1)
  266 + return
  267 + }
  268 + if b, m := this.Valid(request); !b {
  269 + msg = m
  270 + return
  271 + }
  272 + header := controllers.GetRequestHeader(this.Ctx)
  273 + msg = protocol.NewReturnResponse(chance.MyChance(header, request))
  274 +}
@@ -149,7 +149,7 @@ type AuditConfig struct { @@ -149,7 +149,7 @@ type AuditConfig struct {
149 NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】 149 NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】
150 } 150 }
151 151
152 -/*ChanceStatistics */ 152 +/*ChanceStatistics 首页-机会池统计*/
153 type ChanceStatisticsRequest struct { 153 type ChanceStatisticsRequest struct {
154 } 154 }
155 type ChanceStatisticsResponse struct { 155 type ChanceStatisticsResponse struct {
@@ -162,3 +162,10 @@ type ChanceTotalItem struct { @@ -162,3 +162,10 @@ type ChanceTotalItem struct {
162 Name string `json:"name"` //总数 162 Name string `json:"name"` //总数
163 Total int `json:"total"` 163 Total int `json:"total"`
164 } 164 }
  165 +
  166 +/*MyChance 我的机会*/
  167 +type MyChanceRequest struct {
  168 + Xxx string `json:"xxx" valid:"Required"`
  169 +}
  170 +type MyChanceResponse struct {
  171 +}
@@ -33,6 +33,6 @@ const ( @@ -33,6 +33,6 @@ const (
33 MyCommitChancePass //我提交的机会-已通过 33 MyCommitChancePass //我提交的机会-已通过
34 MyAuditChance //我审核的机会 34 MyAuditChance //我审核的机会
35 MyAuditChanceWait //我审核的机会-待我审批 35 MyAuditChanceWait //我审核的机会-待我审批
36 - MyAuditChancePass //我审核的机会-待我审批 36 + MyAuditChancePass //我审核的机会-已通过
37 MyAuditChanceReturn //我审核的机会-已退回 37 MyAuditChanceReturn //我审核的机会-已退回
38 ) 38 )
@@ -8,6 +8,7 @@ var errmessge ErrorMap = map[int]string{ @@ -8,6 +8,7 @@ var errmessge ErrorMap = map[int]string{
8 0: "成功", 8 0: "成功",
9 1: "系统异常", 9 1: "系统异常",
10 2: "参数错误", 10 2: "参数错误",
  11 + 3: "统一用户中心操作异常",
11 101: "clientId或clientSecret无效", 12 101: "clientId或clientSecret无效",
12 113: "签名验证失败", 13 113: "签名验证失败",
13 1009: "验证码已失效", 14 1009: "验证码已失效",
@@ -25,7 +25,7 @@ func init() { @@ -25,7 +25,7 @@ func init() {
25 ) 25 )
26 beego.AddNamespace(nsV1) 26 beego.AddNamespace(nsV1)
27 27
28 - nsH5 := beego.NewNamespace("h5", beego.NSInclude(&controllers.H5Controller{})) 28 + nsH5 := beego.NewNamespace("h5", beego.NSBefore(controllers.LogRequestData), beego.NSBefore(controllers.AllowOption), beego.NSInclude(&controllers.H5Controller{}))
29 beego.AddNamespace(nsH5) 29 beego.AddNamespace(nsH5)
30 30
31 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path")) 31 beego.SetStaticPath("/file/opp", beego.AppConfig.String("source_path"))
@@ -74,7 +74,7 @@ func getUserCenterCheckSum(curTime, nonce, appKey, salt string) string { @@ -74,7 +74,7 @@ func getUserCenterCheckSum(curTime, nonce, appKey, salt string) string {
74 //修改统一用户中心 用户信息 74 //修改统一用户中心 用户信息
75 func ChangeUcenterUserInfo(uid int64, phone string, user *protocol.UCenterPutUserRequest) (err error) { 75 func ChangeUcenterUserInfo(uid int64, phone string, user *protocol.UCenterPutUserRequest) (err error) {
76 var message protocol.Message 76 var message protocol.Message
77 - log.Info(fmt.Sprintf("统一用户中心-修改密码 simnum:%v ucenter_id:%v user:%v", phone, uid, user)) 77 + log.Info(fmt.Sprintf("统一用户中心-修改密码 simnum:%vucenter_id:%vuser:%v", phone, uid, user))
78 //修改密码 78 //修改密码
79 if _, err = RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodPutUser, uid), http.MethodPut, user, &message); err != nil { 79 if _, err = RequestUserCenter(fmt.Sprintf("%v%v", protocol.MethodPutUser, uid), http.MethodPut, user, &message); err != nil {
80 log.Error(err) 80 log.Error(err)
@@ -51,11 +51,17 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp @@ -51,11 +51,17 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp
51 err = protocol.NewErrWithMessage(2002, err) //账号不存在 51 err = protocol.NewErrWithMessage(2002, err) //账号不存在
52 return 52 return
53 } 53 }
  54 + //获取最后一次公司编号给统一用户中心
54 if userAuth, err = models.GetUserAuthByUserId(user.Id, protocol.DeviceType); err == nil { 55 if userAuth, err = models.GetUserAuthByUserId(user.Id, protocol.DeviceType); err == nil {
55 if company, err = models.GetCompanyById(userAuth.CurrentCompanyId); err == nil { 56 if company, err = models.GetCompanyById(userAuth.CurrentCompanyId); err == nil {
56 getUserRequest.CompanyId = company.UserCenterId 57 getUserRequest.CompanyId = company.UserCenterId
57 } 58 }
58 } 59 }
  60 + //else{
  61 + // log.Error(err)
  62 + // err = protocol.NewErrWithMessage(4139) //authCode无效或过期
  63 + // return
  64 + //}
59 //TODO:验证模块权限 65 //TODO:验证模块权限
60 66
61 //从用户中心获取用户信息 67 //从用户中心获取用户信息
@@ -92,6 +98,7 @@ Success: @@ -92,6 +98,7 @@ Success:
92 userAuth, err = models.GetUserAuthByUserId(user.Id, 1) 98 userAuth, err = models.GetUserAuthByUserId(user.Id, 1)
93 if err != nil { 99 if err != nil {
94 if err == orm.ErrNoRows { 100 if err == orm.ErrNoRows {
  101 + err = nil
95 userAuth = &models.UserAuth{ 102 userAuth = &models.UserAuth{
96 UserId: user.Id, 103 UserId: user.Id,
97 DeviceType: 1, //int8(header.DeviceType), 104 DeviceType: 1, //int8(header.DeviceType),
@@ -329,7 +336,7 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e @@ -329,7 +336,7 @@ func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, e
329 smsInfo.Count = 0 336 smsInfo.Count = 0
330 smsInfo.CreateTime = time.Now().Unix() 337 smsInfo.CreateTime = time.Now().Unix()
331 } 338 }
332 - if smsInfo.Count >= protocol.SmscodeDayLimitTime { //TODO:limit send time 339 + if beego.BConfig.RunMode != "prod" && smsInfo.Count >= protocol.SmscodeDayLimitTime { //TODO:limit send time
333 err = protocol.NewErrWithMessage(1011) 340 err = protocol.NewErrWithMessage(1011)
334 return 341 return
335 } 342 }
@@ -340,7 +347,7 @@ Send: @@ -340,7 +347,7 @@ Send:
340 smsInfo.Code = common.RandomStringWithChars(6, string(protocol.Nums)) 347 smsInfo.Code = common.RandomStringWithChars(6, string(protocol.Nums))
341 smsInfo.LastTime = time.Now().Unix() 348 smsInfo.LastTime = time.Now().Unix()
342 smsInfo.ErrorCount = 0 349 smsInfo.ErrorCount = 0
343 - //Todo Lock 350 + smsInfo.Checked = 0
344 smsInfo.Count += 1 351 smsInfo.Count += 1
345 if err = redis.Hset(key, request.Phone, common.AssertJson(smsInfo), -1); err != nil { 352 if err = redis.Hset(key, request.Phone, common.AssertJson(smsInfo), -1); err != nil {
346 return 353 return
@@ -371,7 +378,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { @@ -371,7 +378,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
371 ) 378 )
372 result = false 379 result = false
373 if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode 380 if value, err = redis.Hget(sendType, phone); err != nil { //protocol.SmsLoginCode
374 - log.Error(fmt.Sprintf("%v smscode not exists", phone)) 381 + log.Error(fmt.Sprintf("%vsmscode not exists", phone))
375 err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire")) 382 err = protocol.NewErrWithMessage(1009, fmt.Errorf("smscode expire"))
376 return 383 return
377 } 384 }
@@ -385,7 +392,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) { @@ -385,7 +392,7 @@ func CheckSmsCode(phone, code, sendType string) (result bool, err error) {
385 return 392 return
386 } 393 }
387 if (smsInfo.LastTime + 60*5) < time.Now().Unix() { 394 if (smsInfo.LastTime + 60*5) < time.Now().Unix() {
388 - log.Error(fmt.Sprintf("smscode expire %v < %v", (smsInfo.LastTime + 60*5), time.Now().Unix())) 395 + log.Error(fmt.Sprintf("smscode phone:%v expire %v < %v", phone, (smsInfo.LastTime + 60*5), time.Now().Unix()))
389 err = protocol.NewErrWithMessage(1009) 396 err = protocol.NewErrWithMessage(1009)
390 goto Fail 397 goto Fail
391 } 398 }
@@ -395,6 +395,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -395,6 +395,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
395 company *models.Company 395 company *models.Company
396 ) 396 )
397 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil { 397 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
  398 + if err == orm.ErrNoRows {
  399 + err = nil
  400 + return
  401 + }
398 log.Error(err) 402 log.Error(err)
399 return 403 return
400 } 404 }
@@ -425,8 +429,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat @@ -425,8 +429,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
425 } 429 }
426 430
427 if groupId == 0 { 431 if groupId == 0 {
428 - err = fmt.Errorf("group_id=0 template_id:%v", templateId)  
429 - log.Error(err) 432 + log.Error(fmt.Sprintf("group_id=0 template_id:%v", templateId))
  433 + //log.Error(err)
430 return 434 return
431 } 435 }
432 436
@@ -582,3 +586,10 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt @@ -582,3 +586,10 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
582 } 586 }
583 return 587 return
584 } 588 }
  589 +
  590 +//我的机会
  591 +func MyChance(header *protocol.RequestHeader, request *protocol.MyChanceRequest) (rsp *protocol.MyChanceResponse, err error) {
  592 + var ()
  593 + rsp = &protocol.MyChanceResponse{}
  594 + return
  595 +}
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/astaxie/beego/orm" 5 "github.com/astaxie/beego/orm"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid" 6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/uid"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  8 + "net/http"
8 "opp/internal/utils" 9 "opp/internal/utils"
9 "opp/models" 10 "opp/models"
10 "opp/protocol" 11 "opp/protocol"
@@ -46,7 +47,11 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -46,7 +47,11 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
46 log.Error(err) 47 log.Error(err)
47 return 48 return
48 } 49 }
49 - if result, err = auth.CheckSmsCode(user.Phone, request.Captcha, protocol.SmsCode); err != nil { 50 + if result, err = auth.CheckSmsCode(strings.TrimSpace(user.Phone), "", protocol.SmsCode); err != nil {
  51 + log.Error(err)
  52 + return
  53 + }
  54 + if result, err = auth.CheckSmsCode(request.Phone, request.Captcha, protocol.SmsCode); err != nil {
50 log.Error(err) 55 log.Error(err)
51 return 56 return
52 } 57 }
@@ -142,8 +147,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -142,8 +147,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
142 //修改密码 147 //修改密码
143 func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { 148 func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
144 var ( 149 var (
145 - user *models.User  
146 - //loginResponse *protocol.UserCenterLoginResponse 150 + user *models.User
  151 + loginResponse *protocol.UCenterGetUserResponse //UserCenterLoginResponse
147 ) 152 )
148 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { 153 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
149 err = protocol.NewErrWithMessage(2026) 154 err = protocol.NewErrWithMessage(2026)
@@ -161,49 +166,54 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -161,49 +166,54 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
161 log.Error(err) 166 log.Error(err)
162 return 167 return
163 } 168 }
164 - err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{  
165 - PassWord: request.NewPwd,  
166 - //Phone:user.Phone,  
167 - })  
168 - log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd))  
169 - if err != nil {  
170 - err = protocol.NewErrWithMessage(1)  
171 - log.Error(err)  
172 - return  
173 - }  
174 - //var message protocol.Message  
175 - //if _, err = agg.RequestUserCenter(protocol.MethodLogin, http.MethodPost, &protocol.UCenterLoginRequest{  
176 - // PassWord: request.OldPwd,  
177 - // Phone: user.Phone,  
178 - // Type: 1,  
179 - // GrantType: protocol.LoginTypePassPord,  
180 - //}, &message); err != nil { 169 + //err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
  170 + // PassWord: request.NewPwd,
  171 + // //Phone:user.Phone,
  172 + //})
  173 + //log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd))
  174 + //if err != nil {
  175 + // err = protocol.NewErrWithMessage(1)
181 // log.Error(err) 176 // log.Error(err)
182 // return 177 // return
183 //} 178 //}
184 - //if message.Errno == 0 && message.Errmsg == "ok" {  
185 - // if err = message.Unmarshal(&loginResponse); err != nil {  
186 - // log.Error(err)  
187 - // return  
188 - // }  
189 - // if loginResponse.Id != user.UserCenterId {  
190 - // log.Error(fmt.Sprintf("用户中心uid不一致 input:%v want:%v", loginResponse.Id, user.UserCenterId))  
191 - // err = protocol.NewErrWithMessage(1)  
192 - // return  
193 - // }  
194 - // err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{  
195 - // PassWord: request.NewPwd,  
196 - // //Phone:user.Phone,  
197 - // })  
198 - //} else {  
199 - // if message.Errno == -1 {  
200 - // err = protocol.NewErrWithMessage(2028)  
201 - // } else {  
202 - // err = protocol.NewErrWithMessage(2028)  
203 - // }  
204 - // log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd), message.Errno, message.Errmsg)  
205 - // return  
206 - //} 179 + var message protocol.Message
  180 + if _, err = agg.RequestUserCenter(protocol.MethodServerLogin, http.MethodPost, &protocol.UCenterLoginRequest{
  181 + PassWord: request.OldPwd,
  182 + Phone: user.Phone,
  183 + Type: 1,
  184 + GrantType: protocol.LoginTypePassPord,
  185 + }, &message); err != nil {
  186 + log.Error(err)
  187 + err = protocol.NewErrWithMessage(3)
  188 + return
  189 + }
  190 + if message.Errno == 0 && message.Errmsg == "ok" {
  191 + if err = message.Unmarshal(&loginResponse); err != nil {
  192 + log.Error(err)
  193 + return
  194 + }
  195 + if loginResponse.Id != user.UserCenterId {
  196 + log.Error(fmt.Sprintf("用户中心uid不一致 input:%v want:%v", loginResponse.Id, user.UserCenterId))
  197 + err = protocol.NewErrWithMessage(1)
  198 + return
  199 + }
  200 + if err = agg.ChangeUcenterUserInfo(user.UserCenterId, user.Phone, &protocol.UCenterPutUserRequest{
  201 + PassWord: request.NewPwd,
  202 + //Phone:user.Phone,
  203 + }); err != nil {
  204 + log.Error(err)
  205 + err = protocol.NewErrWithMessage(3)
  206 + return
  207 + }
  208 + } else {
  209 + if message.Errno == -1 {
  210 + err = protocol.NewErrWithMessage(2028)
  211 + } else {
  212 + err = protocol.NewErrWithMessage(3)
  213 + }
  214 + log.Debug(fmt.Sprintf("修改密码 simnum:%v ucenter_id:%v pwd:%v", user.Phone, user.UserCenterId, request.NewPwd), message.Errno, message.Errmsg)
  215 + return
  216 + }
207 return 217 return
208 } 218 }
209 219