Skip to content
Snippets Groups Projects
Commit 072b58ff authored by BEAUVAIS ANTOINE's avatar BEAUVAIS ANTOINE
Browse files

Merge branch 'develop' into 'master'

Added sample login form. #4

See merge request !17
parents db8ab3c4 ef616c45
Branches
1 merge request!17Added sample login form. #4
Showing
with 213 additions and 9 deletions
...@@ -73,6 +73,11 @@ public class WebMvcConfig implements WebMvcConfigurer { ...@@ -73,6 +73,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
*/ */
public static final String MAPPING_LOGIN = "/login"; public static final String MAPPING_LOGIN = "/login";
/**
* Web mapping for the items list.
*/
public static final String WEB_MAPPING_ITEMS = "/products";
/** /**
* Adds interceptors to the application. * Adds interceptors to the application.
* *
......
...@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; ...@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
* @author BEAUVAIS ANTOINE * @author BEAUVAIS ANTOINE
*/ */
@RestControllerAdvice @RestControllerAdvice
public class ApiErrorHandler { public class ApiExceptionHandler {
/** /**
* Handler for HTTP 500 Internal Server Error. * Handler for HTTP 500 Internal Server Error.
......
...@@ -5,8 +5,13 @@ ...@@ -5,8 +5,13 @@
package fr.unistra.sil.erp.back.controller.web; package fr.unistra.sil.erp.back.controller.web;
import static fr.unistra.sil.erp.back.WebMvcConfig.MAPPING_LOGIN; import static fr.unistra.sil.erp.back.WebMvcConfig.MAPPING_LOGIN;
import static fr.unistra.sil.erp.back.WebMvcConfig.WEB_MAPPING_ITEMS;
import fr.unistra.sil.erp.back.model.LoginForm;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
/** /**
* Controller for the Web login interface. * Controller for the Web login interface.
...@@ -20,15 +25,34 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -20,15 +25,34 @@ import org.springframework.web.bind.annotation.GetMapping;
public class LoginController { public class LoginController {
/** /**
* Logic for handling login. * Logic for serving the login page.
* *
* TODO: Actual implementation. * This method defines how to serve the login page.
*
* @param model Spring Model.
* @return the name of the template to use. * @return the name of the template to use.
*/ */
@GetMapping(MAPPING_LOGIN) @GetMapping(MAPPING_LOGIN)
public String login() public String login(Model model)
{ {
model.addAttribute("login", new LoginForm());
return "login"; return "login";
} }
/**
* Login for handling the login process.
*
* This method actually processes the user-submitted form for login.
*
* TODO: Actual implementation.
*
* @param loginForm
* @throws WebMovedPermanentlyException Post-login redirection.
*/
@PostMapping(MAPPING_LOGIN)
public void handleLogin(@ModelAttribute("login") LoginForm loginForm)
throws WebMovedPermanentlyException
{
throw new WebMovedPermanentlyException(WEB_MAPPING_ITEMS);
}
} }
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.view.RedirectView;
/**
* Handles exceptions for the Web frontend.
* @author BEAUVAIS ANTOINE
*/
@ControllerAdvice
public class WebExceptionHandler {
/**
* Handler for redirections.
* @param ex the thrown exception that triggered the redirection.
* @param request Spring Request Servlet.
* @param response Spring Response Servlet.
* @return the Spring RedirectView.
*/
@ExceptionHandler(WebMovedPermanentlyException.class)
public RedirectView handleMovedPermanently(Exception ex,
HttpServletRequest request, HttpServletResponse response) {
return new RedirectView(ex.getMessage(), false, true, false);
}
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller.web;
/**
* Web Controller for redirecting the user to another page.
*
* If a controller wants to take the user to another page,
* it can use this exception to do so.
*
* @author BEAUVAIS ANTOINE
*/
public class WebMovedPermanentlyException extends Exception {
/**
* Class constructor.
* @param string the URL to redirect to.
*/
public WebMovedPermanentlyException(String string)
{
super(string);
}
}
package fr.unistra.sil.erp.back.controller.web;
import static fr.unistra.sil.erp.back.WebMvcConfig.WEB_MAPPING_ITEMS;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
/**
* Web Controller for the item list.
* @author BEAUVAIS ANTOINE
*/
@Controller
public class WebProductsController {
/**
* Handles the item list view.
* @return the template to use.
*/
@GetMapping(WEB_MAPPING_ITEMS)
public String products()
{
return "items";
}
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.model;
/**
* Login form model.
* @author BEAUVAIS ANTOINE
*/
public class LoginForm {
/**
* User-submitted username.
*/
private String username;
/**
* User-submitted password.
*/
private String password;
/**
* Class constructor.
*/
public LoginForm()
{
}
/**
* Returns the username.
* @return the username.
*/
public String getUsername()
{
return this.username;
}
/**
* Returns the password.
* @return the password.
*/
public String getPassword()
{
return this.password;
}
/**
* Sets the username.
* @param username the username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
/**
* Sets the password.
* @param password the password to set.
*/
public void setPassword(String password)
{
this.password = password;
}
}
...@@ -15,4 +15,4 @@ web.ui.products=Products ...@@ -15,4 +15,4 @@ web.ui.products=Products
#Financial registry. #Financial registry.
web.ui.registry=Registry web.ui.registry=Registry
#Documents. #Documents.
web.ui.property.documents=Documents web.ui.documents=Documents
...@@ -15,4 +15,4 @@ web.ui.products=Products ...@@ -15,4 +15,4 @@ web.ui.products=Products
#Financial registry. #Financial registry.
web.ui.registry=Registry web.ui.registry=Registry
#Documents. #Documents.
web.ui.property.documents=Documents web.ui.documents=Documents
...@@ -15,4 +15,4 @@ web.ui.products=Produits ...@@ -15,4 +15,4 @@ web.ui.products=Produits
#Financial registry. #Financial registry.
web.ui.registry=Registre web.ui.registry=Registre
#Documents. #Documents.
web.ui.property.documents=Documents web.ui.documents=Documents
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head :: sharedHead (pageName=#{web.ui.products})">
</head>
<body>
<div th:replace="fragments/navbar :: topNavBar"></div>
<article>
<h1 th:text="#{web.ui.products}"></h1>
<p>TODO</p>
</article>
</body>
</html>
\ No newline at end of file
...@@ -5,7 +5,15 @@ ...@@ -5,7 +5,15 @@
<body> <body>
<div th:replace="fragments/navbarGuest :: topNavBar"></div> <div th:replace="fragments/navbarGuest :: topNavBar"></div>
<h1 th:text="#{web.ui.login.login}"></h1> <article>
<p>TODO</p> <h1 th:text="#{web.ui.login.login}"></h1>
<form method="POST" th:object="${login}">
<label for="username" th:text="#{web.ui.login.username}"></label>
<input type="text" th:id="username" th:field="*{username}">
<label for="password" th:text="#{web.ui.login.password}"></label>
<input type="password" th:id="password" th:field="*{password}">
<input type="submit" th:value="#{web.ui.login.submit}">
</form>
</article>
</body> </body>
</html> </html>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment