PageRenderTime 89ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/cyclingeventapplication/src/main/java/cs472/mum/service/UserService.java

https://bitbucket.org/danhuycao/cs472_mum
Java | 50 lines | 37 code | 12 blank | 1 comment | 4 complexity | e984a3e0ba036b607705676dd954575a MD5 | raw file
  1. // Did Oumar
  2. package cs472.mum.service;
  3. import cs472.mum.dao.UserDao;
  4. import cs472.mum.model.User;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9. public class UserService {
  10. private UserDao userdao = new UserDao() ;
  11. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  12. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  13. public long insertUser(User u )
  14. {
  15. return userdao.insert(u);
  16. }
  17. public List<User> findAll( )
  18. {
  19. return userdao.findAll();
  20. }
  21. public List<String> validateUser(User u) {
  22. List<String> result = new ArrayList<String>();
  23. if (u.getFname().isEmpty()) {
  24. result.add("First name required");
  25. }
  26. if (u.getLname().isEmpty()) {
  27. result.add("Last name required");
  28. }
  29. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(u.getEmail());
  30. if (u.getEmail().isEmpty()|| !matcher.find()) {
  31. result.add("email should have Email format");
  32. }
  33. if (u.getPassword().length() <4 ) {
  34. result.add("password must be more than 3 characters)");
  35. }
  36. return result;
  37. }
  38. }