Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def registrationData = request.JSON
- List errors = []
- if (!registrationData.email) {
- errors.add('email')
- }
- if (User.countByUsername(registrationData.email) > 0) {
- errors.add('duplicate')
- }
- if (!registrationData.password) {
- errors.add('passwordMissing')
- } else if (registrationData.password.size() < 8) {
- errors.add('passwordLength')
- }
- if (!registrationData.password2) {
- errors.add('passwordMatchMissing')
- } else if (registrationData.password != registrationData.password2) {
- errors.add('passwordMatchFailed')
- }
- Boolean containsNumberAndLetter = (registrationData.password =~ /\p{Alpha}/) &&
- (registrationData.password =~ /\p{Digit}/)
- if(!containsNumberAndLetter) {
- errors.add('passwordContent')
- }
- if (errors){
- response.setStatus(SC_PRECONDITION_FAILED)
- render errors as JSON
- return
- }
- User user = new User()
- user.username = registrationData.email
- user.password = registrationData.password
- user.enabled = true
- user.save(failOnError: true)
- response.setStatus(SC_CREATED)
- render [userId: user.id] as JSON
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement