Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def registrationData = request.JSON
  2. List errors = []
  3.  
  4. if (!registrationData.email) {
  5. errors.add('email')
  6. }
  7.  
  8. if (User.countByUsername(registrationData.email) > 0) {
  9. errors.add('duplicate')
  10. }
  11.  
  12. if (!registrationData.password) {
  13. errors.add('passwordMissing')
  14. } else if (registrationData.password.size() < 8) {
  15. errors.add('passwordLength')
  16. }
  17.  
  18. if (!registrationData.password2) {
  19. errors.add('passwordMatchMissing')
  20. } else if (registrationData.password != registrationData.password2) {
  21. errors.add('passwordMatchFailed')
  22. }
  23. Boolean containsNumberAndLetter = (registrationData.password =~ /\p{Alpha}/) &&
  24. (registrationData.password =~ /\p{Digit}/)
  25. if(!containsNumberAndLetter) {
  26. errors.add('passwordContent')
  27. }
  28.  
  29. if (errors){
  30. response.setStatus(SC_PRECONDITION_FAILED)
  31. render errors as JSON
  32. return
  33. }
  34.  
  35.  
  36. User user = new User()
  37. user.username = registrationData.email
  38. user.password = registrationData.password
  39. user.enabled = true
  40. user.save(failOnError: true)
  41.  
  42. response.setStatus(SC_CREATED)
  43. render [userId: user.id] as JSON
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement