Created
October 25, 2018 18:10
-
-
Save swat-cat/57fa235ea317e2df55f9f3622a5ba584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ValidationMiddleware extends MiddlewareClass<AppState>{ | |
| final String emailPattern = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'; | |
| @override | |
| void call(Store<AppState> store, dynamic action, NextDispatcher next) { | |
| if(action is ValidateEmailAction){ | |
| validateEmail(action.screen,action.email, next); | |
| } | |
| ... | |
| if(action is ValidateLoginFields){ | |
| validateEmail(Screen.SIGNIN,action.email, next); | |
| validatePassword(Screen.SIGNIN,action.password, next); | |
| RegExp exp = new RegExp(emailPattern); | |
| if(!exp.hasMatch(action.email) || action.password.length<6){ | |
| next(ChangeLoadingStatusAction(LoadingStatus.error)); | |
| }else{ | |
| next(new SignInAction(new AuthRequest(action.email,action.password))); | |
| } | |
| } | |
| ... | |
| next(action); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment