正在显示
7 个修改的文件
包含
258 行增加
和
125 行删除
@@ -52,6 +52,9 @@ func Partners(header *protocol.RequestHeader, request *protocolx.PartnersRequest | @@ -52,6 +52,9 @@ func Partners(header *protocol.RequestHeader, request *protocolx.PartnersRequest | ||
52 | log.Error(err) | 52 | log.Error(err) |
53 | return | 53 | return |
54 | } | 54 | } |
55 | + if rsp.Partners == nil { | ||
56 | + rsp.Partners = []struct{}{} | ||
57 | + } | ||
55 | err = transactionContext.CommitTransaction() | 58 | err = transactionContext.CommitTransaction() |
56 | return | 59 | return |
57 | } | 60 | } |
@@ -7,6 +7,8 @@ import ( | @@ -7,6 +7,8 @@ import ( | ||
7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" |
8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" |
9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
10 | + domain_service_i "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/domain_service" | ||
10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 12 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
11 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" | 13 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" |
12 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 14 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
@@ -129,9 +131,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | @@ -129,9 +131,7 @@ func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCode | ||
129 | func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) { | 131 | func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) { |
130 | var ( | 132 | var ( |
131 | transactionContext, _ = factory.CreateTransactionContext(nil) | 133 | transactionContext, _ = factory.CreateTransactionContext(nil) |
132 | - PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
133 | - PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
134 | - partnerInfo *domain.PartnerInfo | 134 | + UserAuthService = CreateUserAuthService(header.AdminType, transactionContext) |
135 | ) | 135 | ) |
136 | if err = transactionContext.StartTransaction(); err != nil { | 136 | if err = transactionContext.StartTransaction(); err != nil { |
137 | return nil, err | 137 | return nil, err |
@@ -139,32 +139,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -139,32 +139,10 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
139 | defer func() { | 139 | defer func() { |
140 | transactionContext.RollbackTransaction() | 140 | transactionContext.RollbackTransaction() |
141 | }() | 141 | }() |
142 | - // 管理员不支持修改手机号 | ||
143 | - if header.AdminType == int(protocolx.AdminTypeManager) { | ||
144 | - //if err=changeUserPhone(header.UserId,request.Phone,transactionContext);err!=nil{ | ||
145 | - // err = protocol.NewCustomMessage(1,err.Error()) | ||
146 | - //} | ||
147 | - return | ||
148 | - } | ||
149 | - if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { | ||
150 | - err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
151 | - return | ||
152 | - } | ||
153 | - //验证新手机是否已经存在 | ||
154 | - if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": request.Phone}); e == nil { | ||
155 | - err = protocol.NewErrWithMessage(2029, err) //账号已存在 | ||
156 | - return | ||
157 | - } | ||
158 | - if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil { | ||
159 | - log.Error(err) | ||
160 | - return | ||
161 | - } | ||
162 | - if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
163 | - "Id": partnerInfo.Id, | ||
164 | - "Account": request.Phone, | ||
165 | - }); err != nil { | 142 | + if err = UserAuthService.ChangeUserPhone(header.UserId, request.Phone, request.OldPhone); err != nil { |
166 | return | 143 | return |
167 | } | 144 | } |
145 | + //TODO:修改完手机号 ,token失效,清理缓存 | ||
168 | err = transactionContext.CommitTransaction() | 146 | err = transactionContext.CommitTransaction() |
169 | return | 147 | return |
170 | } | 148 | } |
@@ -172,10 +150,8 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | @@ -172,10 +150,8 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe | ||
172 | //重置密码 | 150 | //重置密码 |
173 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { | 151 | func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) { |
174 | var ( | 152 | var ( |
175 | - partnerInfo *domain.PartnerInfo | ||
176 | transactionContext, _ = factory.CreateTransactionContext(nil) | 153 | transactionContext, _ = factory.CreateTransactionContext(nil) |
177 | - PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
178 | - PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 154 | + UserAuthService = CreateUserAuthService(header.AdminType, transactionContext) |
179 | ) | 155 | ) |
180 | rsp = &protocol.ResetPasswordResponse{} | 156 | rsp = &protocol.ResetPasswordResponse{} |
181 | if err = transactionContext.StartTransaction(); err != nil { | 157 | if err = transactionContext.StartTransaction(); err != nil { |
@@ -184,40 +160,9 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -184,40 +160,9 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
184 | defer func() { | 160 | defer func() { |
185 | transactionContext.RollbackTransaction() | 161 | transactionContext.RollbackTransaction() |
186 | }() | 162 | }() |
187 | - if len(request.NewPwd) < 6 { | ||
188 | - err = protocol.NewErrWithMessage(2027) | ||
189 | - return | ||
190 | - } | ||
191 | - if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
192 | - err = protocol.NewErrWithMessage(2026) | ||
193 | - return | ||
194 | - } | ||
195 | - if header.AdminType == int(protocolx.AdminTypeManager) { | ||
196 | - if err = changeUserInfo(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd, transactionContext); err != nil { | ||
197 | - err = protocol.NewCustomMessage(1, err.Error()) | ||
198 | - } | ||
199 | - return | ||
200 | - } | ||
201 | - if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { | ||
202 | - err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
203 | - return | ||
204 | - } | ||
205 | - if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
206 | - "Id": partnerInfo.Id, | ||
207 | - "Password": request.ConfirmPwd, | ||
208 | - }); err != nil { | 163 | + if err = UserAuthService.ResetUserPassword(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd); err != nil { |
209 | return | 164 | return |
210 | } | 165 | } |
211 | - //清除auth token | ||
212 | - //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
213 | - //if !auth.Exist() { | ||
214 | - // return | ||
215 | - //} | ||
216 | - //if err = auth.RemoveAuth(); err != nil { | ||
217 | - // log.Error(err) | ||
218 | - // err = protocol.NewErrWithMessage(4140, err) | ||
219 | - // return | ||
220 | - //} | ||
221 | err = transactionContext.CommitTransaction() | 166 | err = transactionContext.CommitTransaction() |
222 | return | 167 | return |
223 | } | 168 | } |
@@ -225,10 +170,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -225,10 +170,8 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
225 | //修改密码 | 170 | //修改密码 |
226 | func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { | 171 | func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) { |
227 | var ( | 172 | var ( |
228 | - partnerInfo *domain.PartnerInfo | ||
229 | transactionContext, _ = factory.CreateTransactionContext(nil) | 173 | transactionContext, _ = factory.CreateTransactionContext(nil) |
230 | - PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
231 | - PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 174 | + UserAuthService = CreateUserAuthService(header.AdminType, transactionContext) |
232 | ) | 175 | ) |
233 | if err = transactionContext.StartTransaction(); err != nil { | 176 | if err = transactionContext.StartTransaction(); err != nil { |
234 | return nil, err | 177 | return nil, err |
@@ -237,49 +180,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | @@ -237,49 +180,10 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | ||
237 | transactionContext.RollbackTransaction() | 180 | transactionContext.RollbackTransaction() |
238 | }() | 181 | }() |
239 | rsp = &protocol.ChangePasswordResponse{} | 182 | rsp = &protocol.ChangePasswordResponse{} |
240 | - if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
241 | - err = protocol.NewErrWithMessage(2026) | ||
242 | - return | ||
243 | - } | ||
244 | - if header.AdminType == int(protocolx.AdminTypeManager) { | ||
245 | - if err = changeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum), transactionContext); err != nil { | 183 | + if err = UserAuthService.ChangeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum)); err != nil { |
246 | err = protocol.NewCustomMessage(1, err.Error()) | 184 | err = protocol.NewCustomMessage(1, err.Error()) |
247 | - } | ||
248 | return | 185 | return |
249 | } | 186 | } |
250 | - if strings.EqualFold(request.NewPwd, request.OldPwd) { | ||
251 | - err = protocol.NewErrWithMessage(2030) | ||
252 | - return | ||
253 | - } | ||
254 | - if len(request.NewPwd) < 6 { | ||
255 | - err = protocol.NewErrWithMessage(2027) | ||
256 | - return | ||
257 | - } | ||
258 | - if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { | ||
259 | - err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
260 | - return | ||
261 | - } | ||
262 | - if !strings.EqualFold(partnerInfo.Password, request.OldPwd) { | ||
263 | - //密码不一致 | ||
264 | - err = protocol.NewErrWithMessage(2028, err) //账号不存在 | ||
265 | - return | ||
266 | - } | ||
267 | - if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
268 | - "Id": partnerInfo.Id, | ||
269 | - "Password": request.ConfirmPwd, | ||
270 | - }); err != nil { | ||
271 | - return | ||
272 | - } | ||
273 | - //清除auth token | ||
274 | - //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
275 | - //if !auth.Exist() { | ||
276 | - // return | ||
277 | - //} | ||
278 | - //if err = auth.RemoveAuth(); err != nil { | ||
279 | - // log.Error(err) | ||
280 | - // err = protocol.NewErrWithMessage(4140, err) | ||
281 | - // return | ||
282 | - //} | ||
283 | err = transactionContext.CommitTransaction() | 187 | err = transactionContext.CommitTransaction() |
284 | return | 188 | return |
285 | } | 189 | } |
@@ -401,10 +305,10 @@ func changeUserInfo(userId int64, phone, password string, transactionContext *tr | @@ -401,10 +305,10 @@ func changeUserInfo(userId int64, phone, password string, transactionContext *tr | ||
401 | err = fmt.Errorf("用户不存在") | 305 | err = fmt.Errorf("用户不存在") |
402 | return | 306 | return |
403 | } | 307 | } |
404 | - _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, password) | 308 | + _, err = ucenterApiGateway.UpdateUser(user.OpenId, phone, password) |
405 | return | 309 | return |
406 | } | 310 | } |
407 | -func changeUserPhone(userId int64, phone string, transactionContext *transaction.TransactionContext) (err error) { | 311 | +func changeUserPhone(userId int64, phone, oldPhone string, transactionContext *transaction.TransactionContext) (err error) { |
408 | var ( | 312 | var ( |
409 | ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway() | 313 | ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway() |
410 | UsersRepository, _ = factory.CreateUsersRepository(transactionContext) | 314 | UsersRepository, _ = factory.CreateUsersRepository(transactionContext) |
@@ -419,10 +323,10 @@ func changeUserPhone(userId int64, phone string, transactionContext *transaction | @@ -419,10 +323,10 @@ func changeUserPhone(userId int64, phone string, transactionContext *transaction | ||
419 | err = protocol.NewErrWithMessage(2029, err) | 323 | err = protocol.NewErrWithMessage(2029, err) |
420 | return | 324 | return |
421 | } | 325 | } |
422 | - _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, "") | ||
423 | - if err != nil { | ||
424 | - _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId) | ||
425 | - } | 326 | + _, err = ucenterApiGateway.ChangePhone(phone, oldPhone) |
327 | + //if err != nil { | ||
328 | + // _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId) | ||
329 | + //} | ||
426 | return | 330 | return |
427 | } | 331 | } |
428 | func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) { | 332 | func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) { |
@@ -439,3 +343,22 @@ func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionC | @@ -439,3 +343,22 @@ func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionC | ||
439 | _, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd) | 343 | _, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd) |
440 | return | 344 | return |
441 | } | 345 | } |
346 | + | ||
347 | +func CreateUserAuthService(adminType int, transactionContext *transaction.TransactionContext) domain_service_i.UserAuthService { | ||
348 | + if adminType == int(protocolx.AdminTypeManager) { | ||
349 | + return domain_service.NewPgManagerAuthService(transactionContext) | ||
350 | + } | ||
351 | + return domain_service.NewPgPartnerAuthService(transactionContext) | ||
352 | +} | ||
353 | + | ||
354 | +//TODO:修改密码/重置密码 清除uer_auth 缓存 | ||
355 | +//清除auth token | ||
356 | +//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
357 | +//if !auth.Exist() { | ||
358 | +// return | ||
359 | +//} | ||
360 | +//if err = auth.RemoveAuth(); err != nil { | ||
361 | +// log.Error(err) | ||
362 | +// err = protocol.NewErrWithMessage(4140, err) | ||
363 | +// return | ||
364 | +//} |
pkg/domain/service/user_auth_service.go
0 → 100644
1 | +package domain_service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/tiptok/gocomm/xa/eda" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/repository" | ||
10 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | ||
12 | +) | ||
13 | + | ||
14 | +type PgManagerAuthService struct { | ||
15 | + eda.EventCenterPublisher | ||
16 | + transactionContext *transaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func NewPgManagerAuthService(ctx *transaction.TransactionContext) *PgManagerAuthService { | ||
20 | + return &PgManagerAuthService{ | ||
21 | + transactionContext: ctx, | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | +func (s *PgManagerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { | ||
26 | + var ( | ||
27 | + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway() | ||
28 | + UsersRepository, _ = repository.NewUsersRepository(s.transactionContext) | ||
29 | + user *domain.Users | ||
30 | + ) | ||
31 | + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { | ||
32 | + log.Error(err) | ||
33 | + err = fmt.Errorf("用户不存在") | ||
34 | + return | ||
35 | + } | ||
36 | + if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": newPhone}); e == nil || newUser != nil { | ||
37 | + err = fmt.Errorf("当前手机号已存在,请重新输入") | ||
38 | + return | ||
39 | + } | ||
40 | + _, err = ucenterApiGateway.ChangePhone(newPhone, oldPhone) | ||
41 | + if err == nil { | ||
42 | + _, err = s.transactionContext.PgTx.Exec("update users set phone=? where phone=?", newPhone, oldPhone) | ||
43 | + } | ||
44 | + //event | ||
45 | + return | ||
46 | +} | ||
47 | +func (s *PgManagerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { | ||
48 | + var ( | ||
49 | + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway() | ||
50 | + UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext) | ||
51 | + user *domain.Users | ||
52 | + ) | ||
53 | + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { | ||
54 | + log.Error(err) | ||
55 | + err = fmt.Errorf("用户不存在") | ||
56 | + return | ||
57 | + } | ||
58 | + _, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd) | ||
59 | + return | ||
60 | +} | ||
61 | +func (s *PgManagerAuthService) ResetUserPassword(userId int64, phone, password string) (err error) { | ||
62 | + var ( | ||
63 | + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway() | ||
64 | + UsersRepository, _ = factory.CreateUsersRepository(s.transactionContext) | ||
65 | + user *domain.Users | ||
66 | + ) | ||
67 | + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil { | ||
68 | + log.Error(err) | ||
69 | + err = fmt.Errorf("用户不存在") | ||
70 | + return | ||
71 | + } | ||
72 | + _, err = ucenterApiGateway.UpdateUser(user.OpenId, phone, password) | ||
73 | + return | ||
74 | +} |
1 | +package domain_service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/tiptok/gocomm/xa/eda" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/repository" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
10 | + "strings" | ||
11 | +) | ||
12 | + | ||
13 | +type PgPartnerAuthService struct { | ||
14 | + eda.EventCenterPublisher | ||
15 | + transactionContext *transaction.TransactionContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewPgPartnerAuthService(ctx *transaction.TransactionContext) *PgPartnerAuthService { | ||
19 | + return &PgPartnerAuthService{ | ||
20 | + transactionContext: ctx, | ||
21 | + } | ||
22 | +} | ||
23 | + | ||
24 | +func (s *PgPartnerAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { | ||
25 | + var ( | ||
26 | + PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext) | ||
27 | + PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext) | ||
28 | + partnerInfo *domain.PartnerInfo | ||
29 | + ) | ||
30 | + //验证新手机是否已经存在 | ||
31 | + if _, e := PartnerInfoService.FindOne(map[string]interface{}{"account": newPhone}); e == nil { | ||
32 | + err = protocol.NewErrWithMessage(2029, err) //账号已存在 | ||
33 | + return | ||
34 | + } | ||
35 | + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil || (partnerInfo.Account != oldPhone) { | ||
36 | + err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
37 | + return | ||
38 | + } | ||
39 | + if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
40 | + "Id": userId, | ||
41 | + "Account": newPhone, | ||
42 | + }); err != nil { | ||
43 | + return | ||
44 | + } | ||
45 | + return | ||
46 | +} | ||
47 | +func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { | ||
48 | + var ( | ||
49 | + partnerInfo *domain.PartnerInfo | ||
50 | + PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext) | ||
51 | + PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext) | ||
52 | + ) | ||
53 | + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil { | ||
54 | + err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
55 | + return | ||
56 | + } | ||
57 | + if !strings.EqualFold(partnerInfo.Password, oldPwd) { | ||
58 | + //密码不一致 | ||
59 | + err = protocol.NewErrWithMessage(2028, err) //账号不存在 | ||
60 | + return | ||
61 | + } | ||
62 | + if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
63 | + "Id": partnerInfo.Id, | ||
64 | + "Password": newPwd, | ||
65 | + }); err != nil { | ||
66 | + return | ||
67 | + } | ||
68 | + return | ||
69 | +} | ||
70 | +func (s *PgPartnerAuthService) ResetUserPassword(userId int64, phone, password string) (err error) { | ||
71 | + var ( | ||
72 | + partnerInfo *domain.PartnerInfo | ||
73 | + PartnerInfoDao, _ = dao.NewPartnerInfoDao(s.transactionContext) | ||
74 | + PartnerInfoService, _ = repository.NewPartnerInfoRepository(s.transactionContext) | ||
75 | + ) | ||
76 | + if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": userId}); err != nil { | ||
77 | + err = protocol.NewErrWithMessage(502, err) //账号不存在 | ||
78 | + return | ||
79 | + } | ||
80 | + if err = PartnerInfoDao.Update(map[string]interface{}{ | ||
81 | + "Id": partnerInfo.Id, | ||
82 | + "Password": password, | ||
83 | + }); err != nil { | ||
84 | + return | ||
85 | + } | ||
86 | + return | ||
87 | +} |
@@ -43,7 +43,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, passwo | @@ -43,7 +43,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, passwo | ||
43 | } | 43 | } |
44 | 44 | ||
45 | // 修改密码 | 45 | // 修改密码 |
46 | -func (serviceGateway *HttplibUCenterApiServiceGateway) UpdateUserPassword(uid int64, phone, password string) (int, error) { | 46 | +func (serviceGateway *HttplibUCenterApiServiceGateway) UpdateUser(uid int64, phone, password string) (int, error) { |
47 | url := strings.Join([]string{serviceGateway.baseURL, "users", fmt.Sprintf("%v", uid)}, "/") | 47 | url := strings.Join([]string{serviceGateway.baseURL, "users", fmt.Sprintf("%v", uid)}, "/") |
48 | request := serviceGateway.createRequest(url, "put") | 48 | request := serviceGateway.createRequest(url, "put") |
49 | //request.Header("appKey", constant.UCENTER_APP_KEY) | 49 | //request.Header("appKey", constant.UCENTER_APP_KEY) |
@@ -81,6 +81,21 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new | @@ -81,6 +81,21 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new | ||
81 | } | 81 | } |
82 | return serviceGateway.handlerError(response) | 82 | return serviceGateway.handlerError(response) |
83 | } | 83 | } |
84 | +func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) { | ||
85 | + url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/") | ||
86 | + request := serviceGateway.createRequest(url, "post") | ||
87 | + options := make(map[string]interface{}) | ||
88 | + options["phone"] = strings.TrimSpace(newPhone) | ||
89 | + options["oldPhone"] = strings.TrimSpace(oldPhone) | ||
90 | + request.JSONBody(options) | ||
91 | + response := make(map[string]interface{}) | ||
92 | + err := request.ToJSON(&response) | ||
93 | + if err != nil { | ||
94 | + log.Error("Service Gateway Fail:", err) | ||
95 | + return 0, err | ||
96 | + } | ||
97 | + return serviceGateway.handlerError(response) | ||
98 | +} | ||
84 | 99 | ||
85 | func (serviceGateway *HttplibUCenterApiServiceGateway) handlerError(in map[string]interface{}) (int, error) { | 100 | func (serviceGateway *HttplibUCenterApiServiceGateway) handlerError(in map[string]interface{}) (int, error) { |
86 | var rspCode int | 101 | var rspCode int |
@@ -67,19 +67,19 @@ func (this *UserController) ChangePhone() { | @@ -67,19 +67,19 @@ func (this *UserController) ChangePhone() { | ||
67 | msg = m | 67 | msg = m |
68 | return | 68 | return |
69 | } | 69 | } |
70 | - //if !CacheSms.IsExist(request.OldPhone) { | ||
71 | - // msg = protocol.NewMesage(1009) //验证码失效 | ||
72 | - // return | ||
73 | - //} | ||
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 | - //} | 70 | + if !CacheSms.IsExist(request.OldPhone) { |
71 | + msg = protocol.NewMesage(1009) //验证码失效 | ||
72 | + return | ||
73 | + } | ||
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 | + } | ||
83 | header := this.GetRequestHeader(this.Ctx) | 83 | header := this.GetRequestHeader(this.Ctx) |
84 | data, err := user.ChangePhone(header, request) | 84 | data, err := user.ChangePhone(header, request) |
85 | if err == nil { | 85 | if err == nil { |
@@ -105,6 +105,15 @@ func (this *UserController) ResetPassword() { | @@ -105,6 +105,15 @@ func (this *UserController) ResetPassword() { | ||
105 | msg = m | 105 | msg = m |
106 | return | 106 | return |
107 | } | 107 | } |
108 | + if len(request.NewPwd) < 6 { | ||
109 | + msg = protocol.BadRequestParam(2027) | ||
110 | + return | ||
111 | + } | ||
112 | + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
113 | + msg = protocol.BadRequestParam(2026) | ||
114 | + return | ||
115 | + } | ||
116 | + | ||
108 | if !CacheSms.IsExist(request.Phone) { | 117 | if !CacheSms.IsExist(request.Phone) { |
109 | msg = protocol.NewMesage(1009) //验证码失效 | 118 | msg = protocol.NewMesage(1009) //验证码失效 |
110 | return | 119 | return |
@@ -118,6 +127,7 @@ func (this *UserController) ResetPassword() { | @@ -118,6 +127,7 @@ func (this *UserController) ResetPassword() { | ||
118 | msg = protocol.NewMesage(1013) //验证码不一致 | 127 | msg = protocol.NewMesage(1013) //验证码不一致 |
119 | return | 128 | return |
120 | } | 129 | } |
130 | + | ||
121 | header := this.GetRequestHeader(this.Ctx) | 131 | header := this.GetRequestHeader(this.Ctx) |
122 | data, err := user.ResetPassword(header, request) | 132 | data, err := user.ResetPassword(header, request) |
123 | if err == nil { | 133 | if err == nil { |
@@ -139,10 +149,24 @@ func (this *UserController) ChangePassword() { | @@ -139,10 +149,24 @@ func (this *UserController) ChangePassword() { | ||
139 | msg = protocol.BadRequestParam(1) | 149 | msg = protocol.BadRequestParam(1) |
140 | return | 150 | return |
141 | } | 151 | } |
152 | + | ||
142 | if b, m := this.Valid(request); !b { | 153 | if b, m := this.Valid(request); !b { |
143 | msg = m | 154 | msg = m |
144 | return | 155 | return |
145 | } | 156 | } |
157 | + if strings.EqualFold(request.NewPwd, request.OldPwd) { | ||
158 | + msg = protocol.BadRequestParam(2030) | ||
159 | + return | ||
160 | + } | ||
161 | + if len(request.NewPwd) < 6 { | ||
162 | + msg = protocol.BadRequestParam(2027) | ||
163 | + return | ||
164 | + } | ||
165 | + if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { | ||
166 | + msg = protocol.BadRequestParam(2026) | ||
167 | + return | ||
168 | + } | ||
169 | + | ||
146 | header := this.GetRequestHeader(this.Ctx) | 170 | header := this.GetRequestHeader(this.Ctx) |
147 | data, err := user.ChangePassword(header, request) | 171 | data, err := user.ChangePassword(header, request) |
148 | if err == nil { | 172 | if err == nil { |
-
请 注册 或 登录 后发表评论