-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
852 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# WARNING: Paths must not include the name of the "lessons" directory. | ||
# Outside, this directory is called "exercises". | ||
|
||
**/*/presentation*.html | ||
.vagrant | ||
.idea/ | ||
node_modules/ | ||
vendor/ | ||
dist | ||
.gradle/ | ||
build/ | ||
caches/ | ||
.vscode/ | ||
.project | ||
.settings | ||
jte-classes | ||
.classpath | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
test: | ||
./gradlew test | ||
|
||
start: | ||
./gradlew run |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## Сессии | ||
|
||
В этой практике необходимо реализовать систему аутентификации. В нашем случае она состоит из таких маршрутов: | ||
|
||
* GET */sessions/build* — форма логина, в которой пользователь вводит имя и пароль | ||
* POST */sessions* для создания сессии | ||
* POST */sessions/delete* для удаления сессии | ||
|
||
После выполнения каждого из этих действий происходит редирект на главную страницу. | ||
|
||
### Ссылки | ||
|
||
* [Методы работы с контекстом](https://javalin.io/documentation#context) | ||
|
||
### src/main/java/exercise/controller/SessionsController.java | ||
|
||
Реализуйте обработчики для указанных выше маршрутов. Для работы с пользователями используйте репозиторий `UsersRepository`. | ||
|
||
Список пользователей с именами и паролями можно посмотреть в классе `Generator`. Обратите внимание, что пароль хранится в зашифрованном виде. Это значит, что при сравнении необходимо шифровать пароль от пользователя и сравнивать хеши. | ||
|
||
Если имя или пароль неверные, то снова отрисовывается форма логина и показывается сообщение *Wrong username or password*. | ||
|
||
### src/main/java/exercise/App.java | ||
|
||
Опишите роутинг для указанных выше обработчиков. Используйте именованные маршруты. | ||
|
||
В этом задании имена маршрутов уже описаны в классе `NamedRoutes`. | ||
|
||
### src/main/jte/posts/build.jte | ||
|
||
Реализуйте шаблон с формой логина. Для входа в систему мы должны запрашивать у пользователя его имя и пароль. | ||
|
||
### src/main/jte/posts/index.jte | ||
|
||
Реализуйте шаблон главной страницы: | ||
|
||
* Если пользователь не аутентифицирован, то ему показывается ссылка на страницу логина с текстом *Войти* | ||
* Если аутентифицирован, то его имя и форма с кнопкой *Выйти* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat | ||
import org.gradle.api.tasks.testing.logging.TestLogEvent | ||
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask | ||
|
||
plugins { | ||
id("com.github.ben-manes.versions") version "0.48.0" | ||
application | ||
|
||
id("io.freefair.lombok") version "8.1.0" | ||
} | ||
|
||
application { | ||
mainClass.set("exercise.App") | ||
} | ||
|
||
group = "exercise" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("io.javalin:javalin:5.6.1") | ||
|
||
implementation("gg.jte:jte:3.0.1") | ||
implementation("io.javalin:javalin-rendering:5.6.0") | ||
implementation("org.slf4j:slf4j-simple:2.0.7") | ||
implementation("net.datafaker:datafaker:2.0.1") | ||
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.0") | ||
testImplementation(platform("org.junit:junit-bom:5.9.1")) | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
testImplementation("com.konghq:unirest-java:3.13.0") | ||
testImplementation("org.hamcrest:hamcrest-core:2.2") | ||
testImplementation("org.assertj:assertj-core:3.24.2") | ||
implementation("com.google.guava:guava:32.1.2-jre") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
// https://technology.lastminute.com/junit5-kotlin-and-gradle-dsl/ | ||
testLogging { | ||
exceptionFormat = TestExceptionFormat.FULL | ||
events = mutableSetOf(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED) | ||
// showStackTraces = true | ||
// showCauses = true | ||
showStandardStreams = true | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import io.javalin.Javalin; | ||
|
||
public final class App { | ||
|
||
public static Javalin getApp() { | ||
|
||
var app = Javalin.create(config -> { | ||
config.plugins.enableDevLogging(); | ||
}); | ||
|
||
List<String> users = List.of("John", "Mark", "Ann"); | ||
|
||
app.get("/users", ctx -> { | ||
var userNumber = ctx.pathParamAsClass("id", Integer.class); | ||
var cond = ctx.queryParam("cond"); | ||
List<String> filteredUsers; | ||
|
||
if (term == null) { | ||
filteredUsers = users; | ||
} else { | ||
filteredUsers = users | ||
.stream() | ||
.filter(u -> u.contains(cond)) | ||
.toList(); | ||
} | ||
|
||
var page = new UsersPage(users, cond); | ||
ctx.render("users/index.jte", Collections.singletonMap("page", page)); | ||
}); | ||
|
||
return app; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Javalin app = getApp(); | ||
app.start(7070); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.