@@ -11,24 +11,22 @@ export default class UserController extends Controller {
1111 this . logger . info ( '[ controller | user ] registerUser : 进入registerUser方法' ) ;
1212 // 校验参数
1313 const registerUserRule = {
14- username : { type : 'email' , required : true } ,
14+ username : { type : 'email' } ,
1515 password : {
1616 type : 'string' ,
17- required : true ,
18- allowEmpty : false ,
1917 format : / ^ (? = .* [ a - z ] ) (? = .* [ A - Z ] ) (? = .* \d ) [ a - z A - Z \d ] { 8 , } $ / ,
2018 } ,
2119 } ;
2220 const err = app . validator . validate ( registerUserRule , payload ) ;
2321 if ( err ?. length ) {
24- ctx . helper . commonJson ( ctx , { } , 400 , 'InvalidParameter' ) ;
22+ ctx . helper . commonJson ( ctx , { } , 500 , 'InvalidParameter' ) ;
2523 return ;
2624 }
2725 const { username, password } = payload ;
2826 // 判断用户是否已经存在
2927 const user = await ctx . service . user . getUserByName ( username ) ;
3028 if ( user ) {
31- ctx . helper . commonJson ( ctx , { } , 400 , 'UserAlreadyExist' ) ;
29+ ctx . helper . commonJson ( ctx , { } , 500 , 'UserAlreadyExist' ) ;
3230 return ;
3331 }
3432 const hash = BcryptUtils . genHash ( password ) ;
@@ -39,8 +37,6 @@ export default class UserController extends Controller {
3937 ctx . helper . commonJson ( ctx , userInfo , 200 ) ;
4038 } catch ( error ) {
4139 await transaction . rollback ( ) ;
42- console . log ( 'error' , error ) ;
43- // ctx.helper.exceptionHandling(ctx, error);
4440 ctx . helper . commonJson ( ctx , { } , 500 , 'InterError' ) ;
4541 }
4642 }
@@ -53,13 +49,11 @@ export default class UserController extends Controller {
5349 this . logger . info ( '[ controller | user ] getUserInfo : 进入getUserInfo方法' ) ;
5450 const userInfo = await ctx . service . user . getUserInfoById ( id ) ;
5551 if ( ! userInfo ) {
56- ctx . helper . commonJson ( ctx , { } , 404 , 'UserNotFound' ) ;
52+ ctx . helper . commonJson ( ctx , { } , 500 , 'UserNotFound' ) ;
5753 return ;
5854 }
5955 ctx . helper . commonJson ( ctx , userInfo , 200 ) ;
6056 } catch ( error ) {
61- console . log ( 'error' , error ) ;
62- // ctx.helper.exceptionHandling(ctx, error);
6357 ctx . helper . commonJson ( ctx , { } , 500 , 'InterError' ) ;
6458 }
6559 }
@@ -73,27 +67,27 @@ export default class UserController extends Controller {
7367 // 校验参数格式
7468 const err = app . validator . validate (
7569 {
76- username : { type : 'email' , required : true } ,
77- password : { type : 'string' , required : true , allowEmpty : false } ,
70+ username : { type : 'email' } ,
71+ password : { type : 'string' } ,
7872 } ,
7973 payload ,
8074 ) ;
8175 if ( err ?. length ) {
82- ctx . helper . commonJson ( ctx , { } , 400 , 'InvalidParameter' ) ;
76+ ctx . helper . commonJson ( ctx , { } , 500 , 'InvalidParameter' ) ;
8377 return ;
8478 }
8579
8680 // 用户是否存在
8781 const user = await ctx . service . user . getUserByName ( payload . username ) ;
8882 if ( ! user ) {
89- ctx . helper . commonJson ( ctx , { } , 400 , 'UserNotFound' ) ;
83+ ctx . helper . commonJson ( ctx , { } , 500 , 'UserNotFound' ) ;
9084 return ;
9185 }
9286
9387 // 密码是否正确
9488 const match = BcryptUtils . compare ( payload . password , user . password ) ;
9589 if ( ! match ) {
96- ctx . helper . commonJson ( ctx , { } , 401 , 'ErrorPassword' ) ;
90+ ctx . helper . commonJson ( ctx , { } , 500 , 'ErrorPassword' ) ;
9791 return ;
9892 }
9993
@@ -103,8 +97,6 @@ export default class UserController extends Controller {
10397 const token = this . app . jwt . sign ( userInfo . dataValues , secret , sign ) ;
10498 ctx . helper . commonJson ( ctx , { token } , 200 ) ;
10599 } catch ( error ) {
106- console . log ( 'error' , error ) ;
107- // ctx.helper.exceptionHandling(ctx, error);
108100 ctx . helper . commonJson ( ctx , { } , 500 , 'InterError' ) ;
109101 }
110102 }
0 commit comments