Commit 367f05cb by jhrabal

BT

parent f53f7c16
......@@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.logging.ErrorManager;
import javax.servlet.http.HttpSession;
......@@ -113,20 +114,20 @@ public class AuthApiController {
throw new BadRequestException();
}
List<AuthError> errors = new ArrayList<>();
List<ErrorMessage> errors = new ArrayList<>();
//TODO validate email
if (!StringUtils.hasText(signup.getLogin())) {
errors.add(new AuthError("username", "BadUsername"));
errors.add(ErrorMessage.withFieldCode("username", "AUTH.BAD_USERNAME"));
}
if (!PasswordUtils.validatePassword(signup.getPassword())) {
errors.add(new AuthError("password", "BadPassword"));
errors.add(ErrorMessage.withFieldCode("password", "AUTH.BAD_PASSWORD"));
}
if (!errors.isEmpty()) {
// throw new BadRequestException(errors);
throw new BadRequestException();
throw new RestApiException(HttpStatus.BAD_REQUEST, errors);
// throw new BadRequestException();
}
try {
......@@ -136,10 +137,14 @@ public class AuthApiController {
} catch (Exception e) {
e.printStackTrace();
errors.add(new AuthError(null, e.getMessage()));
errors.add(ErrorMessage.withMessage(e.getMessage()));
}
return new LoginResponse("Authorization", "Basic " + Base64.getEncoder().encodeToString((signup.getLogin() + ":" + signup.getPassword()).getBytes()));
if (errors.isEmpty()) {
return new LoginResponse("Authorization", "Basic " + Base64.getEncoder().encodeToString((signup.getLogin() + ":" + signup.getPassword()).getBytes()));
}
throw new RestApiException(HttpStatus.BAD_REQUEST, errors);
}
......@@ -165,7 +170,7 @@ public class AuthApiController {
return new ResponseEntity<>(Collections.singletonList(new AuthError(null, "NO_TOKEN")), HttpStatus.BAD_REQUEST);
}
List<AuthError> errors = new ArrayList<>();
List<ErrorMessage> errors = new ArrayList<>();
try {
authService.resetPassword(resetPassword.getLogin(), resetPassword.getToken(), resetPassword.getPassword());
......@@ -177,7 +182,7 @@ public class AuthApiController {
// }
} catch (Exception e) {
e.printStackTrace();
errors.add(new AuthError(null, e.getMessage()));
errors.add(ErrorMessage.withMessage(e.getMessage()));
}
if (errors.isEmpty()) {
......@@ -185,7 +190,7 @@ public class AuthApiController {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
throw new RestApiException(HttpStatus.BAD_REQUEST, errors);
}
......
......@@ -110,7 +110,7 @@ public class ErrorMessage {
*/
public static ErrorMessage withCode(String code) {
ErrorMessage em = new ErrorMessage();
em.message = code;
em.code = code;
return em;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment