作者 陈志颖

feat:增加密码校验

... ... @@ -8,6 +8,8 @@ import (
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama"
//"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
)
... ... @@ -23,5 +25,8 @@ func main() {
//注册事件
event.InitEventCenter()
//启动kafaka消息订阅
go sarama.Run()
beego.Run()
}
... ...
... ... @@ -301,6 +301,48 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
return
}
// 企业平台-密码校验
func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginRequest) (v interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
loginSvr = domain_service.NewPgLoginService(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
// loginSvr 初始化
loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
v = map[string]interface{}{}
err = protocol.NewErrWithMessage(10001)
return
}
if len(request.Password) == 0 {
v = map[string]interface{}{}
err = protocol.NewCustomMessage(1, "密码不能为空!")
return
}
if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
v = map[string]interface{}{}
err = protocol.NewCustomMessage(1, "密码输入有误!")
return
}
v = map[string]interface{}{}
err = transactionContext.CommitTransaction()
return
}
// 企业平台-多公司登录
func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
var (
... ...
... ... @@ -81,6 +81,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new
}
return serviceGateway.handlerError(response)
}
func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) {
url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/")
request := serviceGateway.createRequest(url, "post")
... ...
... ... @@ -39,6 +39,7 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger {
log.SetLevel(ilv)
log.EnableFuncCallDepth(true)
log.SetLogFuncCallDepth(5)
log.SetPrefix(constant.LOG_PREFIX)
return log
}
... ...
... ... @@ -272,3 +272,32 @@ func (this *AuthController) UCenterRevoke() {
}
msg = protocol.NewReturnResponse(auth.UCenterRevoke(nil, int64(uid)))
}
/**
* @Author SteveChan
* @Description //校验密码
* @Date 01:00 2021/1/8
* @Param
* @return
**/
func (this *AuthController) CheckPassword() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.LoginRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := auth.PasswordLogin(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
... ... @@ -51,8 +51,14 @@ func (this *UserController) CheckSmsCode() {
msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request))
}
//ChangePhone
// @router /changePhone [post]
/**
* @Author SteveChan
* @Description //TODO 修改手机号
* @Date 00:29 2021/1/8
* @Param
* @return
* @router /changePhone [post]
**/
func (this *UserController) ChangePhone() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -71,15 +77,16 @@ func (this *UserController) ChangePhone() {
msg = protocol.NewMesage(1009) //验证码失效
return
}
if v := CacheSms.Get(request.OldPhone); v != nil {
if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
msg = protocol.NewMesage(1012) //验证码不一致
return
}
} else {
msg = protocol.NewMesage(1009) //验证码不一致
return
}
// TODO ?
//if v := CacheSms.Get(request.OldPhone); v != nil {
// if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
// msg = protocol.NewMesage(1012) //验证码不一致
// return
// }
//} else {
// msg = protocol.NewMesage(1009) //验证码不一致
// return
//}
header := this.GetRequestHeader(this.Ctx)
data, err := user.ChangePhone(header, request)
if err == nil {
... ...
... ... @@ -8,6 +8,7 @@ import (
func init() {
nsV1 := beego.NewNamespace("v1") //, beego.NSBefore(middleware.CheckJWTToken)
nsV1.Router("/auth/login", &controllers.AuthController{}, "Post:Login")
nsV1.Router("/auth/checkPassword", &controllers.AuthController{}, "Post:CheckPassword") // 校验密码
nsV1.Router("/auth/smsCode", &controllers.AuthController{}, "Post:SmsCode")
nsV1.Router("/auth/accessToken", &controllers.AuthController{}, "Post:AccessToken")
nsV1.Router("/auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken")
... ...
... ... @@ -2,10 +2,10 @@ package messageHandler
import "github.com/Shopify/sarama"
type UcenterMessageCommand struct {
type UCenterMessageCommand struct {
}
func (c *UcenterMessageCommand) ChangePhoneHandler(message interface{}) error {
func (c *UCenterMessageCommand) ChangePhoneHandler(message interface{}) error {
msg, ok := message.(*sarama.Message)
if !ok && msg == nil {
return nil
... ...
package sarama
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/kafkax"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama/messageHandler"
//"suplus-message/pkg/constant"
//"suplus-message/pkg/port/sarama/messageHandler"
)
type PgMessageReceiverRepository struct {
transactionContext *transaction.TransactionContext
}
func NewPgMessageReceiverRepository(transactionContext *transaction.TransactionContext) *PgMessageReceiverRepository {
return &PgMessageReceiverRepository{
transactionContext: transactionContext,
}
}
func (repository *PgMessageReceiverRepository) ReceiveMessage(params map[string]interface{}) error {
var num int
checkSql := `select count(0) from sys_message_consume where "offset" =? and topic=?`
_, err := repository.transactionContext.PgDd.Query(&num, checkSql, params["offset"], params["topic"])
if err != nil {
return err
}
if num > 0 {
return fmt.Errorf("receive repeate message [%v]", params)
}
sql := `insert into sys_message_consume(topic,partition,"offset",key,value,msg_time,create_at,status)values(?,?,?,?,?,?,?,?)`
_, err = repository.transactionContext.PgDd.Exec(sql, params["topic"], params["partition"], params["offset"], params["key"], params["value"], params["msg_time"], params["create_at"], params["status"])
return err
}
func (repository *PgMessageReceiverRepository) ConfirmReceive(params map[string]interface{}) error {
fmt.Println(params)
_, err := repository.transactionContext.PgDd.Exec(`update sys_message_consume set status=? where "offset" =? and topic=?`, int(models.Finished), params["offset"], params["topic"])
return err
}
func Run() {
var (
ucenterMessage = &messageHandler.UcenterMessageCommand{}
uCenterMessage = &messageHandler.UCenterMessageCommand{}
)
saramaConsumer := kafkax.NewSaramaConsumer(constant.KAFKA_HOSTS, constant.SERVICE_NAME)
saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, ucenterMessage.ChangePhoneHandler)
saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, uCenterMessage.ChangePhoneHandler)
saramaConsumer.WithMessageReceiver(NewPgMessageReceiverRepository(nil)) // 持久化
err := saramaConsumer.StartConsume()
if err != nil {
... ...
... ... @@ -55,9 +55,10 @@ type ChangePhoneRequest struct {
Phone string `json:"phone" valid:"Required"`
Captcha string `json:"captcha" valid:"Required"`
OldPhone string `json:"oldPhone" valid:"Required"`
CaptchaCertificate string `json:"captchaCertificate" valid:"Required"`
OldPhone string `json:"oldPhone" valid:"Required"`
//CaptchaCertificate string `json:"captchaCertificate" valid:"Required"`
}
type ChangePhoneResponse struct {
}
... ...