mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add prototype of login/register
This commit is contained in:
parent
a156d9b2f7
commit
4969473821
|
@ -22,6 +22,8 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* The main application class.
|
||||
|
@ -42,14 +44,23 @@ public class Application {
|
|||
static class WebSecurityConfiguration {
|
||||
|
||||
@Bean
|
||||
SecurityFilterChain videoShopSecurity(HttpSecurity http) throws Exception {
|
||||
SecurityFilterChain WebSecurity(HttpSecurity http) throws Exception {
|
||||
|
||||
return http
|
||||
.headers(headers -> headers.frameOptions(FrameOptionsConfig::sameOrigin))
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.formLogin(login -> login.loginProcessingUrl("/login"))
|
||||
.formLogin(login -> login.loginPage("/login").loginProcessingUrl("/login"))
|
||||
.logout(logout -> logout.logoutUrl("/logout").logoutSuccessUrl("/"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class WebConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login").setViewName("login");
|
||||
registry.addViewController("/").setViewName("index");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
src/main/java/catering/customer/CustomerController.java
Normal file
35
src/main/java/catering/customer/CustomerController.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package catering.customer;
|
||||
|
||||
import org.salespointframework.useraccount.Password;
|
||||
import org.salespointframework.useraccount.UserAccountManagement;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class CustomerController {
|
||||
|
||||
UserAccountManagement userAccountManagement;
|
||||
CustomerController(UserAccountManagement userAccountManagement) {
|
||||
|
||||
this.userAccountManagement = userAccountManagement;
|
||||
}
|
||||
|
||||
@GetMapping("/register")
|
||||
String register() {
|
||||
return "register";
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
public String loginPage(){
|
||||
|
||||
return "login";
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
String register(@RequestParam String username, @RequestParam String password) {
|
||||
userAccountManagement.create(username, Password.UnencryptedPassword.of(password));
|
||||
return "redirect:/";
|
||||
}
|
||||
}
|
32
src/main/java/catering/customer/RegistrationForm.java
Normal file
32
src/main/java/catering/customer/RegistrationForm.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package catering.customer;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import org.springframework.validation.Errors;
|
||||
|
||||
public class RegistrationForm {
|
||||
|
||||
private final @NotEmpty String name, password, address;
|
||||
|
||||
public RegistrationForm(String name, String password, String address) {
|
||||
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void validate(Errors errors) {
|
||||
|
||||
}
|
||||
}
|
69
src/main/resources/templates/login.html
Normal file
69
src/main/resources/templates/login.html
Normal file
|
@ -0,0 +1,69 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<h1>Login</h1>
|
||||
|
||||
<!-- FIXME no inline styles -->
|
||||
|
||||
<style>
|
||||
|
||||
form#login {
|
||||
|
||||
display: flex;
|
||||
|
||||
flex-direction: column;
|
||||
|
||||
gap: 1em;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
form#login > div {
|
||||
|
||||
display: flex;
|
||||
|
||||
flex-direction: column;
|
||||
|
||||
gap: .5em;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
form#login > div > * {
|
||||
|
||||
display: flex;
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<form class="ui form" role="form" th:action="@{/login}" method="post">
|
||||
|
||||
<div class="field">
|
||||
|
||||
<label for="username">Nutzername</label>
|
||||
|
||||
<input class="form-control" type="text" id="username" name="username" autofocus="autofocus" placeholder="Username">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
<label for="password">Passwort</label>
|
||||
|
||||
<input type="password" id="password" name="password" placeholder="Password">
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<button type="submit" class="ui button">Login</button>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<p>Haben Sie noch keinen Account? Registrieren Sie sich <a th:href="@{/register}">hier</a>.</p>
|
||||
|
||||
</html>
|
40
src/main/resources/templates/register.html
Normal file
40
src/main/resources/templates/register.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<h1>Registrierung</h1>
|
||||
|
||||
<form method="post" role="form" class="ui form" id="form" th:action="@{/register}">
|
||||
|
||||
<div class="field">
|
||||
|
||||
<label for="username">Nutzername</label>
|
||||
|
||||
<input id="username" name="username" type="text" required="required">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
<label for="password">Passwort</label>
|
||||
|
||||
<input id="password" name="password" type="password"
|
||||
required="required">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
<label for="address">Adresse</label>
|
||||
|
||||
<input id="address" name="address" type="text"><!-- FIXME: Address should be required!-->
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<button type="submit" class="ui button">Registrieren</button>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue