Sunday, August 16, 2015

UserLoginValidator validator

1:31 AM

package com.education.vidyarthi.online.validator;

import java.util.List;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.education.vidyarthi.online.model.User;
import com.education.vidyarthi.online.service.UserService;

@Component("userLoginValidator")
public class UserLoginValidator {
    @Autowired
    private UserService userService;

    public boolean supports(Class<?> klass) {
        return User.class.isAssignableFrom(klass);
    }

    public void validate(Object target, Errors errors) {
        User user = (User) target;
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userEmail",
                "NotEmpty.user.userEmail", "User Email must not be Empty.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
                "NotEmpty.user.password", "Password must not be Empty.");

        if ((user.getUserEmail() != null) && (user.getUserEmail().length() > 0)) {
            user.setUserEmail(user.getUserEmail().trim());
            List userlist = userService.validateLoginUser(user.getUserEmail(),(user.getPassword())
                    );
            if ((userlist != null) && (userlist.size() > 0)) {
            } else {
                errors.rejectValue("userEmail",
                        "notMatchEmailAndPassword.user.userEmail",
                        "User Email or Password you entered is incorrect.");
            }

        }

    }


}

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 Java Tutorials. All rights resevered. Designed by Templateism

Back To Top