Created
October 23, 2018 19:04
-
-
Save swat-cat/358f7bca9a2c78b3671f98af0918adcc 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
| import 'dart:async'; | |
| import 'package:redux/redux.dart'; | |
| import 'package:reduxsample/models/auth_request.dart'; | |
| import 'package:reduxsample/models/loading_status.dart'; | |
| import 'package:reduxsample/redux/app/app_state.dart'; | |
| import 'package:reduxsample/redux/auth/auth_actions.dart'; | |
| import 'package:reduxsample/redux/auth/screen.dart'; | |
| import 'package:reduxsample/utils/strings.dart'; | |
| 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 ValidatePasswordAction){ | |
| validatePassword(action.screen,action.password, next); | |
| } | |
| if(action is ValidatePasswordMatchAction){ | |
| validatePassMatch(action.screen,action.password, action.confirmPassword, next); | |
| } | |
| ... | |
| next(action); | |
| } | |
| void validatePassMatch(Screen screen, String password, String confirmPassword, NextDispatcher next) { | |
| if(password != confirmPassword){ | |
| next(new RetypePasswordErrorAction(password_match_error,screen)); | |
| }else{ | |
| next(new RetypePasswordErrorAction("",screen)); | |
| } | |
| } | |
| void validatePassword(Screen screen, String password, NextDispatcher next) { | |
| if(password.length<6){ | |
| next(new PasswordErrorAction(password_error,screen)); | |
| }else{ | |
| next(new PasswordErrorAction("",screen)); | |
| } | |
| } | |
| void validateEmail(Screen screen, String email, NextDispatcher next) { | |
| RegExp exp = new RegExp(emailPattern); | |
| if(!exp.hasMatch(email)){ | |
| next(new EmailErrorAction(email_error,screen)); | |
| }else{ | |
| next(new EmailErrorAction("",screen)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment