Skip to content

Instantly share code, notes, and snippets.

@swat-cat
Created October 25, 2018 18:10
Show Gist options
  • Select an option

  • Save swat-cat/57fa235ea317e2df55f9f3622a5ba584 to your computer and use it in GitHub Desktop.

Select an option

Save swat-cat/57fa235ea317e2df55f9f3622a5ba584 to your computer and use it in GitHub Desktop.
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