add oauth2 google
parent
71448364d7
commit
ac55481bc6
@ -1,120 +0,0 @@
|
|||||||
package ru.ulstu.core.controller;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.validation.FieldError;
|
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import ru.ulstu.core.error.EntityIdIsNullException;
|
|
||||||
import ru.ulstu.core.model.ErrorConstants;
|
|
||||||
import ru.ulstu.core.model.response.Response;
|
|
||||||
import ru.ulstu.core.model.response.ResponseExtended;
|
|
||||||
import ru.ulstu.user.error.UserActivationError;
|
|
||||||
import ru.ulstu.user.error.UserEmailExistsException;
|
|
||||||
import ru.ulstu.user.error.UserIdExistsException;
|
|
||||||
import ru.ulstu.user.error.UserIsUndeadException;
|
|
||||||
import ru.ulstu.user.error.UserLoginExistsException;
|
|
||||||
import ru.ulstu.user.error.UserNotActivatedException;
|
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
|
||||||
import ru.ulstu.user.error.UserSendingMailException;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@ControllerAdvice
|
|
||||||
public class AdviceController {
|
|
||||||
private final Logger log = LoggerFactory.getLogger(AdviceController.class);
|
|
||||||
private final UserService userService;
|
|
||||||
|
|
||||||
public AdviceController(UserService userService) {
|
|
||||||
this.userService = userService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModelAttribute("currentUser")
|
|
||||||
public String getCurrentUser() {
|
|
||||||
return userService.getCurrentUser().getUserAbbreviate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModelAttribute("flashMessage")
|
|
||||||
public String getFlashMessage() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Response<Void> handleException(ErrorConstants error) {
|
|
||||||
log.warn(error.toString());
|
|
||||||
return new Response<>(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <E> ResponseExtended<E> handleException(ErrorConstants error, E errorData) {
|
|
||||||
log.warn(error.toString());
|
|
||||||
return new ResponseExtended<>(error, errorData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(EntityIdIsNullException.class)
|
|
||||||
public Response<Void> handleEntityIdIsNullException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.ID_IS_NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
||||||
public ResponseExtended<Set<String>> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
||||||
final Set<String> errors = e.getBindingResult().getAllErrors().stream()
|
|
||||||
.filter(error -> error instanceof FieldError)
|
|
||||||
.map(error -> ((FieldError) error).getField())
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
return handleException(ErrorConstants.VALIDATION_ERROR, errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserIdExistsException.class)
|
|
||||||
public Response<Void> handleUserIdExistsException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_ID_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserActivationError.class)
|
|
||||||
public ResponseExtended<String> handleUserActivationError(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_ACTIVATION_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserLoginExistsException.class)
|
|
||||||
public ResponseExtended<String> handleUserLoginExistsException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_LOGIN_EXISTS, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserEmailExistsException.class)
|
|
||||||
public ResponseExtended<String> handleUserEmailExistsException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_EMAIL_EXISTS, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserPasswordsNotValidOrNotMatchException.class)
|
|
||||||
public Response<Void> handleUserPasswordsNotValidOrNotMatchException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ExceptionHandler(UserNotFoundException.class)
|
|
||||||
// public ResponseExtended<String> handleUserNotFoundException(Throwable e) {
|
|
||||||
// return handleException(ErrorConstants.USER_NOT_FOUND, e.getMessage());
|
|
||||||
// }
|
|
||||||
|
|
||||||
@ExceptionHandler(UserNotActivatedException.class)
|
|
||||||
public Response<Void> handleUserNotActivatedException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_NOT_ACTIVATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserResetKeyError.class)
|
|
||||||
public ResponseExtended<String> handleUserResetKeyError(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_RESET_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserIsUndeadException.class)
|
|
||||||
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(UserSendingMailException.class)
|
|
||||||
public ResponseExtended<String> handleUserSendingMailException(Throwable e) {
|
|
||||||
return handleException(ErrorConstants.USER_SENDING_MAIL_EXCEPTION, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package ru.ulstu.index.controller;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.ModelMap;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import ru.ulstu.core.controller.AdviceController;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
@RequestMapping(value = "/index")
|
|
||||||
@ApiIgnore
|
|
||||||
public class IndexController extends AdviceController {
|
|
||||||
public IndexController(UserService userService) {
|
|
||||||
super(userService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public void currentUser(ModelMap modelMap) {
|
|
||||||
//нужен здесь для добавления параметров на стартовой странице
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||||
|
<title>Oauth2 Login</title>
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="col-sm-3 well">
|
||||||
|
<h3>Login with:</h3>
|
||||||
|
<div class="list-group">
|
||||||
|
<p th:each="url : ${urls}">
|
||||||
|
<a th:text="${url.key}" th:href="${url.value}" class="list-group-item active">Client</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue