Changed to Voting Mode

This commit is contained in:
2020-12-27 22:37:20 +01:00
parent 4005fd4edb
commit 0597edf116
4 changed files with 530 additions and 66 deletions

View File

@@ -25,16 +25,6 @@ import java.util.concurrent.ExecutionException;
@Controller
public class VotingController {
@Value("motto")
String motto;
@Value("adding")
String adding;
@Value("voting")
String voting;
private boolean votingPhase = false;
private boolean mottoPhase = false;
private boolean addingPhase = false;
@@ -67,8 +57,8 @@ public class VotingController {
@PostConstruct
public void init() {
mottoPhase = false;
votingPhase = false;
addingPhase = true;
votingPhase = true;
addingPhase = false;
LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase);
@@ -127,7 +117,6 @@ public class VotingController {
return "errors/alreadyVoted.html";
} else {
if (authCodesRepository.findByName(name) == null) {
LOGGER.warn("no code");
AuthCode authCode = tableAction.generateToken(name, RandomNumber.getRandomNumberString(), authCodesRepository);
sendSimpleMessage(name, "Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
} else if (authCodesRepository.findByName(name) != null && authCodesRepository.findByName(name).isExpired()) {
@@ -164,7 +153,6 @@ public class VotingController {
@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) {
@@ -244,15 +232,17 @@ public class VotingController {
@RequestMapping("/processVote")
public String ProcessVote(@RequestParam String name, @RequestParam String voteValues) {
if (voterRepository.findByEmail(name).getCandidatesubmit_status()) {
return "errors/alreadySubmitted.html";
if (voterRepository.findByEmail(name).getVote_status()) {
return "errors/alreadyVoted.html";
} else {
String[] partVoteValues = voteValues.split(",");
for (String s : partVoteValues) {
tableAction.voteForCandidate(s, candidateRepository);
if(!voteValues.equals("")) {
String[] partVoteValues = voteValues.split(",");
for (String s : partVoteValues) {
tableAction.voteForCandidate(s, candidateRepository);
}
LOGGER.info(name + " has voted!");
}
tableAction.updateVotingStatus(name, voterRepository);
LOGGER.info(name + " has voted!");
return "voteSuccessful.html";
}
}

View File

@@ -10,7 +10,6 @@
<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>
@@ -18,28 +17,6 @@
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>

View File

@@ -11,7 +11,6 @@
<div class="centered">
<h1>Deine Auswahl fließt nun in die Wahl ein!</h1>
<h2>Danke fürs abstimmen!</h2>
<h2 class="time_remain" id="time_remain">Nächste Abstimmung in: </h2>
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
</div>
</body>
@@ -20,28 +19,6 @@
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>
</html>