-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from GEdO23/dev
Usuario (1)
- Loading branch information
Showing
16 changed files
with
142 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/br/com/cpsb/controller/UsuarioController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package br.com.cpsb.controller; | ||
|
||
import br.com.cpsb.model.Usuario; | ||
import br.com.cpsb.repository.UsuarioRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.util.Optional; | ||
|
||
@Controller | ||
public class UsuarioController { | ||
|
||
@Autowired | ||
private UsuarioRepository usuarioRepository; | ||
|
||
@GetMapping("/login") | ||
public ModelAndView login() { | ||
ModelAndView mv = new ModelAndView("formulario_login_usuario"); | ||
|
||
mv.addObject("usuario", new Usuario()); | ||
|
||
return mv; | ||
} | ||
|
||
@PostMapping("/login") | ||
public ModelAndView logar(Usuario usuario) { | ||
|
||
Optional<Usuario> usuarioEncontrado = usuarioRepository.findAll().stream().filter(u -> | ||
u.getNome().equals(usuario.getNome()) | ||
).findFirst(); | ||
|
||
if (usuarioEncontrado.isPresent()) { | ||
return new ModelAndView("redirect:/"); | ||
} else { | ||
ModelAndView mv = new ModelAndView("/formulario_login_usuario"); | ||
mv.addObject("usuario", new Usuario()); | ||
return mv; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package br.com.cpsb.model; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@Table(name = "TB_CPSB_USUARIO") | ||
public class Usuario { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id_usuario") | ||
private Long id; | ||
|
||
@Column(name = "nm_usuario") | ||
private String nome; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package br.com.cpsb.repository; | ||
|
||
import br.com.cpsb.model.Usuario; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UsuarioRepository extends JpaRepository<Usuario, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/resources/templates/formulario_login_usuario.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> | ||
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | ||
<head th:replace="~{fragmentos :: cabecalho('Login')}"></head> | ||
<body> | ||
|
||
<div class="container mt-5"> | ||
<div class="row"> | ||
<h1>Cutcute Petshop</h1> | ||
</div> | ||
|
||
<div class="row"> | ||
<h2>Login</h2> | ||
</div> | ||
|
||
<div class="row"> | ||
<form th:action="@{/login}" method="post" th:object="${usuario}"> | ||
|
||
<div class="form-group"> | ||
<label for="nome">Nome</label> | ||
<input class="form-control" type="text" id="nome" th:field="*{nome}"> | ||
</div> | ||
|
||
<button class="btn btn-primary mt-4" type="submit">Entrar</button> | ||
|
||
</form> | ||
</div> | ||
|
||
</div> | ||
|
||
<!-- Option 1: Bootstrap Bundle with Popper --> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" | ||
crossorigin="anonymous"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<head th:fragment="cabecalho(parametro)"> | ||
|
||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-- Bootstrap CSS --> | ||
<link | ||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" | ||
rel="stylesheet" | ||
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" | ||
crossorigin="anonymous"> | ||
|
||
<title th:text="${parametro}">AQUI!</title> | ||
|
||
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters