Must function now Email is down
This commit is contained in:
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
public class VotingController {
|
||||
@@ -110,16 +111,22 @@ public class VotingController {
|
||||
if (name.strip().toLowerCase().matches("[a-z]+\\.[a-z]+@adolfinum+\\.de$")) {
|
||||
try {
|
||||
LOGGER.warn(name);
|
||||
try {
|
||||
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
||||
} catch (Exception e){
|
||||
LOGGER.error(name + " is not allowed to vote");
|
||||
return "errors/notRegistered.html";
|
||||
}
|
||||
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
||||
if (voter.getVote_status() && votingPhase) {
|
||||
LOGGER.warn(name + " has already voted");
|
||||
return "errors/alreadyVoted.html";
|
||||
} else if (voter.getCandidatesubmit_status() && addingPhase) {
|
||||
LOGGER.warn(name + " has already submitted its candidates");
|
||||
return "errors/alreadysubmittedcandidates.html";
|
||||
return "errors/alreadyVoted.html";
|
||||
} else if (voter.getMotto_status() && mottoPhase) {
|
||||
LOGGER.warn(name + " has already chose their motto");
|
||||
return "errors/alreadyVotedForMotto.html";
|
||||
return "errors/alreadyVoted.html";
|
||||
} else {
|
||||
if (authCodesRepository.findByName(name) == null) {
|
||||
LOGGER.warn("no code");
|
||||
@@ -130,30 +137,43 @@ public class VotingController {
|
||||
sendSimpleMessage(name, "Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
|
||||
}
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("codeTime", authCodesRepository.findByName(name).getExpirationTime());
|
||||
model.addAttribute("codeExpired", false);
|
||||
model.addAttribute("codeFalse", false);
|
||||
return "authenticate.html";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(name + " is not allowed to vote");
|
||||
return "errors/notRegistered.html";
|
||||
tableAction.deleteToken(name, authCodesRepository);
|
||||
return "error.html";
|
||||
}
|
||||
} else {
|
||||
return "errors/falseInput.html";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/newCode")
|
||||
public String provideNewCode(@RequestParam String name, Model model){
|
||||
AuthCode authCode = tableAction.generateToken(name, RandomNumber.getRandomNumberString(), authCodesRepository);
|
||||
sendSimpleMessage(name, "Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("codeTime", authCodesRepository.findByName(name).getExpirationTime());
|
||||
model.addAttribute("codeExpired", false);
|
||||
model.addAttribute("codeFalse", false);
|
||||
return "authenticate.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/vote")
|
||||
public String voting_adding(@RequestParam String code, @RequestParam String name, Model model) {
|
||||
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
||||
|
||||
LOGGER.warn(code);
|
||||
if (tokenStatus.equals("matched")) {
|
||||
LOGGER.warn("matched");
|
||||
if (mottoPhase) {
|
||||
List<Motto> mottos = mottoRepository.findAll();
|
||||
model.addAttribute("mottos", mottos);
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("code", code);
|
||||
return "mottoVoting.html";
|
||||
} else if (addingPhase) {
|
||||
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
||||
@@ -164,11 +184,13 @@ public class VotingController {
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("form", possibleCandidates);
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("code", code);
|
||||
return "addingCandidates.html";
|
||||
} else if (votingPhase) {
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("code", code);
|
||||
return "voting.html";
|
||||
}
|
||||
} else if (tokenStatus.equals("expired")) {
|
||||
@@ -188,10 +210,11 @@ public class VotingController {
|
||||
}
|
||||
|
||||
@RequestMapping("/saveCandidates")
|
||||
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates, @RequestParam String name) {
|
||||
public String candidateSaving(@ModelAttribute PossibleCandidateWrapper possibleCandidates, @RequestParam String name, @RequestParam String code) {
|
||||
if (voterRepository.findByEmail(name).getVote_status()) {
|
||||
return "errors/alreadyVoted.html";
|
||||
} else {
|
||||
authCodesRepository.delete(authCodesRepository.findByName(code));
|
||||
LinkedList<PossibleCandidate> posCandidates = possibleCandidates.getPossibleCandidates();
|
||||
long index = 1;
|
||||
for (PossibleCandidate posCandidate : posCandidates) {
|
||||
@@ -213,11 +236,12 @@ public class VotingController {
|
||||
}
|
||||
|
||||
@RequestMapping("/saveMotto")
|
||||
public String mottoSaving(@RequestParam String name, @RequestParam String voteValue) {
|
||||
public String mottoSaving(@RequestParam String name, @RequestParam String voteValue, @RequestParam String code) {
|
||||
LOGGER.info(name);
|
||||
if (voterRepository.findByEmail(name).getMotto_status()) {
|
||||
return "errors/alreadySubmitted.html";
|
||||
} else {
|
||||
authCodesRepository.delete(authCodesRepository.findByName(code));
|
||||
tableAction.voteForMotto(voteValue, mottoRepository);
|
||||
tableAction.updateMottoStatus(name, voterRepository);
|
||||
LOGGER.info(name + " has choose his motto");
|
||||
@@ -226,10 +250,11 @@ public class VotingController {
|
||||
}
|
||||
|
||||
@RequestMapping("/processVote")
|
||||
public String ProcessVote(@RequestParam String name, @RequestParam String voteValues) {
|
||||
public String ProcessVote(@RequestParam String name, @RequestParam String voteValues, @RequestParam String code) {
|
||||
if (voterRepository.findByEmail(name).getCandidatesubmit_status()) {
|
||||
return "errors/alreadySubmitted.html";
|
||||
} else {
|
||||
authCodesRepository.delete(authCodesRepository.findByName(code));
|
||||
String[] partVoteValues = voteValues.split(",");
|
||||
for (String s : partVoteValues) {
|
||||
tableAction.voteForCandidate(s, candidateRepository);
|
||||
|
||||
@@ -37,6 +37,10 @@ public class AuthCode {
|
||||
return time;
|
||||
}
|
||||
|
||||
public long getExpirationTime(){
|
||||
return time + 1800*1000;
|
||||
}
|
||||
|
||||
public boolean isExpired(){
|
||||
return System.currentTimeMillis() >= (time + 1800*1000);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ public class TableAction {
|
||||
try {
|
||||
AuthCode authCode = authCodesRepository.findByName(name);
|
||||
if (authCode.getCode().equals(code) && !authCode.isExpired()) {
|
||||
authCodesRepository.delete(authCode);
|
||||
return "matched";
|
||||
} else if (authCode.isExpired()) {
|
||||
authCodesRepository.delete(authCode);
|
||||
@@ -67,6 +66,10 @@ public class TableAction {
|
||||
return "wrong";
|
||||
}
|
||||
|
||||
public void deleteToken(String name, AuthCodesRepository authCodesRepository){
|
||||
authCodesRepository.delete(authCodesRepository.findByName(name));
|
||||
}
|
||||
|
||||
private boolean fiveMinutesPassed(Long time){
|
||||
return System.currentTimeMillis() >= (time + 300*1000);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ h1 {
|
||||
font-size: 75px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #6d6d78;
|
||||
}
|
||||
|
||||
.submitButton {
|
||||
padding: .25em 0;
|
||||
border: 0;
|
||||
@@ -21,9 +21,12 @@ body {
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 5%;
|
||||
color: #FFF;
|
||||
margin-bottom: 5%;
|
||||
}
|
||||
|
||||
h1.end {
|
||||
color: #6d6d78;
|
||||
margin-bottom: 2%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
@@ -41,7 +44,7 @@ input {
|
||||
|
||||
.submitButton {
|
||||
margin-top: 5%;
|
||||
margin-bottom: 5%;
|
||||
margin-bottom: 1%;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
background: #bb1515;
|
||||
@@ -54,6 +57,19 @@ input {
|
||||
text-shadow: 0 -2px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.newCode {
|
||||
border: 0;
|
||||
outline: 0;
|
||||
background: #bb1515;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
font-size: 1rem;
|
||||
width: 250px;
|
||||
letter-spacing: .0625rem;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 3px 5px 1px rgba(0, 0, 0, 0.25);
|
||||
text-shadow: 0 -2px 0 rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.errorCode {
|
||||
margin-top: 10%;
|
||||
color: #bb1515;
|
||||
|
||||
@@ -10,14 +10,9 @@
|
||||
|
||||
<body class="center-screen">
|
||||
|
||||
<script>
|
||||
var scale = Math.min(
|
||||
availableWidth / contentWidth,
|
||||
availableHeight / contentHeight
|
||||
);
|
||||
</script>
|
||||
|
||||
<h1 th:text="|Dir wurde ein Code an ${name} gesendet!|"></h1>
|
||||
<h1>Nicht wundern das kann ein wenig dauern!</h1>
|
||||
<h1 id="time_remain" class="end" th:text="${codeTime}"></h1>
|
||||
<h2>Bitte gebe den Authentifizierungscode ein</h2>
|
||||
<form action="#" id="passForm" th:action="@{/vote}" method="post">
|
||||
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
||||
@@ -28,11 +23,18 @@
|
||||
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
||||
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
||||
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
||||
|
||||
</form>
|
||||
<button class="submitButton" id="signup_button" onclick="getCode()">Abstimmen</button>
|
||||
|
||||
|
||||
<form action="#" th:action="@{/newCode}" method="post">
|
||||
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
||||
<button class="newCode">Neuen Code anfordern</button>
|
||||
</form>
|
||||
|
||||
|
||||
<div th:if="${codeExpired}">
|
||||
<h2 class="errorCode">Der Code ist nicht mehr gültig!<br>Fordere einen neuen an</h2>
|
||||
<h2 class="errorCode">Der Code ist nicht mehr gültig!</h2>
|
||||
</div>
|
||||
|
||||
<div th:if="${codeFalse}">
|
||||
@@ -76,6 +78,33 @@
|
||||
output.value = code;
|
||||
document.getElementById("passForm").submit();
|
||||
}
|
||||
|
||||
function updateCounter(time) {
|
||||
const zeroPad = (num, places) => String(num).padStart(places, '0')
|
||||
|
||||
// Show time remaining now.
|
||||
showTimeRemaining();
|
||||
|
||||
var dateFuture = time;
|
||||
console.log(dateFuture);
|
||||
|
||||
// Set a timer to update the displayed clock every 1000 milliseconds.
|
||||
var updateTimeLoop = setInterval(showTimeRemaining, 1000);
|
||||
|
||||
function showTimeRemaining() {
|
||||
var dateNow = Date.now();
|
||||
var days = zeroPad(Math.floor((dateFuture - dateNow) / (1000 * 60 * 60 * 24)), 2);
|
||||
var hours = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24) / (1000 * 60 * 60)), 2);
|
||||
var mins = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60) / (1000 * 60)), 2);
|
||||
var secs = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60 - mins * 1000 * 60) / 1000), 2);
|
||||
document.getElementById("time_remain").innerHTML = "Der Code gilt noch für " + mins + ":" + secs;
|
||||
if (hours + mins + secs == 0) {
|
||||
document.getElementById("time_remain").innerHTML = "Der Code ist abgelaufen";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateCounter(document.getElementById("time_remain").innerHTML);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="de" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<body>
|
||||
<h1>Something went wrong! </h1>
|
||||
<h2>Our Engineers are on it</h2>
|
||||
<a href="/">Go Home</a>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/allreadyVoted.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body class="center-screen">
|
||||
<div class="centered">
|
||||
<h1>Oops irgendwas ist kaputt gegangen</h1>
|
||||
<h2 id="time_remain">Keine Sorge! <br> Probiers nochmal :D</h2>
|
||||
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("backButton").onclick = function() {
|
||||
location.href = "/";
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -3,12 +3,44 @@
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/allreadyVoted.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 style="color: red;"> Jeder darf nur einmal abstimmen! </h1>
|
||||
<a href="/">Return to Login-Site</a>
|
||||
<body class="center-screen">
|
||||
<div class="centered">
|
||||
<h1>Du hast schon abgestimmt!</h1>
|
||||
<h2 id="time_remain">Nächste Abstimmung in: </h2>
|
||||
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("backButton").onclick = function() {
|
||||
location.href = "/";
|
||||
};
|
||||
|
||||
const zeroPad = (num, places) => String(num).padStart(places, '0')
|
||||
|
||||
// We can set endTime to whatever we want here (e.g. Midnight today )
|
||||
// Use moment().endOf('day') to do this.
|
||||
var dateFuture = new Date(2020, 11, 28, 0, 0);
|
||||
|
||||
// Show time remaining now.
|
||||
showTimeRemaining();
|
||||
|
||||
// Set a timer to update the displayed clock every 1000 milliseconds.
|
||||
setInterval(showTimeRemaining, 1000);
|
||||
|
||||
function showTimeRemaining() {
|
||||
var dateNow = Date.now();
|
||||
var days = zeroPad(Math.floor((dateFuture - dateNow) / (1000 * 60 * 60 * 24)), 2);
|
||||
var hours = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24) / (1000 * 60 * 60)), 2);
|
||||
var mins = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60) / (1000 * 60)), 2);
|
||||
var secs = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60 - mins * 1000 * 60) / 1000), 2);
|
||||
document.getElementById("time_remain").innerHTML = "Nächste Abstimmung in: " + days + "D " + hours + ":" + mins + ":" + secs;
|
||||
console.log("Nächste Abstimmung in: " + days + "D " + hours + ":" + mins + ":" + secs);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1 style="color: red;">Du hast deine Motto schon gewählt!</h1>
|
||||
<a href="/">Return to Login-Site</a>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,44 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/alreadysubmittedcandidates.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body class="center-screen">
|
||||
<div class="centered">
|
||||
<h1>Du hast schon abgestimmt!</h1>
|
||||
<h2 id="time_remain">Nächste Abstimmung in: </h2>
|
||||
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("backButton").onclick = function() {
|
||||
location.href = "/";
|
||||
};
|
||||
|
||||
// We can set endTime to whatever we want here (e.g. Midnight today )
|
||||
// Use moment().endOf('day') to do this.
|
||||
var dateFuture = new Date(2020, 11, 28, 0, 0);
|
||||
|
||||
// Show time remaining now.
|
||||
showTimeRemaining();
|
||||
|
||||
// Set a timer to update the displayed clock every 1000 milliseconds.
|
||||
setInterval(showTimeRemaining, 1000);
|
||||
|
||||
function showTimeRemaining() {
|
||||
var dateNow = Date.now();
|
||||
var days = Math.floor((dateFuture - dateNow) / (1000 * 60 * 60 * 24));
|
||||
var hours = Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24) / (1000 * 60 * 60));
|
||||
var mins = Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60) / (1000 * 60));
|
||||
var secs = Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60 - mins * 1000 * 60) / 1000);
|
||||
document.getElementById("time_remain").innerHTML = "Nächste Abstimmung in: " + days + "D " + hours + ":" + mins + ":" + secs;
|
||||
console.log("Nächste Abstimmung in: " + days + "D " + hours + ":" + mins + ":" + secs);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,14 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="de" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/allreadyVoted.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1> Überprüfe noch einmal die eingegebene E-Mail Adresse Sollte der Fall eintreten, dass du deine E-Mail Adresse richtig eingegeben hast und du Schüler der Q2 bist, schreibe eine Mail an simon.bussmann@adolfinum.de mit dem Betreff LoginFehler</h1>
|
||||
<a href="/">Return to Login-Site</a>
|
||||
<body class="center-screen">
|
||||
<div class="centered">
|
||||
<h1>Du bist nicht zur Wahl zugelassen!</h1>
|
||||
<h2 id="time_remain">Falls du abstimmen können solltest <br> schreibe eine Mail an adolfinumvoting@gmail.com</h2>
|
||||
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("backButton").onclick = function() {
|
||||
location.href = "/";
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user