Merge remote-tracking branch 'origin/html-gruppe' into html-gruppe
# Conflicts: # src/main/java/mops/gruppen2/controllers/Gruppen2Controller.java
This commit is contained in:
@ -1,24 +1,36 @@
|
||||
package mops.gruppen2.controllers;
|
||||
|
||||
import mops.gruppen2.services.KeyCloakService;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
|
||||
import mops.gruppen2.entities.Gruppe;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.keycloak.KeycloakPrincipal;
|
||||
import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.context.annotation.SessionScope;
|
||||
|
||||
@SessionScope
|
||||
@Controller
|
||||
@RequestMapping("/gruppen2")
|
||||
public class Gruppen2Controller {
|
||||
|
||||
private final KeyCloakService keyCloakService;
|
||||
|
||||
public Gruppen2Controller(KeyCloakService keyCloakService) {
|
||||
this.keyCloakService = keyCloakService;
|
||||
/**
|
||||
* Creates an Account.
|
||||
*
|
||||
* @param token Ein toller token
|
||||
* @return Account with current userdata
|
||||
*/
|
||||
private Account createAccountFromPrincipal(KeycloakAuthenticationToken token) {
|
||||
KeycloakPrincipal principal = (KeycloakPrincipal) token.getPrincipal();
|
||||
return new Account(
|
||||
principal.getName(),
|
||||
principal.getKeycloakSecurityContext().getIdToken().getEmail(),
|
||||
null,
|
||||
principal.getKeycloakSecurityContext().getIdToken().getGivenName(),
|
||||
principal.getKeycloakSecurityContext().getIdToken().getFamilyName(),
|
||||
token.getAccount().getRoles());
|
||||
}
|
||||
|
||||
/**Zeigt die index.html an.
|
||||
@ -27,10 +39,26 @@ public class Gruppen2Controller {
|
||||
* @param model tolles model
|
||||
* @return index.html
|
||||
*/
|
||||
@GetMapping("/")
|
||||
@RolesAllowed({"ROLE_orga", "ROLE_studentin", "ROLE_actuator)"})
|
||||
@GetMapping("")
|
||||
public String index(KeycloakAuthenticationToken token, Model model) {
|
||||
model.addAttribute("account", keyCloakService.createAccountFromPrincipal(token));
|
||||
model.addAttribute("account", createAccountFromPrincipal(token));
|
||||
return "index";
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public String addGruppe(@ModelAttribute Gruppe gruppe) {
|
||||
System.out.println(gruppe);
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
@GetMapping("/createGroup")
|
||||
public String createGruppe(){
|
||||
return "create";
|
||||
}
|
||||
|
||||
@GetMapping("/findGroup")
|
||||
public String findGruppe(){
|
||||
return "search";
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,34 +25,7 @@
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Titel</th>
|
||||
<th scope="col">Beschreibung</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Titel1</td>
|
||||
<td>Beschreibung1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Titel2</th>
|
||||
<td>Beschreibung2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Titel3</td>
|
||||
<td>Beschreibung3</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -25,26 +25,7 @@
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 rounded-sm text-center m-0">
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/">
|
||||
<div class="form-group">
|
||||
<label>Titel der Gruppe</label>
|
||||
<input class="form-control" type="text" th:value="${titel}" name="titel" placeholder="Titel der Gruppe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Beschreibung der Gruppe</label>
|
||||
<input class="form-control" type="text" th:value="${beschreibung}" name="beschreibung" placeholder="Beschreibung der Gruppe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-outline-dark">weiter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -25,7 +25,26 @@
|
||||
</nav>
|
||||
</header>
|
||||
<main th:fragment="bodycontent">
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-sm-8 ">
|
||||
<h1>Gruppenerstellung</h1>
|
||||
<form method="post" action="/">
|
||||
<div class="form-group">
|
||||
<label>Titel der Gruppe</label>
|
||||
<input class="form-control" type="text" th:value="${titel}" name="titel" placeholder="Titel der Gruppe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Beschreibung der Gruppe</label>
|
||||
<input class="form-control" type="text" th:value="${beschreibung}" name="beschreibung" placeholder="Beschreibung der Gruppe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-outline-dark">weiter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user