diff options
| author | realtradam <[email protected]> | 2024-07-23 20:47:31 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-07-23 20:47:31 -0400 |
| commit | 1e18e0ad7a47536be92384bbf815e0923a06698d (patch) | |
| tree | b07405ecdef4f05a96b6c4348930cbee976554cb /src/main/java/com/blog/web/controllers/AuthController.java | |
| parent | 56c59e3b98fe554c4e1484e208e4be5c30f09a04 (diff) | |
| download | spring-blog-1e18e0ad7a47536be92384bbf815e0923a06698d.tar.gz spring-blog-1e18e0ad7a47536be92384bbf815e0923a06698d.zip | |
split front and back end, add react to project
Diffstat (limited to 'src/main/java/com/blog/web/controllers/AuthController.java')
| -rw-r--r-- | src/main/java/com/blog/web/controllers/AuthController.java | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/main/java/com/blog/web/controllers/AuthController.java b/src/main/java/com/blog/web/controllers/AuthController.java deleted file mode 100644 index efb3672..0000000 --- a/src/main/java/com/blog/web/controllers/AuthController.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.blog.web.controllers; - -import com.blog.web.dto.RegistrationDto; -import com.blog.web.models.UserEntity; -import com.blog.web.services.UserService; -import jakarta.validation.Valid; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; - -@Controller -public class AuthController { - private final UserService userService; - - public AuthController(UserService userService) { - this.userService = userService; - } - - @GetMapping("/userlogin") - public String login(Model model) { - final UserEntity user = userService.getLoggedInUser().orElse(new UserEntity()); - model.addAttribute("user", user); - return "auth/login"; - } - - @GetMapping("/register") - public String getRegisterForm(Model model) { - final RegistrationDto user = new RegistrationDto(); - model.addAttribute("user", user); - return "auth/register"; - } - - @PostMapping("/register/save") - public String register(@Valid @ModelAttribute("user") RegistrationDto user, BindingResult result, Model model) { - UserEntity existingUserEmail = userService.findByEmail(user.getEmail()).orElse(null); - if (existingUserEmail != null && StringUtils.isBlank(existingUserEmail.getEmail())) { - result.rejectValue("email", "There is already a user with this email"); - } - - UserEntity existingUsername = userService.findByUsername(user.getUsername()).orElse(null); - if (existingUsername != null && StringUtils.isBlank(existingUsername.getUsername())) { - result.rejectValue("username", "There is already a user with this username"); - } - - if (result.hasErrors()) { - model.addAttribute("user", user); - return "register"; - } - userService.saveUser(user); - return "redirect:/articles?success"; - } -} |
