diff --git a/.current.json b/.current.json index 748701d..56f9647 100644 --- a/.current.json +++ b/.current.json @@ -1 +1 @@ -{"assignment":"java-web-ru/get-form"} +{"assignment":"java-web-ru/post-form"} diff --git a/java-web-ru/post-form/gradlew b/java-web-ru/post-form/gradlew old mode 100644 new mode 100755 diff --git a/java-web-ru/post-form/gradlew.bat b/java-web-ru/post-form/gradlew.bat index 93e3f59..6689b85 100644 --- a/java-web-ru/post-form/gradlew.bat +++ b/java-web-ru/post-form/gradlew.bat @@ -1,92 +1,92 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/java-web-ru/post-form/src/main/java/exercise/App.java b/java-web-ru/post-form/src/main/java/exercise/App.java index b67bd40..5354102 100644 --- a/java-web-ru/post-form/src/main/java/exercise/App.java +++ b/java-web-ru/post-form/src/main/java/exercise/App.java @@ -1,53 +1,53 @@ -package exercise; - -import io.javalin.Javalin; -import java.util.List; -import java.util.Collections; -import java.util.Objects; - -import exercise.model.User; -import exercise.dto.users.UsersPage; -import exercise.repository.UserRepository; -import org.apache.commons.lang3.StringUtils; -import exercise.util.Security; - -public final class App { - - public static Javalin getApp() { - - var app = Javalin.create(config -> { - config.plugins.enableDevLogging(); - }); - - app.get("/", ctx -> { - ctx.render("index.jte"); - }); - - app.get("/users", ctx -> { - List users = UserRepository.getEntities(); - var page = new UsersPage(users); - ctx.render("users/index.jte", Collections.singletonMap("page", page)); - }); - - // BEGIN - app.get("/users/build", ctx -> ctx.render("users/build.jte")); - - app.post("/users", ctx -> { - var firstName = StringUtils.capitalize(ctx.formParam("firstName")); - var lastName = StringUtils.capitalize(ctx.formParam("lastName")); - var email = Objects.requireNonNull(ctx.formParam("email")).trim().toLowerCase(); - var password = Security.encrypt(Objects.requireNonNull(ctx.formParam("password"))); - var user = new User(firstName, lastName, email, password); - UserRepository.save(user); - ctx.redirect("/users"); - }); - // END - - return app; - } - - public static void main(String[] args) { - Javalin app = getApp(); - app.start(7070); - } -} +package exercise; + +import io.javalin.Javalin; +import java.util.List; +import java.util.Collections; +import java.util.Objects; + +import exercise.model.User; +import exercise.dto.users.UsersPage; +import exercise.repository.UserRepository; +import org.apache.commons.lang3.StringUtils; +import exercise.util.Security; + +public final class App { + + public static Javalin getApp() { + + var app = Javalin.create(config -> { + config.plugins.enableDevLogging(); + }); + + app.get("/", ctx -> { + ctx.render("index.jte"); + }); + + app.get("/users", ctx -> { + List users = UserRepository.getEntities(); + var page = new UsersPage(users); + ctx.render("users/index.jte", Collections.singletonMap("page", page)); + }); + + // BEGIN + app.get("/users/build", ctx -> ctx.render("users/build.jte")); + + app.post("/users", ctx -> { + var firstName = StringUtils.capitalize(ctx.formParam("firstName")); + var lastName = StringUtils.capitalize(ctx.formParam("lastName")); + var email = Objects.requireNonNull(ctx.formParam("email")).trim().toLowerCase(); + var password = Security.encrypt(Objects.requireNonNull(ctx.formParam("password"))); + var user = new User(firstName, lastName, email, password); + UserRepository.save(user); + ctx.redirect("/users"); + }); + // END + + return app; + } + + public static void main(String[] args) { + Javalin app = getApp(); + app.start(7070); + } +} diff --git a/java-web-ru/post-form/src/main/java/exercise/dto/users/UsersPage.java b/java-web-ru/post-form/src/main/java/exercise/dto/users/UsersPage.java index 28138fb..5664adf 100644 --- a/java-web-ru/post-form/src/main/java/exercise/dto/users/UsersPage.java +++ b/java-web-ru/post-form/src/main/java/exercise/dto/users/UsersPage.java @@ -1,15 +1,15 @@ -package exercise.dto.users; - -import exercise.model.User; -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Getter; -@Getter -@AllArgsConstructor -// BEGIN -public class UsersPage { - private List users; - -} -// END +package exercise.dto.users; + +import exercise.model.User; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +@Getter +@AllArgsConstructor +// BEGIN +public class UsersPage { + private List users; + +} +// END diff --git a/java-web-ru/post-form/src/main/jte/users/build.jte b/java-web-ru/post-form/src/main/jte/users/build.jte index dd42e81..4e016ef 100644 --- a/java-web-ru/post-form/src/main/jte/users/build.jte +++ b/java-web-ru/post-form/src/main/jte/users/build.jte @@ -1,30 +1,30 @@ -@import gg.jte.Content -@param Content content - -
-
- -
-
- -
-
- -
-
- -
- -
+@import gg.jte.Content +@param Content content + +
+
+ +
+
+ +
+
+ +
+
+ +
+ +