Changed to Voting Mode
This commit is contained in:
+7
-17
@@ -25,16 +25,6 @@ import java.util.concurrent.ExecutionException;
|
|||||||
@Controller
|
@Controller
|
||||||
public class VotingController {
|
public class VotingController {
|
||||||
|
|
||||||
|
|
||||||
@Value("motto")
|
|
||||||
String motto;
|
|
||||||
|
|
||||||
@Value("adding")
|
|
||||||
String adding;
|
|
||||||
|
|
||||||
@Value("voting")
|
|
||||||
String voting;
|
|
||||||
|
|
||||||
private boolean votingPhase = false;
|
private boolean votingPhase = false;
|
||||||
private boolean mottoPhase = false;
|
private boolean mottoPhase = false;
|
||||||
private boolean addingPhase = false;
|
private boolean addingPhase = false;
|
||||||
@@ -67,8 +57,8 @@ public class VotingController {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
mottoPhase = false;
|
mottoPhase = false;
|
||||||
votingPhase = false;
|
votingPhase = true;
|
||||||
addingPhase = true;
|
addingPhase = false;
|
||||||
|
|
||||||
LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase);
|
LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase);
|
||||||
|
|
||||||
@@ -127,7 +117,6 @@ public class VotingController {
|
|||||||
return "errors/alreadyVoted.html";
|
return "errors/alreadyVoted.html";
|
||||||
} else {
|
} else {
|
||||||
if (authCodesRepository.findByName(name) == null) {
|
if (authCodesRepository.findByName(name) == null) {
|
||||||
LOGGER.warn("no code");
|
|
||||||
AuthCode authCode = tableAction.generateToken(name, RandomNumber.getRandomNumberString(), authCodesRepository);
|
AuthCode authCode = tableAction.generateToken(name, RandomNumber.getRandomNumberString(), authCodesRepository);
|
||||||
sendSimpleMessage(name, "Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
|
sendSimpleMessage(name, "Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
|
||||||
} else if (authCodesRepository.findByName(name) != null && authCodesRepository.findByName(name).isExpired()) {
|
} else if (authCodesRepository.findByName(name) != null && authCodesRepository.findByName(name).isExpired()) {
|
||||||
@@ -164,7 +153,6 @@ public class VotingController {
|
|||||||
@RequestMapping("/vote")
|
@RequestMapping("/vote")
|
||||||
public String voting_adding(@RequestParam String code, @RequestParam String name, Model model) {
|
public String voting_adding(@RequestParam String code, @RequestParam String name, Model model) {
|
||||||
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
||||||
LOGGER.warn(code);
|
|
||||||
if (tokenStatus.equals("matched")) {
|
if (tokenStatus.equals("matched")) {
|
||||||
LOGGER.warn("matched");
|
LOGGER.warn("matched");
|
||||||
if (mottoPhase) {
|
if (mottoPhase) {
|
||||||
@@ -244,15 +232,17 @@ public class VotingController {
|
|||||||
|
|
||||||
@RequestMapping("/processVote")
|
@RequestMapping("/processVote")
|
||||||
public String ProcessVote(@RequestParam String name, @RequestParam String voteValues) {
|
public String ProcessVote(@RequestParam String name, @RequestParam String voteValues) {
|
||||||
if (voterRepository.findByEmail(name).getCandidatesubmit_status()) {
|
if (voterRepository.findByEmail(name).getVote_status()) {
|
||||||
return "errors/alreadySubmitted.html";
|
return "errors/alreadyVoted.html";
|
||||||
} else {
|
} else {
|
||||||
|
if(!voteValues.equals("")) {
|
||||||
String[] partVoteValues = voteValues.split(",");
|
String[] partVoteValues = voteValues.split(",");
|
||||||
for (String s : partVoteValues) {
|
for (String s : partVoteValues) {
|
||||||
tableAction.voteForCandidate(s, candidateRepository);
|
tableAction.voteForCandidate(s, candidateRepository);
|
||||||
}
|
}
|
||||||
tableAction.updateVotingStatus(name, voterRepository);
|
|
||||||
LOGGER.info(name + " has voted!");
|
LOGGER.info(name + " has voted!");
|
||||||
|
}
|
||||||
|
tableAction.updateVotingStatus(name, voterRepository);
|
||||||
return "voteSuccessful.html";
|
return "voteSuccessful.html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
<body class="center-screen">
|
<body class="center-screen">
|
||||||
<div class="centered">
|
<div class="centered">
|
||||||
<h1>Du hast schon abgestimmt!</h1>
|
<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>
|
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -18,28 +17,6 @@
|
|||||||
document.getElementById("backButton").onclick = function() {
|
document.getElementById("backButton").onclick = function() {
|
||||||
location.href = "/";
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
<div class="centered">
|
<div class="centered">
|
||||||
<h1>Deine Auswahl fließt nun in die Wahl ein!</h1>
|
<h1>Deine Auswahl fließt nun in die Wahl ein!</h1>
|
||||||
<h2>Danke fürs abstimmen!</h2>
|
<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>
|
<button id="backButton" class="submitButton">Zurück zum Anfang</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
@@ -20,28 +19,6 @@
|
|||||||
document.getElementById("backButton").onclick = function() {
|
document.getElementById("backButton").onclick = function() {
|
||||||
location.href = "/";
|
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>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user