Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:17.0.2-jdk-slim-buster
ARG JAR_FILE=target/*.jar
COPY resources /resources
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar","app.jar"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
- https://habr.com/ru/articles/259055/

Список выполненных задач:
...
2, 3, 6, 11, 4, 5, 9
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@
<mapstruct.version>1.5.3.Final</mapstruct.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<testcontainers.version>1.18.3</testcontainers.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
Expand Down Expand Up @@ -142,6 +154,18 @@
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
9 changes: 4 additions & 5 deletions resources/mails/email-confirmation.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>JiraRush - подтверждение почты</title>
<title th:text="#{mails.confirmation.title}"></title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<body>
<p th:text="'Привет, ' + ${user.firstName} + '.'"/>
<p>Чтобы завершить настройку учетной записи и начать пользоваться JiraRush, подтвердите, что вы правильно указали вашу
электронную почту.</p>
<a th:href="${confirmationUrl}">Подтвердить почту</a>
<p th:text=" #{mails.confirmation.greetings} + ', ' + ${user.firstName} + '.'"/>
<p th:text="#{mails.confirmation.text}"></p>
<a th:href="${confirmationUrl}" th:text="#{mails.button.confirm-mail}"></a>
</body>
</html>
8 changes: 4 additions & 4 deletions resources/mails/password-reset.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="head">
<title>JiraRush - установить новый пароль</title>
<title th:text="#{mails.password-reset.title}"></title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<body>
<p th:text="'Привет, ' + ${user.firstName} + '.'"/>
<p th:text="'Мы получили запрос на установку нового пароля JiraRush для учетной записи: ' + ${user.email} + '.'"/>
<a th:href="${resetUrl}">Установить пароль</a>
<p th:text=" #{mails.password-reset.greetings} + ', ' + ${user.firstName} + '.'"/>
<p th:text=" #{mails.password-reset.request} + ': ' + ${user.email} + '.'"/>
<a th:href="${resetUrl}" th:text="#{mails.button.reset}"></a>
</body>
</html>
2 changes: 1 addition & 1 deletion resources/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<th:block th:replace="~{layout/main::page(title='JiraRush: mini bugtracking system',appMain=~{::appMain})}">
<appMain>
<h1>JiraRush Home page</h1>
<h1 th:text="#{index.title}"></h1>
<div th:if="${authUser} != null">
<form action="/ui/logout" method="post">
<button class="btn btn-primary btn-lg mt-3" type="submit">Logout</button>
Expand Down
8 changes: 0 additions & 8 deletions resources/view/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ <h3 class="mb-3">Sign in</h3>
type="button">
<i class="fa-brands fa-google"></i>
</a>
<a class="btn btn-primary btn-lg me-2" href="/oauth2/authorization/vk" style="padding-left: 17px; padding-right: 17px;"
type="button">
<i class="fa-brands fa-vk"></i>
</a>
<a class="btn btn-danger btn-lg me-2" href="/oauth2/authorization/yandex" style="padding-left: 21px; padding-right: 21px;"
type="button">
<i class="fa-brands fa-yandex"></i>
</a>
<a class="btn btn-dark btn-lg me-2" href="/oauth2/authorization/github" type="button">
<i class="fa-brands fa-github"></i>
</a>
Expand Down
8 changes: 0 additions & 8 deletions resources/view/unauth/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ <h3 class="mb-3">Registration</h3>
type="button">
<i class="fa-brands fa-google"></i>
</a>
<a class="btn btn-primary btn-lg me-2" href="/oauth2/authorization/vk" style="padding-left: 17px; padding-right: 17px;"
type="button">
<i class="fa-brands fa-vk"></i>
</a>
<a class="btn btn-danger btn-lg me-2" href="/oauth2/authorization/yandex" style="padding-left: 21px; padding-right: 21px;"
type="button">
<i class="fa-brands fa-yandex"></i>
</a>
<a class="btn btn-dark btn-lg me-2" href="/oauth2/authorization/github" type="button">
<i class="fa-brands fa-github"></i>
</a>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/javarush/jira/JiraRushApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class JiraRushApplication {

public static void main(String[] args) {
SpringApplication.run(JiraRushApplication.class, args);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public static void upload(MultipartFile multipartFile, String directoryPath, Str
File dir = new File(directoryPath);
if (dir.exists() || dir.mkdirs()) {
File file = new File(directoryPath + fileName);
try (OutputStream outStream = new FileOutputStream(file)) {
outStream.write(multipartFile.getBytes());
} catch (IOException ex) {
try {
multipartFile.transferTo(file);
} catch (IOException e) {
throw new IllegalRequestDataException("Failed to upload file" + multipartFile.getOriginalFilename());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@ public TaskTreeNode(TaskTo taskTo) {
this(taskTo, new LinkedList<>());
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.mvc.UrlFilenameViewController;

import java.time.Duration;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void preHandle(WebRequest request) {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authInterceptor).excludePathPatterns("/api/**");
registry.addInterceptor(localeChangeInterceptor());
}

// http://www.codejava.net/frameworks/spring/spring-mvc-url-based-view-resolution-with-urlfilenameviewcontroller-example
Expand Down Expand Up @@ -95,4 +97,11 @@ public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
.setReadTimeout(Duration.ofSeconds(10))
.build();
}

@Bean
public LocaleChangeInterceptor localeChangeInterceptor(){
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.thymeleaf.spring6.SpringTemplateEngine;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.FileTemplateResolver;

import java.util.Locale;
import java.util.Set;

@Configuration
Expand Down Expand Up @@ -38,4 +41,11 @@ private FileTemplateResolver createTemplateResolver(String pfx) {
setCharacterEncoding("UTF-8");
}};
}

@Bean
public LocaleResolver localResolver(){
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(Locale.US);
return sessionLocaleResolver;
}
}
30 changes: 30 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/jira
spring.datasource.username=jira
spring.datasource.password=JiraRush

spring.security.oauth2.client.registration.github.client-id=3d0d8738e65881fff266
spring.security.oauth2.client.registration.github.client-secret=0f97031ce6178b7dfb67a6af587f37e222a16120
spring.security.oauth2.client.registration.github.scope=email

spring.security.oauth2.client.registration.google.client-id=329113642700-f8if6pu68j2repq3ef6umd5jgiliup60.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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
spring.security.oauth2.client.registration.google.scope=email, profile

spring.security.oauth2.client.registration.gitlab.client-id=b8520a3266089063c0d8261cce36971defa513f5ffd9f9b7a3d16728fc83a494
spring.security.oauth2.client.registration.gitlab.client-secret=e72c65320cf9d6495984a37b0f9cc03ec46be0bb6f071feaebbfe75168117004
spring.security.oauth2.client.registration.gitlab.client-name=GitLab
spring.security.oauth2.client.registration.gitlab.redirect-uri="{baseUrl}/login/oauth2/code/{registrationId}"
spring.security.oauth2.client.registration.gitlab.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.gitlab.scope=read_user

spring.security.oauth2.client.provider.gitlab.authorization-uri=https://gitlab.com/oauth/authorize
spring.security.oauth2.client.provider.gitlab.token-uri=https://gitlab.com/oauth/token
spring.security.oauth2.client.provider.gitlab.user-info-uri=https://gitlab.com/api/v4/user
spring.security.oauth2.client.provider.gitlab.user-name-attribute=email

spring.mail.host=smtp.gmail.com
spring.mail.username=jira4jr@gmail.com
spring.mail.password=zdfzsrqvgimldzyj
spring.mail.port=587


66 changes: 5 additions & 61 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ app:
max-pool-size: 100

spring:
messages:
basename: language/messages
encoding: UTF-8

init:

mode: never
jpa:
show-sql: true
Expand All @@ -25,10 +30,6 @@ spring:
default_batch_fetch_size: 20
# https://stackoverflow.com/questions/21257819/what-is-the-difference-between-hibernate-jdbc-fetch-size-and-hibernate-jdbc-batc
jdbc.batch_size: 20
datasource:
url: jdbc:postgresql://localhost:5432/jira
username: jira
password: JiraRush

liquibase:
changeLog: "classpath:db/changelog.sql"
Expand All @@ -46,59 +47,6 @@ spring:
cache-names: users
caffeine.spec: maximumSize=10000,expireAfterAccess=5m

security:
oauth2:
client:
registration:
github:
client-id: 3d0d8738e65881fff266
client-secret: 0f97031ce6178b7dfb67a6af587f37e222a16120
scope:
- email
google:
client-id: 329113642700-f8if6pu68j2repq3ef6umd5jgiliup60.apps.googleusercontent.com
client-secret: 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
scope:
- email
- profile
vk:
client-id: 51562377
client-secret: jNM1YHQy1362Mqs49wUN
client-name: Vkontakte
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
client-authentication-method: client_secret_post
authorization-grant-type: authorization_code
scope: email
yandex:
client-id: 2f3395214ba84075956b76a34b231985
client-secret: ed236c501e444a609b0f419e5e88f1e1
client-name: Yandex
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
authorization-grant-type: authorization_code
gitlab:
client-id: b8520a3266089063c0d8261cce36971defa513f5ffd9f9b7a3d16728fc83a494
client-secret: e72c65320cf9d6495984a37b0f9cc03ec46be0bb6f071feaebbfe75168117004
client-name: GitLab
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
authorization-grant-type: authorization_code
scope: read_user
provider:
vk:
authorization-uri: https://oauth.vk.com/authorize
token-uri: https://oauth.vk.com/access_token
user-info-uri: https://api.vk.com/method/users.get?v=8.1
user-name-attribute: response
yandex:
authorization-uri: https://oauth.yandex.ru/authorize
token-uri: https://oauth.yandex.ru/token
user-info-uri: https://login.yandex.ru/info
user-name-attribute: login
gitlab:
authorization-uri: https://gitlab.com/oauth/authorize
token-uri: https://gitlab.com/oauth/token
user-info-uri: https://gitlab.com/api/v4/user
user-name-attribute: email

sql:
init:
mode: always
Expand All @@ -110,10 +58,6 @@ spring:
starttls:
enable: true
auth: true
host: smtp.gmail.com
username: jira4jr@gmail.com
password: zdfzsrqvgimldzyj
port: 587
thymeleaf.check-template-location: false

mvc.throw-exception-if-no-handler-found: true
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/language/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#-----------Mails-----------------------
mails.confirmation.greetings = \u041F\u0440\u0438\u0432\u0435\u0442
mails.confirmation.title = JiraRush - \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u043F\u043E\u0447\u0442\u044B
mails.confirmation.text = \u0427\u0442\u043E\u0431\u044B \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044C \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0443 \u0443\u0447\u0435\u0442\u043D\u043E\u0439 \u0437\u0430\u043F\u0438\u0441\u0438 \u0438 \u043D\u0430\u0447\u0430\u0442\u044C \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F JiraRush, \u043F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u0435, \u0447\u0442\u043E \u0432\u044B \u043F\u0440\u0430\u0432\u0438\u043B\u044C\u043D\u043E \u0443\u043A\u0430\u0437\u0430\u043B\u0438 \u0432\u0430\u0448\u0443 \u044D\u043B\u0435\u043A\u0442\u0440\u043E\u043D\u043D\u0443\u044E \u043F\u043E\u0447\u0442\u0443.
mails.button.confirm-mail = \u041F\u043E\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044C \u043F\u043E\u0447\u0442\u0443
mails.password-reset.title = JiraRush - \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043D\u043E\u0432\u044B\u0439 \u043F\u0430\u0440\u043E\u043B\u044C
mails.password-reset.greetings = \u041F\u0440\u0438\u0432\u0435\u0442
mails.password-reset.request = \u041C\u044B \u043F\u043E\u043B\u0443\u0447\u0438\u043B\u0438 \u0437\u0430\u043F\u0440\u043E\u0441 \u043D\u0430 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0443 \u043D\u043E\u0432\u043E\u0433\u043E \u043F\u0430\u0440\u043E\u043B\u044F JiraRush \u0434\u043B\u044F \u0443\u0447\u0435\u0442\u043D\u043E\u0439 \u0437\u0430\u043F\u0438\u0441\u0438
mails.button.reset = \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043F\u0430\u0440\u043E\u043B\u044C

#----------Index----------------
index.title = JiraRush \u0414\u043E\u043C\u0430\u0448\u043D\u044F\u044F \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0430




16 changes: 16 additions & 0 deletions src/main/resources/language/messages_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#-----------Mails-----------------------
mails.confirmation.greetings = Hello
mails.confirmation.title = JiraRush - confirm email
mails.confirmation.text = To complete your account setup and start using JiraRush, please confirm that you have entered your email correctly.
mails.button.confirm-mail = Confirm email
mails.password-reset.title = JiraRush - set a new password
mails.password-reset.greetings = Hello
mails.password-reset.request = We have received a request to set a new JiraRush account password
mails.button.reset = Set password

#----------Index----------------
index.title = JiraRush Home page




15 changes: 15 additions & 0 deletions src/test/java/com/javarush/jira/EnableTestContainers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.javarush.jira;


import org.springframework.test.context.ContextConfiguration;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ContextConfiguration(initializers = TestcontainersInitializer.class)
public @interface EnableTestContainers {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;

@EnableTestContainers
class JiraRushApplicationTests extends BaseTests {
@Test
void contextLoads() {
Expand Down
Loading