diff --git a/build.gradle b/build.gradle index d2d9c24..6e26871 100644 --- a/build.gradle +++ b/build.gradle @@ -99,6 +99,7 @@ repositories { } dependencies { + compile project(':services') compile group: 'org.jacoco', name: 'org.jacoco.core', version: '0.8.3' compile 'org.codehaus.groovy:groovy-all:2.3.11' compile 'org.apache.commons:commons-lang3:3.5' diff --git a/src/main/java/edu/msudenver/tsp/website/Application.java b/src/main/java/edu/msudenver/tsp/website/Application.java index 54da024..1b826ed 100644 --- a/src/main/java/edu/msudenver/tsp/website/Application.java +++ b/src/main/java/edu/msudenver/tsp/website/Application.java @@ -2,11 +2,17 @@ package edu.msudenver.tsp.website; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan("edu.msudenver.tsp") + public class Application { - public static void main(final String[] args) { + + public static void main(String[] args) { SpringApplication.run(Application.class, args); } + + } diff --git a/src/main/java/edu/msudenver/tsp/website/controller/LogInController.java b/src/main/java/edu/msudenver/tsp/website/controller/LogInController.java new file mode 100644 index 0000000..556c8d5 --- /dev/null +++ b/src/main/java/edu/msudenver/tsp/website/controller/LogInController.java @@ -0,0 +1,52 @@ +package edu.msudenver.tsp.website.controller; + + +import edu.msudenver.tsp.services.UserService; +import edu.msudenver.tsp.services.dto.Account; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.ModelAndView; + +import java.util.Optional; + +@Slf4j +@Controller +@AllArgsConstructor +@RequestMapping("/login") +public class LogInController { + @Autowired + private final UserService userService; + + @GetMapping({"/", ""}) + public ModelAndView enterLogInPage() { + LOG.info("Received request to display the log in page: returning model with name 'LogIn'"); + return new ModelAndView("LogIn"); + } + + @PostMapping({"/", ""}) + public String singIn(Model model, @RequestParam("username") String username, @RequestParam("password") String password) { + Optional findUserByUsername = userService.findAccountByUsername(username); + if(findUserByUsername.isPresent()){ + if (password.equals(findUserByUsername.get().getPassword())) { + model.addAttribute("username", username); + model.addAttribute("password", password); + return "index"; + } + else { + model.addAttribute("error", "your username and password is invalid"); + return "LogIn"; + } + } + else { + model.addAttribute("error", "username and password can not be empty"); + return "LogIn"; + } + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f3ce324..09b74b5 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,6 @@ spring.mvc.view.prefix:/WEB-INF/jsp/ -spring.mvc.view.suffix:.jsp \ No newline at end of file +spring.mvc.view.suffix:.jsp + +persistence.api.connection.timeout.milliseconds=5000 +persistence.api.socket.timeout.milliseconds=10000 +persistence.api.base.url=http://localhost:8090/ \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/LogIn.jsp b/src/main/webapp/WEB-INF/jsp/LogIn.jsp new file mode 100644 index 0000000..2670147 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/LogIn.jsp @@ -0,0 +1,35 @@ +<%-- + Created by IntelliJ IDEA. + User: tianliu + Date: 2019-04-24 + Time: 16:25 + To change this template use File | Settings | File Templates. +--%> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + + + + + Log in with your account + + +
+
+

Log in

+
+
+
+ ${error}
+ + +

Create an account

+
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index c87e887..7ee4c24 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -32,6 +32,17 @@ Click on this link to visit theorem ent

Sign In

+ + +
+
+

Theorem Prover

+

Hello! Welcome to Pandamoniumâ„¢ Theorem Prover!!

+ + Click on this link to visit theorem entering page. +

Sign In

+
+
diff --git a/src/test/java/edu/msudenver/tsp/website/controller/LogInControllerTest.java b/src/test/java/edu/msudenver/tsp/website/controller/LogInControllerTest.java new file mode 100644 index 0000000..6012386 --- /dev/null +++ b/src/test/java/edu/msudenver/tsp/website/controller/LogInControllerTest.java @@ -0,0 +1,24 @@ +package edu.msudenver.tsp.website.controller; + +import edu.msudenver.tsp.services.UserService; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.servlet.ModelAndView; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + + + +public class LogInControllerTest { + @Autowired UserService userService; + private final LogInController logInController = new LogInController(userService); + + @Test + public void testEnterTheoremPage() { + ModelAndView modelAndView = logInController.enterLogInPage(); + assertNotNull(modelAndView); + assertEquals("LogIn", modelAndView.getViewName()); + + } +}