PAN-54 For some reason it thinks I deleted these files???
This commit is contained in:
@@ -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<Account> 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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" %>
|
||||||
|
|
||||||
|
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Log in with your account</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<form method="post" action="">
|
||||||
|
<h2 class="form-heading">Log in</h2>
|
||||||
|
<div>
|
||||||
|
<input name="username" type="text" class="form-control" placeholder="Username"/><br>
|
||||||
|
<input name="password" type="password" class="form-control" placeholder="Password"/><br>
|
||||||
|
<span style="Color: red">${error}</span><br>
|
||||||
|
<input type="hidden" name="${parameterName}" value="${token}"/>
|
||||||
|
<button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button>
|
||||||
|
<h4 class="text-center"><a href="/registration">Create an account</a></h4>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user