29 lines
962 B
Java
29 lines
962 B
Java
|
package stirling.software.SPDF.controller.api;
|
||
|
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||
|
import org.springframework.stereotype.Controller;
|
||
|
import org.springframework.ui.Model;
|
||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
||
|
import stirling.software.SPDF.config.security.UserService;
|
||
|
|
||
|
@Controller
|
||
|
public class UserController {
|
||
|
|
||
|
@Autowired
|
||
|
private UserService userService;
|
||
|
|
||
|
@PostMapping("/register")
|
||
|
public String register(@RequestParam String username, @RequestParam String password, Model model) {
|
||
|
if(userService.usernameExists(username)) {
|
||
|
model.addAttribute("error", "Username already exists");
|
||
|
return "register";
|
||
|
}
|
||
|
|
||
|
userService.saveUser(username, password);
|
||
|
return "redirect:/login?registered=true";
|
||
|
}
|
||
|
}
|