Compare commits
26 Commits
v0.4
..
1c69c8998c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c69c8998c | ||
|
|
8cc31b5c21 | ||
|
|
08bda7099a | ||
|
|
766ba2753a | ||
|
|
96a9e584af | ||
|
|
7465568c97 | ||
|
|
d34ba70307 | ||
|
|
8f809ff422 | ||
|
|
071d195d2a | ||
|
|
e72760c528 | ||
|
|
09d76d93c1 | ||
|
|
52cc67ebfb | ||
|
|
3ee3d1bb06 | ||
|
|
27b28c1f36 | ||
|
|
6ab0470fca | ||
|
|
41a78babd9 | ||
|
|
ecd6584422 | ||
|
|
5de86dc498 | ||
|
|
cf49f9e980 | ||
|
|
f86b36aa17 | ||
|
|
1a2715ec04 | ||
|
|
1a12f29755 | ||
|
|
4cc184b6e7 | ||
|
|
6f70785387 | ||
|
|
2a4adcbd08 | ||
|
|
0fc825e11b |
@@ -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'
|
||||
|
||||
@@ -2,11 +2,16 @@ 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) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import edu.msudenver.tsp.services.UserService;
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import edu.msudenver.tsp.website.forms.UserCreationForm;
|
||||
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.validation.annotation.Validated;
|
||||
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.servlet.ModelAndView;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/createuser")
|
||||
public class UserCreationController {
|
||||
@Autowired
|
||||
private final UserService userService;
|
||||
|
||||
@GetMapping({"/",""})
|
||||
public ModelAndView createUserPage() {
|
||||
LOG.info("Received request to display the user creation page: returning model with name 'User'");
|
||||
return new ModelAndView("User");
|
||||
}
|
||||
|
||||
@PostMapping({"/",""})
|
||||
public String registerUser(@Validated final UserCreationForm userCreationForm, final Model model) {
|
||||
model.addAttribute("username", userCreationForm.getUsername());
|
||||
model.addAttribute("password", userCreationForm.getPassword());
|
||||
model.addAttribute("emailAddress", userCreationForm.getEmailAddress());
|
||||
|
||||
LOG.info("Saving user {}...", userCreationForm);
|
||||
|
||||
final Account newUser = new Account();
|
||||
newUser.setUsername(userCreationForm.getUsername());
|
||||
newUser.setPassword(userCreationForm.getPassword());
|
||||
userService.createAccount(newUser);
|
||||
|
||||
return "successfulRegistration";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
public class ValidationExceptionHandler {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package edu.msudenver.tsp.website.forms;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserCreationForm {
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String username;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String password;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String confirmPassword;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String emailAddress;
|
||||
|
||||
@NotNull
|
||||
private boolean agreedToTerms;
|
||||
}
|
||||
@@ -1,2 +1,6 @@
|
||||
spring.mvc.view.prefix:/WEB-INF/jsp/
|
||||
spring.mvc.view.suffix:.jsp
|
||||
spring.mvc.view.suffix:.jsp
|
||||
|
||||
persistence.api.connection.timeout.milliseconds=5000
|
||||
persistence.api.socket.timeout.milliseconds=10000
|
||||
persistence.api.base.url=http://localhost:8090/
|
||||
@@ -0,0 +1,147 @@
|
||||
<%@ taglib prefix="th" uri="http://www.springframework.org/tags/form" %>
|
||||
<%@ page contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>User Creation</title>
|
||||
<style type="text/css">
|
||||
input {
|
||||
padding: 0.25em 0.5em;
|
||||
border: 0.125em solid hsl(30, 76%, 10%);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Show green borders when valid */
|
||||
input[data-state="valid"] {
|
||||
border-color: hsl(120, 76%, 50%);
|
||||
}
|
||||
|
||||
/* Show red borders when filled, but invalid */
|
||||
input[data-state="invalid"] {
|
||||
border-color: hsl(0, 76%, 50%);
|
||||
}
|
||||
|
||||
.error-messages {
|
||||
display:none;
|
||||
}
|
||||
.error-messages[data-state="valid"] {
|
||||
display:none;
|
||||
}
|
||||
.error-messages[data-state="invalid"] {
|
||||
display:inline;
|
||||
color: hsl(0, 76%, 50%);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
document.getElementById("submit").disabled = true;
|
||||
|
||||
function checkIDBeginsWith900(){
|
||||
var userID = document.getElementById("userID");
|
||||
var error = document.getElementById("errorUserID");
|
||||
|
||||
var IDValue = userID.value;
|
||||
|
||||
if(IDValue - 900000000 > 0) {
|
||||
userID.dataset.state = 'valid';
|
||||
error.dataset.state = 'valid';
|
||||
} else {
|
||||
userID.dataset.state = 'invalid';
|
||||
error.dataset.state = 'invalid';
|
||||
}
|
||||
}
|
||||
|
||||
function checkValidUsername(){
|
||||
var username = document.getElementById("username");
|
||||
var error = document.getElementById("errorUsername");
|
||||
|
||||
var re = /^\w+$/;
|
||||
|
||||
if(re.test(username.value)){
|
||||
username.dataset.state = 'valid';
|
||||
error.dataset.state = 'valid';
|
||||
} else {
|
||||
username.dataset.state = 'invalid';
|
||||
error.dataset.state = 'invalid';
|
||||
}
|
||||
}
|
||||
|
||||
function checkValidPassword(){
|
||||
var password = document.getElementById("password");
|
||||
var error = document.getElementById("errorPassword");
|
||||
|
||||
var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
|
||||
|
||||
if(re.test(password.value)){
|
||||
password.dataset.state = 'valid';
|
||||
error.dataset.state = 'valid';
|
||||
} else {
|
||||
password.dataset.state = 'invalid';
|
||||
error.dataset.state = 'invalid';
|
||||
}
|
||||
}
|
||||
|
||||
function checkPasswordsMatch(){
|
||||
var confirmPassword = document.getElementById("confirmPassword");
|
||||
var password = document.getElementById("password");
|
||||
var error = document.getElementById("errorConfirmPassword");
|
||||
|
||||
if(password.value === confirmPassword.value){
|
||||
confirmPassword.dataset.state = 'valid';
|
||||
error.dataset.state = 'valid';
|
||||
} else {
|
||||
confirmPassword.dataset.state = 'invalid';
|
||||
error.dataset.state = 'invalid';
|
||||
}
|
||||
}
|
||||
|
||||
function checkAgreedToTerms(){
|
||||
var agreedToTerms = document.getElementById("agreedToTerms");
|
||||
var error = document.getElementById("errorAgreedToTerms");
|
||||
|
||||
if(agreedToTerms.checked === true){
|
||||
error.dataset.state = 'valid';
|
||||
document.getElementById("submit").disabled = false;
|
||||
return true;
|
||||
} else {
|
||||
error.dataset.state = 'invalid';
|
||||
document.getElementById("submit").disabled = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
New User Registration:
|
||||
<form method="post" action="" enctype="utf8">
|
||||
<label for="username">Username:
|
||||
<input type="text" name="username" id="username" onchange="checkValidUsername()"/>
|
||||
<div class="error-messages" id="errorUsername">Username must contain only letters, numbers, and underscores</div>
|
||||
</label>
|
||||
<br>
|
||||
<label for="password">Password:
|
||||
<input type="text" name="password" id="password" onchange="checkValidPassword()"/>
|
||||
<div class="error-messages" id="errorPassword">Password must be at least 8 characters long, including numbers, uppercase and lowercase letters.</div>
|
||||
</label>
|
||||
<br>
|
||||
<label for="confirmPassword">Confirm Password:
|
||||
<input type="text" name="confirmPassword" id="confirmPassword" onchange="checkPasswordsMatch()"/>
|
||||
<div class="error-messages" id="errorConfirmPassword">Passwords do not match</div>
|
||||
</label>
|
||||
<br>
|
||||
<label for="emailAddress">Email Address:
|
||||
<input type="text" name="emailAddress" id="emailAddress" />
|
||||
<div class="error-messages" id="errorEmailAddress">Invalid email address</div>
|
||||
</label>
|
||||
<br>
|
||||
<label for="agreedToTerms">I agree to the terms and conditions.
|
||||
<input type="checkbox" name="agreedToTerms" id="agreedToTerms" onclick="checkAgreedToTerms()"/>
|
||||
<div class="error-messages" id="errorAgreedToTerms">You must agree to the terms and conditions in order to register.</div>
|
||||
</label>
|
||||
<br>
|
||||
<input type="submit" id="submit" value="Submit" disabled="disabled"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -21,6 +21,8 @@
|
||||
<h2>Hello! Welcome to Pandamonium™ Theorem Prover!!</h2>
|
||||
|
||||
Click on this <strong><a href="/theorem/">link</a></strong> to visit theorem entering page.
|
||||
<h4 class="text-center"><a href="/login">Sign In</a></h4>
|
||||
<h4 class="text-center"><a href="/createuser">New here? Register</a></h4>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>You're Registered!</title>
|
||||
</head>
|
||||
<body>
|
||||
Thank you for joining!
|
||||
<br><b>Username: </b><%= request.getParameter("username")%>
|
||||
<br><b>Email Address: </b><%= request.getParameter("emailAddress")%>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,26 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import edu.msudenver.tsp.services.UserService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserCreationControllerTest {
|
||||
|
||||
private final UserService userService = mock(UserService.class);
|
||||
private final UserCreationController userCreationController = new UserCreationController(userService);
|
||||
|
||||
@Test
|
||||
public void testCreateUserPage() {
|
||||
final ModelAndView modelAndView = userCreationController.createUserPage();
|
||||
|
||||
assertNotNull(modelAndView);
|
||||
assertEquals("User", modelAndView.getViewName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user