Skip to content

Commit 07423a7

Browse files
committed
Elephant added! Index front and back
1 parent f9b23b2 commit 07423a7

File tree

9 files changed

+180
-17
lines changed

9 files changed

+180
-17
lines changed

src/main/java/ru/xpressed/javatemplatescoursework/config/SecurityConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7+
import org.springframework.security.config.annotation.web.builders.WebSecurity;
78
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
89
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
910
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -26,7 +27,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
2627
@Override
2728
protected void configure(HttpSecurity http) throws Exception {
2829
http
29-
.authorizeRequests().antMatchers("/login", "/logout", "/registration").permitAll()
30+
.authorizeRequests()
31+
.antMatchers("/login", "/logout", "/registration", "/icons/**", "/images/**", "/", "/home", "/index").permitAll()
3032
.anyRequest().authenticated()
3133

3234
.and().formLogin()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.xpressed.javatemplatescoursework.controller;
2+
3+
import org.springframework.boot.autoconfigure.web.servlet.error.AbstractErrorController;
4+
import org.springframework.boot.web.servlet.error.ErrorAttributes;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
8+
@Controller
9+
public class ErrorController extends AbstractErrorController {
10+
public ErrorController(ErrorAttributes errorAttributes) {
11+
super(errorAttributes);
12+
}
13+
14+
@GetMapping("/error")
15+
public String showErrorMessage() {
16+
return "error";
17+
}
18+
}
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
package ru.xpressed.javatemplatescoursework.controller;
22

3+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
34
import org.springframework.stereotype.Controller;
5+
import org.springframework.ui.Model;
46
import org.springframework.web.bind.annotation.GetMapping;
57

68
import javax.servlet.http.HttpServletRequest;
79

810
@Controller
911
public class IndexController {
10-
@GetMapping("/index")
11-
public String showIndexPage(HttpServletRequest request) {
12-
System.out.println(request.getUserPrincipal().getName());
12+
@GetMapping({"/index", "/", "/home"})
13+
public String showIndexPage(HttpServletRequest request, Model model) {
14+
if (request.getUserPrincipal() != null) {
15+
model.addAttribute("username", request.getUserPrincipal().getName());
16+
model.addAttribute("linkOutOrUp", "/logout");
17+
model.addAttribute("textOutOrUp", "LogOut");
18+
model.addAttribute("linkInOrAccount", "/account");
19+
model.addAttribute("textInOrAccount", "Account");
20+
}
21+
else {
22+
model.addAttribute("username", "Stranger?");
23+
model.addAttribute("linkOutOrUp", "/registration");
24+
model.addAttribute("textOutOrUp", "SignUp");
25+
model.addAttribute("linkInOrAccount", "/login");
26+
model.addAttribute("textInOrAccount", "LogIn");
27+
}
1328
return "index";
1429
}
1530
}

src/main/java/ru/xpressed/javatemplatescoursework/controller/RegistrationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public String completeRegistration(@Valid Customer customer, BindingResult bindi
4141
customer.setPassword(securityConfig.encoder().encode(customer.getPassword()));
4242
customerRepository.save(customer);
4343
model.addAttribute("message", "Registration Completed");
44-
model.addAttribute("onload", "redirect()");
44+
model.addAttribute("onload", "redirectTimer()");
4545
} else {
4646
bindingResult.rejectValue("username", "customer.username", "This username is already taken!");
4747
}
9.26 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
5+
<meta charset="UTF-8">
6+
<title>Error :(</title>
7+
<link rel="icon" th:href="@{/icons/elephant2.png}">
8+
</head>
9+
<body style="background-color: #dfdfe9;">
10+
<div class="mt-4 container-fluid">
11+
<div class="row justify-content-center">
12+
<div class="col-10 col-xl-5">
13+
<div style="background-color: white; border-radius: 25px">
14+
<img alt="elephant?" src="../static/icons/elephant.png" class="mx-auto d-block" width="200px" th:src="@{/icons/elephant.png}">
15+
<p class="text-center display-4 pb-3" style="color: #5700f7">Something went wrong... :(</p>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
</body>
21+
</html>
Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,112 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="en" xmlns:th="http://www.thymeleaf.org">
33
<head>
4+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
5+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
6+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
7+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
48
<meta charset="UTF-8">
5-
<title>Title</title>
9+
<title>Home</title>
10+
<link rel="icon" th:href="@{/icons/elephant2.png}">
611
</head>
7-
<body>
8-
<h1>INDEX</h1>
12+
<body style="background-color: #dfdfe9;">
13+
<div class="my-4 container-fluid">
14+
<div class="row justify-content-center">
15+
<div class="col-11 col-xl-11">
16+
<div style="background-color: white; border-radius: 25px; overflow: hidden">
17+
18+
<nav class="navbar navbar-expand-lg navbar-light">
19+
<img alt="elephant?" class="d-block mx-5" width="75px" src="../static/icons/elephant.png" th:src="@{/icons/elephant.png}">
20+
<a class="display-4" style="color: black" href="/index">Elephant Express</a>
21+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
22+
<span class="navbar-toggler-icon"></span>
23+
</button>
24+
<div class="collapse navbar-collapse" id="navbarNavDropdown">
25+
<ul class="navbar-nav ml-auto">
26+
<li class="nav-item active">
27+
<a class="nav-link h4" href="/home">Home <span class="sr-only">(current)</span></a>
28+
</li>
29+
<li class="nav-item">
30+
<a class="nav-link h4" href="/order">Order</a>
31+
</li>
32+
<li class="nav-item dropdown">
33+
<a class="nav-link dropdown-toggle h4" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" th:text="${username}"></a>
34+
<div class="dropdown-menu dropdown-menu-right p-0" style="border: none" aria-labelledby="navbarDropdownMenuLink">
35+
<a class="dropdown-item mb-2" th:attr="href=${linkInOrAccount}" style="background-color: #5700f7; color: white; border-radius: 25px" th:text="${textInOrAccount}">LogIn</a>
36+
<a class="dropdown-item" th:attr="href=${linkOutOrUp}" style="background-color: grey; color: white; border-radius: 25px" th:text="${textOutOrUp}">LogOut</a>
37+
</div>
38+
</li>
39+
</ul>
40+
</div>
41+
</nav>
42+
<hr class="mx-3" style="background-color: #5700f7">
43+
44+
<div class="row justify-content-center text-center">
45+
<div class="col-10 col-xl-5">
46+
<p class="h3 font-weight-normal my-4"> Быстро? Качественно? Elephant Express! </p>
47+
<img alt="map?" class="mx-auto" width="100%" src="../static/images/map.png" th:src="@{/images/map.png}">
48+
<p class="h3 font-weight-normal my-4"> Во все населенные точки мира! </p>
49+
<p class="h3 font-weight-normal my-4" style="color: #5700f7"> А иногда даже дальше... </p>
50+
</div>
51+
</div>
52+
<hr class="mx-3">
53+
54+
<div class="row justify-content-center text-center mb-3">
55+
<div class="col-10 col-xl-5">
56+
<p class="h3 font-weight-normal my-3"> Услуги, предоставляемые компанией </p>
57+
<div class="h4 font-weight-normal">
58+
<img alt="leaf?" class="mx-auto" width="30px" src="../static/icons/leaf.png" th:src="@{/icons/leaf.png}">
59+
Логистика
60+
</div>
61+
<div class="h4 font-weight-normal">
62+
<img alt="leaf?" class="mx-auto" width="30px" src="../static/icons/leaf.png" th:src="@{/icons/leaf.png}">
63+
Курьерские и почтовые доставки
64+
</div>
65+
<div class="h4 font-weight-normal">
66+
<img alt="leaf?" class="mx-auto" width="30px" src="../static/icons/leaf.png" th:src="@{/icons/leaf.png}">
67+
Взаимодейтсвие с другими компаниями
68+
</div>
69+
<p class="h3 font-weight-normal my-4" style="color: #5700f7"> Специалисты все сделают за вас! </p>
70+
</div>
71+
</div>
72+
73+
<footer class="footer py-3" style="background-color: #5700f7; color: white; border-radius: 25px">
74+
<div class="mx-5">
75+
<div class="row justify-content-center text-center">
76+
<div class="col">Contacts! Just in case...</div>
77+
</div>
78+
<div class="row justify-content-center text-center">
79+
<div class="col-6 col-xl-3">Звягинцев М.Е.</div>
80+
<div class="col-6 col-xl-3">ИКБО-16-20</div>
81+
<div class="col-6 col-xl-3">
82+
<img alt="vk?" class="mx-auto" width="30px" src="../static/icons/vk.png" th:src="@{/icons/vk.png}">
83+
<a class="text-light" href="https://vk.com/max.zvyagincev">vk.com/max.zvyagincev</a>
84+
</div>
85+
<div class="col-6 col-xl-3">
86+
<img alt="telegram?" class="mx-auto" width="30px" src="../static/icons/telegram.png" th:src="@{/icons/telegram.png}">
87+
<a class="text-light" href="https://t.me/max_zvyagincev">t.me/max_zvyagincev</a>
88+
</div>
89+
</div>
90+
<div class="row justify-content-center text-center">
91+
<div class="col-6 col-xl-3">
92+
<img alt="github?" class="mx-auto" width="30px" src="../static/icons/mail.png" th:src="@{/icons/mail.png}">
93+
maxim@zvyagincev.tk
94+
</div>
95+
<div class="col-6 col-xl-3">
96+
<img alt="github?" class="mx-auto" width="30px" src="../static/icons/mail.png" th:src="@{/icons/mail.png}">
97+
max.zvyagincev@gmail.com
98+
</div>
99+
<div class="col-6 col-xl-3">
100+
<img alt="github?" class="mx-auto" width="30px" src="../static/icons/github.png" th:src="@{/icons/github.png}">
101+
<a class="text-light" href="https://github.com/xPressed">github.com/xPressed</a>
102+
</div>
103+
<div class="col-6 col-xl-3">All rights reserved © 2021-2023</div>
104+
</div>
105+
</div>
106+
</footer>
107+
</div>
108+
</div>
109+
</div>
110+
</div>
9111
</body>
10112
</html>

src/main/resources/templates/login.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
55
<meta charset="UTF-8">
66
<title>Authorization</title>
7-
<link rel="icon" href="../static/elephant.png">
7+
<link rel="icon" th:href="@{/icons/elephant2.png}">
88
<script>
99
function redirect() {
1010
location.href="/registration";
1111
}
1212
</script>
1313
</head>
1414
<body style="background-color: #dfdfe9;">
15-
<div class="mt-5 pt-5 container-fluid">
15+
<div class="mt-4 container-fluid">
1616
<div class="row justify-content-center">
1717
<div class="col-10 col-xl-5">
1818
<div style="background-color: white; border-radius: 25px">
19-
<img alt="elephant?" src="../static/elephant.png" class="mx-auto d-block" width="200px">
19+
<img alt="elephant?" class="mx-auto d-block" width="200px" src="../static/icons/elephant.png" th:src="@{/icons/elephant.png}">
2020
<p class="text-center display-4">Authorization</p>
2121

2222
<form action="#" th:action="@{/perform-login}" method="post">
@@ -36,7 +36,7 @@
3636

3737

3838
<div class="d-flex justify-content-center m-3 pb-3">
39-
<button type="submit" class="btn btn-primary btn-lg pb-3 mx-4" style="background-color: #5700f7">LogIn</button>
39+
<button type="submit" class="btn btn-primary btn-lg" style="background-color: #5700f7">LogIn</button>
4040
<button type="button" onclick="redirect()" class="btn btn-primary btn-lg pb-3 mx-4" style="background-color: #5700f7">Registration</button>
4141
</div>
4242
</form>

src/main/resources/templates/registration.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
55
<meta charset="UTF-8">
66
<title>Registration</title>
7-
<link rel="icon" href="../static/elephant.png">
7+
<link rel="icon" th:href="@{/icons/elephant2.png}">
88
<script>
9-
function redirect() {
9+
function redirectTimer() {
1010
setTimeout('location.href="/login";', 5000);
1111
}
12+
13+
function redirect() {
14+
location.href="/login"
15+
}
1216
</script>
1317
</head>
1418
<body th:attr="onload=${onload}" style="background-color: #dfdfe9;">
15-
<div class="mt-5 pt-5 container-fluid">
19+
<div class="mt-4 container-fluid">
1620
<div class="row justify-content-center">
1721
<div class="col-10 col-xl-5">
1822
<div style="background-color: white; border-radius: 25px">
19-
<img alt="elephant?" src="../static/elephant.png" class="mx-auto d-block" width="200px">
23+
<img alt="elephant?" class="mx-auto d-block" width="200px" src="../static/icons/elephant.png" th:src="@{/icons/elephant.png}">
2024
<p class="text-center display-4">Registration</p>
2125

2226
<form action="#" th:action="@{/registration}" th:object="${customer}" method="post">
@@ -42,6 +46,7 @@
4246

4347
<div class="d-flex justify-content-center m-3">
4448
<button type="submit" class="btn btn-primary btn-lg" style="background-color: #5700f7">Register</button>
49+
<button type="button" onclick="redirect()" class="btn btn-primary btn-lg pb-3 mx-4" style="background-color: #5700f7">Authorization</button>
4550
</div>
4651
</form>
4752

0 commit comments

Comments
 (0)