11"use strict" ;
22
3- const { Rule, LinValidator } = require ( "lin-mizar" ) ;
4- const { extendedValidator } = require ( "lin-mizar/lin/extended-validator" ) ;
3+ const { Rule, LinValidator, isNotEmpty } = require ( "lin-mizar" ) ;
54const { PaginateValidator, PositiveIdValidator } = require ( "./common" ) ;
65
76class AdminUsersValidator extends PaginateValidator {
@@ -22,17 +21,19 @@ class ResetPasswordValidator extends PositiveIdValidator {
2221 "密码长度必须在6~22位之间,包含字符、数字和 _ " ,
2322 / ^ [ A - Z a - z 0 - 9 _ * & $ # @ ] { 6 , 22 } $ /
2423 ) ;
25- this . confirm_password = new Rule (
26- this . passwordCheck . bind ( this ) ,
27- "两次输入密码不一致"
28- ) ;
24+ this . confirm_password = new Rule ( "isNotEmpty" , "确认密码不可为空" ) ;
2925 }
3026
31- passwordCheck ( val ) {
32- if ( ! this . data . body . new_password || ! this . data . body . confirm_password ) {
33- return false ;
27+ validateConfirmPassword ( data ) {
28+ if ( ! data . body . new_password || ! data . body . confirm_password ) {
29+ return [ false , "两次输入的密码不一致,请重新输入" ] ;
30+ }
31+ let ok = data . body . new_password === data . body . confirm_password ;
32+ if ( ok ) {
33+ return ok ;
34+ } else {
35+ return [ false , "两次输入的密码不一致,请重新输入" ] ;
3436 }
35- return this . data . body . new_password === this . data . body . confirm_password ;
3637 }
3738}
3839
@@ -58,15 +59,17 @@ class RemoveAuthsValidator extends LinValidator {
5859 constructor ( ) {
5960 super ( ) ;
6061 this . group_id = new Rule ( "isInt" , "分组id必须正整数" ) ;
61- this . auths = new Rule ( this . checkAuths , "请输入auths字段" ) ;
62+ this . auths = new Rule ( "isNotEmpty" , "请输入auths字段" ) ;
6263 }
63- checkAuths ( auths ) {
64+
65+ validateAuths ( data ) {
66+ const auths = data . body . auths ;
6467 if ( ! Array . isArray ( auths ) ) {
65- return false ;
68+ return [ false , "auths必须为非空数组" ] ;
6669 }
67- for ( const auth in auths ) {
68- if ( ! extendedValidator . isNotEmpty ( auth ) ) {
69- return false ;
70+ for ( const auth of auths ) {
71+ if ( ! isNotEmpty ( auth ) ) {
72+ return [ false , "auths必须为非空数组" ] ;
7073 }
7174 }
7275 return true ;
@@ -77,16 +80,17 @@ class DispatchAuthsValidator extends LinValidator {
7780 constructor ( ) {
7881 super ( ) ;
7982 this . group_id = new Rule ( "isInt" , "分组id必须正整数" ) ;
80- this . auths = new Rule ( this . checkAuths , "请输入auths字段" ) ;
83+ this . auths = new Rule ( "isNotEmpty" , "请输入auths字段" ) ;
8184 }
8285
83- checkAuths ( auths ) {
86+ validateAuths ( data ) {
87+ const auths = data . body . auths ;
8488 if ( ! Array . isArray ( auths ) ) {
85- return false ;
89+ return [ false , "auths必须为非空数组" ] ;
8690 }
87- for ( const auth in auths ) {
88- if ( ! extendedValidator . isNotEmpty ( auth ) ) {
89- return false ;
91+ for ( const auth of auths ) {
92+ if ( ! isNotEmpty ( auth ) ) {
93+ return [ false , "auths必须为非空数组" ] ;
9094 }
9195 }
9296 return true ;
@@ -98,19 +102,17 @@ class NewGroupValidator extends LinValidator {
98102 super ( ) ;
99103 this . name = new Rule ( "isNotEmpty" , "请输入分组名称" ) ;
100104 this . info = new Rule ( "isOptional" ) ;
101- this . auths = new Rule ( this . checkAuths , "请输入auths字段" ) ;
105+ this . auths = new Rule ( "isNotEmpty" , "请输入auths字段" ) ;
102106 }
103107
104- checkAuths ( auths ) {
108+ validateAuths ( data ) {
109+ const auths = data . body . auths ;
105110 if ( ! Array . isArray ( auths ) ) {
106- return false ;
107- }
108- if ( auths . length === 0 ) {
109- return true ;
111+ return [ false , "auths必须为非空数组" ] ;
110112 }
111- for ( const auth in auths ) {
112- if ( ! extendedValidator . isNotEmpty ( auth ) ) {
113- return false ;
113+ for ( const auth of auths ) {
114+ if ( ! isNotEmpty ( auth ) ) {
115+ return [ false , "auths必须为非空数组" ] ;
114116 }
115117 }
116118 return true ;
0 commit comments