diff --git a/build.gradle b/build.gradle
index 73d5cfc..04b39ec 100644
--- a/build.gradle
+++ b/build.gradle
@@ -20,6 +20,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.projectlombok:lombok:1.18.24'
+
+ // render
+ implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.1.0'
annotationProcessor 'org.projectlombok:lombok'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
diff --git a/src/main/java/com/io/realworld/api/MainController.java b/src/main/java/com/io/realworld/api/MainController.java
new file mode 100644
index 0000000..5d318bc
--- /dev/null
+++ b/src/main/java/com/io/realworld/api/MainController.java
@@ -0,0 +1,25 @@
+package com.io.realworld.api;
+
+import com.io.realworld.DTO.UserSignupRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+@Slf4j
+@Controller
+public class MainController {
+
+ @GetMapping("")
+ public String mainHome(){
+ return "index";
+ }
+
+ @GetMapping("/register")
+ public String signupView(){
+ return "/users/signup";
+ }
+
+}
diff --git a/src/main/java/com/io/realworld/api/users/UserController.java b/src/main/java/com/io/realworld/api/users/UserController.java
index 4d423ca..a3da444 100644
--- a/src/main/java/com/io/realworld/api/users/UserController.java
+++ b/src/main/java/com/io/realworld/api/users/UserController.java
@@ -5,12 +5,17 @@ import com.io.realworld.DTO.UserResponse;
import com.io.realworld.repository.User;
import com.io.realworld.service.UserService;
import com.io.realworld.service.UserServiceImpl;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
@RestController
+@Slf4j
+@RequestMapping("/api")
public class UserController {
@@ -20,14 +25,15 @@ public class UserController {
this.userService = userService;
}
- @PostMapping("/users")
+ @PostMapping(value = "/users")
public UserResponse signup(@Valid @RequestBody UserSignupRequest userSignupRequest) {
User user = userService.signup(userSignupRequest);
+ log.info("register");
+
return UserResponse.builder().username(user.getUsername())
.email(user.getEmail())
.bio(user.getBio())
.image(user.getImage())
.build();
-
}
}
diff --git a/src/main/java/com/io/realworld/config/WebConfig.java b/src/main/java/com/io/realworld/config/WebConfig.java
index e6faa05..4f1a6a2 100644
--- a/src/main/java/com/io/realworld/config/WebConfig.java
+++ b/src/main/java/com/io/realworld/config/WebConfig.java
@@ -27,7 +27,7 @@ public class WebConfig {
http.csrf()
.disable()
.authorizeRequests()
- .antMatchers("/users/**","/h2-console/**").permitAll()
+ .antMatchers("/api/users/**", "/h2-console/**", "/**").permitAll()
.anyRequest().authenticated()
.and().headers().frameOptions().sameOrigin()
.and()
@@ -37,4 +37,5 @@ public class WebConfig {
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
return http.build();
}
+
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index e9dd9be..79f1502 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,4 +1,3 @@
-server.servlet.contextPath=/api
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
diff --git a/src/main/resources/static/js/userAjax.js b/src/main/resources/static/js/userAjax.js
new file mode 100644
index 0000000..1a420f4
--- /dev/null
+++ b/src/main/resources/static/js/userAjax.js
@@ -0,0 +1,25 @@
+function register() {
+ const username = $("#username").val();
+ const password = $("#password").val();
+ const email = $("#email").val();
+ const userDTO = JSON.stringify({
+ user: {
+ username: username,
+ password: password,
+ email: email,
+ }
+ })
+
+ $.ajax({
+ url: "/api/users",
+ data: userDTO,
+ contentType: "application/json",
+ async: false,
+ type: "POST",
+ }).success(function (data) {
+ // Todo redirect home login status
+ console.log(JSON.stringify(data));
+ window.location.href= "/index.html";
+ console.log(window.location.href)
+ });
+}
\ No newline at end of file
diff --git a/src/main/resources/templates/framents/footer.html b/src/main/resources/templates/framents/footer.html
new file mode 100644
index 0000000..0240d0b
--- /dev/null
+++ b/src/main/resources/templates/framents/footer.html
@@ -0,0 +1,14 @@
+
+
+
+ Have an account? +
+ + + + +