正在显示
10 个修改的文件
包含
140 行增加
和
17 行删除
@@ -8,6 +8,8 @@ import ( | @@ -8,6 +8,8 @@ import ( | ||
8 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" | 8 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" |
9 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" | 9 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" |
10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
11 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama" | ||
12 | + | ||
11 | //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr" | 13 | //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr" |
12 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" | 14 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" |
13 | ) | 15 | ) |
@@ -23,5 +25,8 @@ func main() { | @@ -23,5 +25,8 @@ func main() { | ||
23 | //注册事件 | 25 | //注册事件 |
24 | event.InitEventCenter() | 26 | event.InitEventCenter() |
25 | 27 | ||
28 | + //启动kafaka消息订阅 | ||
29 | + go sarama.Run() | ||
30 | + | ||
26 | beego.Run() | 31 | beego.Run() |
27 | } | 32 | } |
@@ -301,6 +301,48 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. | @@ -301,6 +301,48 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. | ||
301 | return | 301 | return |
302 | } | 302 | } |
303 | 303 | ||
304 | +// 企业平台-密码校验 | ||
305 | +func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginRequest) (v interface{}, err error) { | ||
306 | + var ( | ||
307 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
308 | + loginSvr = domain_service.NewPgLoginService(transactionContext) | ||
309 | + ) | ||
310 | + | ||
311 | + if err = transactionContext.StartTransaction(); err != nil { | ||
312 | + log.Error(err) | ||
313 | + return nil, err | ||
314 | + } | ||
315 | + | ||
316 | + defer func() { | ||
317 | + transactionContext.RollbackTransaction() | ||
318 | + }() | ||
319 | + | ||
320 | + // loginSvr 初始化 | ||
321 | + loginSvr.Init(request.Phone) | ||
322 | + | ||
323 | + if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 { | ||
324 | + v = map[string]interface{}{} | ||
325 | + err = protocol.NewErrWithMessage(10001) | ||
326 | + return | ||
327 | + } | ||
328 | + | ||
329 | + if len(request.Password) == 0 { | ||
330 | + v = map[string]interface{}{} | ||
331 | + err = protocol.NewCustomMessage(1, "密码不能为空!") | ||
332 | + return | ||
333 | + } | ||
334 | + | ||
335 | + if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil { | ||
336 | + v = map[string]interface{}{} | ||
337 | + err = protocol.NewCustomMessage(1, "密码输入有误!") | ||
338 | + return | ||
339 | + } | ||
340 | + | ||
341 | + v = map[string]interface{}{} | ||
342 | + err = transactionContext.CommitTransaction() | ||
343 | + return | ||
344 | +} | ||
345 | + | ||
304 | // 企业平台-多公司登录 | 346 | // 企业平台-多公司登录 |
305 | func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { | 347 | func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { |
306 | var ( | 348 | var ( |
@@ -81,6 +81,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new | @@ -81,6 +81,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new | ||
81 | } | 81 | } |
82 | return serviceGateway.handlerError(response) | 82 | return serviceGateway.handlerError(response) |
83 | } | 83 | } |
84 | + | ||
84 | func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) { | 85 | func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) { |
85 | url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/") | 86 | url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/") |
86 | request := serviceGateway.createRequest(url, "post") | 87 | request := serviceGateway.createRequest(url, "post") |
@@ -39,6 +39,7 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger { | @@ -39,6 +39,7 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger { | ||
39 | log.SetLevel(ilv) | 39 | log.SetLevel(ilv) |
40 | log.EnableFuncCallDepth(true) | 40 | log.EnableFuncCallDepth(true) |
41 | log.SetLogFuncCallDepth(5) | 41 | log.SetLogFuncCallDepth(5) |
42 | + log.SetPrefix(constant.LOG_PREFIX) | ||
42 | return log | 43 | return log |
43 | } | 44 | } |
44 | 45 |
@@ -272,3 +272,32 @@ func (this *AuthController) UCenterRevoke() { | @@ -272,3 +272,32 @@ func (this *AuthController) UCenterRevoke() { | ||
272 | } | 272 | } |
273 | msg = protocol.NewReturnResponse(auth.UCenterRevoke(nil, int64(uid))) | 273 | msg = protocol.NewReturnResponse(auth.UCenterRevoke(nil, int64(uid))) |
274 | } | 274 | } |
275 | + | ||
276 | +/** | ||
277 | + * @Author SteveChan | ||
278 | + * @Description //校验密码 | ||
279 | + * @Date 01:00 2021/1/8 | ||
280 | + * @Param | ||
281 | + * @return | ||
282 | + **/ | ||
283 | +func (this *AuthController) CheckPassword() { | ||
284 | + var msg *protocol.ResponseMessage | ||
285 | + defer func() { | ||
286 | + this.Resp(msg) | ||
287 | + }() | ||
288 | + var request *protocol.LoginRequest | ||
289 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
290 | + msg = protocol.BadRequestParam(1) | ||
291 | + return | ||
292 | + } | ||
293 | + if b, m := this.Valid(request); !b { | ||
294 | + msg = m | ||
295 | + return | ||
296 | + } | ||
297 | + header := this.GetRequestHeader(this.Ctx) | ||
298 | + data, err := auth.PasswordLogin(header, request) | ||
299 | + if err != nil { | ||
300 | + log.Error(err) | ||
301 | + } | ||
302 | + msg = protocol.NewReturnResponse(data, err) | ||
303 | +} |
@@ -51,8 +51,14 @@ func (this *UserController) CheckSmsCode() { | @@ -51,8 +51,14 @@ func (this *UserController) CheckSmsCode() { | ||
51 | msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request)) | 51 | msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request)) |
52 | } | 52 | } |
53 | 53 | ||
54 | -//ChangePhone | ||
55 | -// @router /changePhone [post] | 54 | +/** |
55 | + * @Author SteveChan | ||
56 | + * @Description //TODO 修改手机号 | ||
57 | + * @Date 00:29 2021/1/8 | ||
58 | + * @Param | ||
59 | + * @return | ||
60 | + * @router /changePhone [post] | ||
61 | + **/ | ||
56 | func (this *UserController) ChangePhone() { | 62 | func (this *UserController) ChangePhone() { |
57 | var msg *protocol.ResponseMessage | 63 | var msg *protocol.ResponseMessage |
58 | defer func() { | 64 | defer func() { |
@@ -71,15 +77,16 @@ func (this *UserController) ChangePhone() { | @@ -71,15 +77,16 @@ func (this *UserController) ChangePhone() { | ||
71 | msg = protocol.NewMesage(1009) //验证码失效 | 77 | msg = protocol.NewMesage(1009) //验证码失效 |
72 | return | 78 | return |
73 | } | 79 | } |
74 | - if v := CacheSms.Get(request.OldPhone); v != nil { | ||
75 | - if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) { | ||
76 | - msg = protocol.NewMesage(1012) //验证码不一致 | ||
77 | - return | ||
78 | - } | ||
79 | - } else { | ||
80 | - msg = protocol.NewMesage(1009) //验证码不一致 | ||
81 | - return | ||
82 | - } | 80 | + // TODO ? |
81 | + //if v := CacheSms.Get(request.OldPhone); v != nil { | ||
82 | + // if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) { | ||
83 | + // msg = protocol.NewMesage(1012) //验证码不一致 | ||
84 | + // return | ||
85 | + // } | ||
86 | + //} else { | ||
87 | + // msg = protocol.NewMesage(1009) //验证码不一致 | ||
88 | + // return | ||
89 | + //} | ||
83 | header := this.GetRequestHeader(this.Ctx) | 90 | header := this.GetRequestHeader(this.Ctx) |
84 | data, err := user.ChangePhone(header, request) | 91 | data, err := user.ChangePhone(header, request) |
85 | if err == nil { | 92 | if err == nil { |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | func init() { | 8 | func init() { |
9 | nsV1 := beego.NewNamespace("v1") //, beego.NSBefore(middleware.CheckJWTToken) | 9 | nsV1 := beego.NewNamespace("v1") //, beego.NSBefore(middleware.CheckJWTToken) |
10 | nsV1.Router("/auth/login", &controllers.AuthController{}, "Post:Login") | 10 | nsV1.Router("/auth/login", &controllers.AuthController{}, "Post:Login") |
11 | + nsV1.Router("/auth/checkPassword", &controllers.AuthController{}, "Post:CheckPassword") // 校验密码 | ||
11 | nsV1.Router("/auth/smsCode", &controllers.AuthController{}, "Post:SmsCode") | 12 | nsV1.Router("/auth/smsCode", &controllers.AuthController{}, "Post:SmsCode") |
12 | nsV1.Router("/auth/accessToken", &controllers.AuthController{}, "Post:AccessToken") | 13 | nsV1.Router("/auth/accessToken", &controllers.AuthController{}, "Post:AccessToken") |
13 | nsV1.Router("/auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") | 14 | nsV1.Router("/auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") |
@@ -2,10 +2,10 @@ package messageHandler | @@ -2,10 +2,10 @@ package messageHandler | ||
2 | 2 | ||
3 | import "github.com/Shopify/sarama" | 3 | import "github.com/Shopify/sarama" |
4 | 4 | ||
5 | -type UcenterMessageCommand struct { | 5 | +type UCenterMessageCommand struct { |
6 | } | 6 | } |
7 | 7 | ||
8 | -func (c *UcenterMessageCommand) ChangePhoneHandler(message interface{}) error { | 8 | +func (c *UCenterMessageCommand) ChangePhoneHandler(message interface{}) error { |
9 | msg, ok := message.(*sarama.Message) | 9 | msg, ok := message.(*sarama.Message) |
10 | if !ok && msg == nil { | 10 | if !ok && msg == nil { |
11 | return nil | 11 | return nil |
1 | package sarama | 1 | package sarama |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/kafkax" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/kafkax" |
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/models" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama/messageHandler" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama/messageHandler" |
8 | //"suplus-message/pkg/constant" | 11 | //"suplus-message/pkg/constant" |
9 | //"suplus-message/pkg/port/sarama/messageHandler" | 12 | //"suplus-message/pkg/port/sarama/messageHandler" |
10 | ) | 13 | ) |
11 | 14 | ||
15 | +type PgMessageReceiverRepository struct { | ||
16 | + transactionContext *transaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func NewPgMessageReceiverRepository(transactionContext *transaction.TransactionContext) *PgMessageReceiverRepository { | ||
20 | + return &PgMessageReceiverRepository{ | ||
21 | + transactionContext: transactionContext, | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | +func (repository *PgMessageReceiverRepository) ReceiveMessage(params map[string]interface{}) error { | ||
26 | + var num int | ||
27 | + checkSql := `select count(0) from sys_message_consume where "offset" =? and topic=?` | ||
28 | + _, err := repository.transactionContext.PgDd.Query(&num, checkSql, params["offset"], params["topic"]) | ||
29 | + if err != nil { | ||
30 | + return err | ||
31 | + } | ||
32 | + if num > 0 { | ||
33 | + return fmt.Errorf("receive repeate message [%v]", params) | ||
34 | + } | ||
35 | + | ||
36 | + sql := `insert into sys_message_consume(topic,partition,"offset",key,value,msg_time,create_at,status)values(?,?,?,?,?,?,?,?)` | ||
37 | + _, err = repository.transactionContext.PgDd.Exec(sql, params["topic"], params["partition"], params["offset"], params["key"], params["value"], params["msg_time"], params["create_at"], params["status"]) | ||
38 | + return err | ||
39 | +} | ||
40 | + | ||
41 | +func (repository *PgMessageReceiverRepository) ConfirmReceive(params map[string]interface{}) error { | ||
42 | + fmt.Println(params) | ||
43 | + _, err := repository.transactionContext.PgDd.Exec(`update sys_message_consume set status=? where "offset" =? and topic=?`, int(models.Finished), params["offset"], params["topic"]) | ||
44 | + return err | ||
45 | +} | ||
46 | + | ||
12 | func Run() { | 47 | func Run() { |
13 | var ( | 48 | var ( |
14 | - ucenterMessage = &messageHandler.UcenterMessageCommand{} | 49 | + uCenterMessage = &messageHandler.UCenterMessageCommand{} |
15 | ) | 50 | ) |
16 | 51 | ||
17 | saramaConsumer := kafkax.NewSaramaConsumer(constant.KAFKA_HOSTS, constant.SERVICE_NAME) | 52 | saramaConsumer := kafkax.NewSaramaConsumer(constant.KAFKA_HOSTS, constant.SERVICE_NAME) |
18 | - saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, ucenterMessage.ChangePhoneHandler) | 53 | + saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, uCenterMessage.ChangePhoneHandler) |
54 | + saramaConsumer.WithMessageReceiver(NewPgMessageReceiverRepository(nil)) // 持久化 | ||
19 | 55 | ||
20 | err := saramaConsumer.StartConsume() | 56 | err := saramaConsumer.StartConsume() |
21 | if err != nil { | 57 | if err != nil { |
@@ -55,9 +55,10 @@ type ChangePhoneRequest struct { | @@ -55,9 +55,10 @@ type ChangePhoneRequest struct { | ||
55 | Phone string `json:"phone" valid:"Required"` | 55 | Phone string `json:"phone" valid:"Required"` |
56 | Captcha string `json:"captcha" valid:"Required"` | 56 | Captcha string `json:"captcha" valid:"Required"` |
57 | 57 | ||
58 | - OldPhone string `json:"oldPhone" valid:"Required"` | ||
59 | - CaptchaCertificate string `json:"captchaCertificate" valid:"Required"` | 58 | + OldPhone string `json:"oldPhone" valid:"Required"` |
59 | + //CaptchaCertificate string `json:"captchaCertificate" valid:"Required"` | ||
60 | } | 60 | } |
61 | + | ||
61 | type ChangePhoneResponse struct { | 62 | type ChangePhoneResponse struct { |
62 | } | 63 | } |
63 | 64 |
-
请 注册 或 登录 后发表评论