作者 陈志颖

合并分支 'dev' 到 'test'

feat:增加修改手机号后强制退出登录



查看合并请求 !70
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
@@ -274,6 +274,7 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. @@ -274,6 +274,7 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
274 ) 274 )
275 275
276 rsp = &protocol.RevokeResponse{} 276 rsp = &protocol.RevokeResponse{}
  277 +
277 if err = transactionContext.StartTransaction(); err != nil { 278 if err = transactionContext.StartTransaction(); err != nil {
278 return nil, err 279 return nil, err
279 } 280 }
@@ -286,8 +287,10 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. @@ -286,8 +287,10 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
286 err = nil 287 err = nil
287 return 288 return
288 } 289 }
  290 +
289 //注销凭证 291 //注销凭证
290 userAuth.NewRedisUserCredential(user.Phone).RemoveAuth() 292 userAuth.NewRedisUserCredential(user.Phone).RemoveAuth()
  293 +
291 //注销token 294 //注销token
292 id, _ := strconv.Atoi(user.Phone) 295 id, _ := strconv.Atoi(user.Phone)
293 auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(id))) 296 auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(id)))
@@ -298,6 +301,7 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. @@ -298,6 +301,7 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
298 log.Error(err) 301 log.Error(err)
299 return 302 return
300 } 303 }
  304 +
301 err = transactionContext.CommitTransaction() 305 err = transactionContext.CommitTransaction()
302 return 306 return
303 } 307 }
@@ -10,3 +10,5 @@ func CreateTransactionContext(options map[string]interface{}) (*transaction.Tran @@ -10,3 +10,5 @@ func CreateTransactionContext(options map[string]interface{}) (*transaction.Tran
10 PgDd: pg.DB, 10 PgDd: pg.DB,
11 }, nil 11 }, nil
12 } 12 }
  13 +
  14 +
1 package user 1 package user
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "fmt" 5 "fmt"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth"
9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" 11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 12 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
11 domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service" 13 domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service"
@@ -132,20 +134,82 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -132,20 +134,82 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
132 transactionContext, _ = factory.CreateTransactionContext(nil) 134 transactionContext, _ = factory.CreateTransactionContext(nil)
133 UserAuthService = CreateUserAuthService(header.AdminType, transactionContext) 135 UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
134 ) 136 )
  137 +
135 if err = transactionContext.StartTransaction(); err != nil { 138 if err = transactionContext.StartTransaction(); err != nil {
136 return nil, err 139 return nil, err
137 } 140 }
138 defer func() { 141 defer func() {
139 transactionContext.RollbackTransaction() 142 transactionContext.RollbackTransaction()
140 }() 143 }()
  144 +
141 if err = UserAuthService.ChangeUserPhone(header.UserId, request.Phone, request.OldPhone); err != nil { 145 if err = UserAuthService.ChangeUserPhone(header.UserId, request.Phone, request.OldPhone); err != nil {
142 err = protocol.NewCustomMessage(1, err.Error()) 146 err = protocol.NewCustomMessage(1, err.Error())
143 return 147 return
144 } 148 }
  149 +
145 err = transactionContext.CommitTransaction() 150 err = transactionContext.CommitTransaction()
146 return 151 return
147 } 152 }
148 153
  154 +// ChangePhoneAllCompany 修改手机号,强制退出登录
  155 +func ChangePhoneAllCompany(header *protocol.RequestHeader, request *protocol.ChangePhoneAllCompanyRequest) (rsp *protocol.ChangePhoneAllCompanyResponse, err error) {
  156 + var (
  157 + transactionContext, _ = factory.CreateTransactionContext(nil)
  158 + UserAuthService = CreateUserAuthService(header.AdminType, transactionContext)
  159 + )
  160 +
  161 + if err = transactionContext.StartTransaction(); err != nil {
  162 + return nil, err
  163 + }
  164 + defer func() {
  165 + _ = transactionContext.RollbackTransaction()
  166 + }()
  167 +
  168 + if request.Module == "employee" && request.Action == "changePhoneAllCompany" {
  169 + var oldPhone string
  170 + var newPhone string
  171 + var data map[string]interface{}
  172 +
  173 + err := json.Unmarshal([]byte(request.Data), &data)
  174 + if err != nil {
  175 + return nil, err
  176 + }
  177 +
  178 + if value, ok := data["old_phone"]; ok {
  179 + oldPhone = value.(string)
  180 + }
  181 + if value, ok := data["new_phone"]; ok {
  182 + newPhone = value.(string)
  183 + }
  184 +
  185 + if err = UserAuthService.ChangeUserPhone(header.UserId, newPhone, oldPhone); err != nil {
  186 + err = protocol.NewCustomMessage(1, err.Error())
  187 + return nil, err
  188 + }
  189 +
  190 + //注销凭证
  191 + errRemoveAuth := userAuth.NewRedisUserCredential(oldPhone).RemoveAuth()
  192 + if errRemoveAuth != nil {
  193 + log.Error(err)
  194 + return nil, err
  195 + }
  196 +
  197 + //注销token
  198 + id, _ := strconv.Atoi(oldPhone)
  199 + uAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(id)))
  200 + if !uAuth.Exist() {
  201 + return nil, nil
  202 + }
  203 + if err = uAuth.RemoveAuth(); err != nil {
  204 + log.Error(err)
  205 + return nil, err
  206 + }
  207 + }
  208 +
  209 + err = transactionContext.CommitTransaction()
  210 + return nil, err
  211 +}
  212 +
149 //重置密码 213 //重置密码
150 func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { 214 func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
151 var ( 215 var (
不能预览此文件类型
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 type UserAuthService interface { 3 type UserAuthService interface {
4 ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) 4 ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error)
  5 + ChangeUserPhoneAllCompany(userId int64, newPhone, oldPhone string) (err error)
5 ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) 6 ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error)
6 ResetUserPassword(userId int64, phone, password string) (err error) 7 ResetUserPassword(userId int64, phone, password string) (err error)
7 } 8 }
不能预览此文件类型
@@ -13,6 +13,8 @@ type PgAuthService struct { @@ -13,6 +13,8 @@ type PgAuthService struct {
13 partner *PgPartnerAuthService 13 partner *PgPartnerAuthService
14 } 14 }
15 15
  16 +
  17 +
16 func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { 18 func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
17 return &PgAuthService{ 19 return &PgAuthService{
18 manager: NewPgManagerAuthService(ctx), 20 manager: NewPgManagerAuthService(ctx),
@@ -20,6 +22,10 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { @@ -20,6 +22,10 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
20 } 22 }
21 } 23 }
22 24
  25 +func (s *PgAuthService) ChangeUserPhoneAllCompany(userId int64, newPhone, oldPhone string) (err error) {
  26 + panic("implement me")
  27 +}
  28 +
23 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { 29 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
24 errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号 30 errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
25 errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号 31 errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
不能预览此文件类型
@@ -53,6 +53,35 @@ func (this *UserController) CheckSmsCode() { @@ -53,6 +53,35 @@ func (this *UserController) CheckSmsCode() {
53 msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request)) 53 msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request))
54 } 54 }
55 55
  56 +// ChangePhoneAllCompany TODO 企业平台调用修改手机号
  57 +func (this *UserController) ChangePhoneAllCompany() {
  58 + var msg *protocol.ResponseMessage
  59 +
  60 + defer func() {
  61 + this.Resp(msg)
  62 + }()
  63 +
  64 + var request *protocol.ChangePhoneAllCompanyRequest
  65 +
  66 + header := this.GetRequestHeader(this.Ctx)
  67 +
  68 + if err := this.JsonUnmarshal(&request); err != nil {
  69 + msg = protocol.BadRequestParam(1)
  70 + return
  71 + }
  72 + if b, m := this.Valid(request); !b {
  73 + msg = m
  74 + return
  75 + }
  76 +
  77 + data, err := user.ChangePhoneAllCompany(header, request)
  78 + if err == nil {
  79 + msg = protocol.NewResponseMessage(0, "修改手机号成功")
  80 + return
  81 + }
  82 + msg = protocol.NewReturnResponse(data, err)
  83 +}
  84 +
56 /** 85 /**
57 * @Author SteveChan 86 * @Author SteveChan
58 * @Description //TODO 修改手机号 87 * @Description //TODO 修改手机号
@@ -7,4 +7,5 @@ import ( @@ -7,4 +7,5 @@ import (
7 7
8 func init() { 8 func init() {
9 beego.Router("ucenter/user/revoke", &controllers.AuthController{}, "Post:UCenterRevoke") 9 beego.Router("ucenter/user/revoke", &controllers.AuthController{}, "Post:UCenterRevoke")
  10 + beego.Router("api/business/index", &controllers.UserController{}, "Post:ChangePhoneAllCompany")
10 } 11 }
@@ -62,6 +62,17 @@ type ChangePhoneRequest struct { @@ -62,6 +62,17 @@ type ChangePhoneRequest struct {
62 type ChangePhoneResponse struct { 62 type ChangePhoneResponse struct {
63 } 63 }
64 64
  65 +type ChangePhoneAllCompanyRequest struct {
  66 + // position:职位,department:部门,employee:员工,company:公司,profile员工档案
  67 + Module string `json:"module" valid:"Required"`
  68 + // add:添加,edit:编辑,delete删除,batchDelete:批量删除,setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,changeAdmin换管理员
  69 + Action string `json:"action" valid:"Required"`
  70 + // 具体的对象JSON数据
  71 + Data string `json:"data" valid:"Required"`
  72 +}
  73 +
  74 +type ChangePhoneAllCompanyResponse struct {}
  75 +
65 /*ResetPassword */ 76 /*ResetPassword */
66 type ResetPasswordRequest struct { 77 type ResetPasswordRequest struct {
67 //Captcha string `json:"captcha" valid:"Required"` 78 //Captcha string `json:"captcha" valid:"Required"`