@ -14,38 +14,17 @@ module.exports = {
controller : async ( req , res , next ) => {
controller : async ( req , res , next ) => {
const errors = [ ] ;
const errors = await checkSchema ( [
{ result : existsBody ( req . body . username ) , expected : true , error : 'Missing username' } ,
//check exist
{ result : lengthBody ( req . body . username , 1 , 50 ) , expected : false , error : 'Username must be 50 characters or less' } ,
if ( ! req . body . username || req . body . username . length <= 0 ) {
{ result : existsBody ( req . body . password ) , expected : true , error : 'Missing password' } ,
errors . push ( 'Missing username' ) ;
{ result : lengthBody ( req . body . password , 1 , 50 ) , expected : false , error : 'Password must be 50 characters or less' } ,
}
{ result : existsBody ( req . body . newpassword ) , expected : true , error : 'Missing new password' } ,
if ( ! req . body . password || req . body . password . length <= 0 ) {
{ result : lengthBody ( req . body . newpassword , 1 , 100 ) , expected : false , error : 'New pasword must be 100 characters or less' } ,
errors . push ( 'Missing password' ) ;
{ result : existsBody ( req . body . newpasswordconfirm ) , expected : true , error : 'Missing new password confirmation' } ,
}
{ result : lengthBody ( req . body . newpasswordconfirm , 1 , 100 ) , expected : false , error : 'New password confirmation must be 100 characters or less' } ,
if ( ! req . body . newpassword || req . body . newpassword . length <= 0 ) {
{ result : ( req . body . newpassword === req . body . newpasswordconfirm ) , expected : true , error : 'New password and password confirmation must match' } ,
errors . push ( 'Missing new password' ) ;
] ) ;
}
if ( ! req . body . newpasswordconfirm || req . body . newpasswordconfirm . length <= 0 ) {
errors . push ( 'Missing new password confirmation' ) ;
}
//check too long
if ( req . body . username && req . body . username . length > 50 ) {
errors . push ( 'Username must be 50 characters or less' ) ;
}
if ( req . body . password && req . body . password . length > 100 ) {
errors . push ( 'Password must be 100 characters or less' ) ;
}
if ( req . body . newpassword && req . body . newpassword . length > 100 ) {
errors . push ( 'Password must be 100 characters or less' ) ;
}
if ( req . body . newpasswordconfirm && req . body . newpasswordconfirm . length > 100 ) {
errors . push ( 'Password confirmation must be 100 characters or less' ) ;
}
if ( req . body . newpassword != req . body . newpasswordconfirm ) {
errors . push ( 'New password and password confirmation must match' ) ;
}
if ( errors . length > 0 ) {
if ( errors . length > 0 ) {
return dynamicResponse ( req , res , 400 , 'message' , {
return dynamicResponse ( req , res , 400 , 'message' , {