42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
package com.ieslamar.GestionInventario.controllers;
|
|
|
|
|
|
import com.ieslamar.GestionInventario.Services.UserService;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
@Controller
|
|
public class UserController {
|
|
|
|
private final UserService userService;
|
|
|
|
public UserController(UserService userService) {
|
|
this.userService = userService;
|
|
}
|
|
|
|
@GetMapping("/login")
|
|
public String loginPage() {
|
|
return "login"; // Retorna la vista login.html
|
|
}
|
|
|
|
@GetMapping("/home")
|
|
public String homePage(Model model) {
|
|
model.addAttribute("message", "Bienvenido a Gestión de Inventario");
|
|
return "home"; // Retorna la vista home.html
|
|
}
|
|
|
|
@GetMapping("/register")
|
|
public String registerPage() {
|
|
return "register"; // Retorna la vista register.html
|
|
}
|
|
|
|
@PostMapping("/register")
|
|
public String register(@RequestParam String username, @RequestParam String password, @RequestParam String role) {
|
|
userService.registerUser(username, password, role);
|
|
return "redirect:/login?success"; // Redirige al login tras registrarse
|
|
}
|
|
}
|