You know the drill
This commit is contained in:
@@ -26,7 +26,7 @@ import java.util.*;
|
||||
@Controller
|
||||
public class VotingController {
|
||||
|
||||
private Boolean candidatesAdded = true;
|
||||
private Boolean candidatesAdded = false;
|
||||
private static final Logger LOGGER = LogManager.getLogger(VotingController.class);
|
||||
private TableAction tableAction = new TableAction();
|
||||
|
||||
@@ -51,7 +51,6 @@ public class VotingController {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
LOGGER.info("setups");
|
||||
if (voterRepository.findAll().size() == 0) {
|
||||
tableAction.setUpVoters(voterRepository);
|
||||
LOGGER.info("Voters successfully set up");
|
||||
@@ -86,6 +85,7 @@ public class VotingController {
|
||||
public String VerifyName(@RequestParam String name, Model model) {
|
||||
if (name.strip().toLowerCase().matches("[a-z]+\\.[a-z]+@adolfinum+\\.de$")) {
|
||||
try {
|
||||
LOGGER.warn(name);
|
||||
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
||||
if (voter.getVote_status()) {
|
||||
LOGGER.warn(name + " has already voted");
|
||||
@@ -97,9 +97,12 @@ public class VotingController {
|
||||
AuthCode authCode = tableAction.generateToken(name, RandomNumber.getRandomNumberString(), authCodesRepository);
|
||||
sendSimpleMessage(name,"Code zur Authentifizierung", "Dein Code lautet: " + authCode.getCode());
|
||||
model.addAttribute("name", name);
|
||||
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";
|
||||
}
|
||||
@@ -109,23 +112,40 @@ public class VotingController {
|
||||
}
|
||||
|
||||
@RequestMapping("/vote")
|
||||
public String voting_adding(@RequestParam String name, Model model){
|
||||
if(candidatesAdded) {
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("name", name);
|
||||
return "voting.html";
|
||||
} else {
|
||||
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
for (int i = 0; i < categories.size(); i++){
|
||||
possibleCandidates.addPossibleCandidate(new PossibleCandidate());
|
||||
}
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("form", possibleCandidates);
|
||||
model.addAttribute("name", name);
|
||||
return "addingCandidates.html";
|
||||
public String voting_adding(@RequestParam String code,@RequestParam String name, Model model){
|
||||
switch (tableAction.checkToken(name, code, authCodesRepository)){
|
||||
case "matched":
|
||||
LOGGER.warn("matched");
|
||||
if(candidatesAdded) {
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("name", name);
|
||||
return "voting.html";
|
||||
} else {
|
||||
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
||||
List<Category> categories = categoryRepository.findAll();
|
||||
for (int i = 0; i < categories.size(); i++){
|
||||
possibleCandidates.addPossibleCandidate(new PossibleCandidate());
|
||||
}
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("form", possibleCandidates);
|
||||
model.addAttribute("name", name);
|
||||
return "addingCandidates.html";
|
||||
}
|
||||
|
||||
case "expired":
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("codeExpired", true);
|
||||
model.addAttribute("codeFalse", false);
|
||||
return "authenticate.html";
|
||||
|
||||
case "wrong":
|
||||
model.addAttribute("name", name);
|
||||
model.addAttribute("codeExpired", false);
|
||||
model.addAttribute("codeFalse", true);
|
||||
return "authenticate.html";
|
||||
}
|
||||
return "fatalError";
|
||||
}
|
||||
|
||||
@RequestMapping("/saveCandidates")
|
||||
@@ -148,7 +168,7 @@ public class VotingController {
|
||||
}
|
||||
index++;
|
||||
}
|
||||
//tableAction.updateCandidatesubmit_status(voterEmail, voterRepository);
|
||||
tableAction.updateCandidatesubmit_status(name, voterRepository);
|
||||
return "candidateAddingSuccessful.html";
|
||||
}
|
||||
}
|
||||
@@ -162,7 +182,7 @@ public class VotingController {
|
||||
for (String s : partVoteValues) {
|
||||
tableAction.voteFor(s, candidateRepository);
|
||||
}
|
||||
//tableAction.updateVotingStatus(voterEmail, voterRepository);
|
||||
tableAction.updateVotingStatus(name, voterRepository);
|
||||
LOGGER.info(name + " has voted!");
|
||||
return "voteSuccessful.html";
|
||||
}
|
||||
|
||||
@@ -36,4 +36,12 @@ public class AuthCode {
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.AuthCode;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface AuthCodesRepository extends JpaRepository<AuthCode, Integer> {
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ import org.aspectj.weaver.loadtime.definition.LightXMLParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.*;
|
||||
|
||||
public class TableAction {
|
||||
@@ -39,10 +43,13 @@ public class TableAction {
|
||||
|
||||
public AuthCode generateToken(String name, String code, AuthCodesRepository authCodesRepository) {
|
||||
AuthCode authCode = new AuthCode(name, code);
|
||||
if (authCodesRepository.findByName(authCode.getName()) != null) {
|
||||
authCodesRepository.findByName(authCode.getName()).setCode(authCode.getCode());
|
||||
return authCode;
|
||||
} else {
|
||||
try{
|
||||
AuthCode existingCode = authCodesRepository.findByName(authCode.getName());
|
||||
existingCode.setCode(code);
|
||||
existingCode.setTime(System.currentTimeMillis());
|
||||
authCodesRepository.save(existingCode);
|
||||
return existingCode;
|
||||
} catch (Exception e){
|
||||
authCodesRepository.save(authCode);
|
||||
return authCode;
|
||||
}
|
||||
@@ -74,7 +81,8 @@ public class TableAction {
|
||||
|
||||
public void setUpVoters(VoterRepository voterRepository){
|
||||
try {
|
||||
File emailFile = new File("src/main/resources/Q2_emails.txt");
|
||||
String path = "src/main/resources/Q2_emails.txt";
|
||||
File emailFile = new File(path);
|
||||
Scanner myReader = new Scanner(emailFile);
|
||||
ArrayList<Voter> voters = new ArrayList<Voter>();
|
||||
while (myReader.hasNextLine()) {
|
||||
@@ -104,9 +112,9 @@ public class TableAction {
|
||||
}
|
||||
|
||||
public void setUpCategories(CategoryRepository categoryRepository){
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
try {
|
||||
File categoryFile = new File("src/main/resources/Categories.txt");
|
||||
String path = "src/main/resources/Categories.txt";
|
||||
File categoryFile = new File(path);
|
||||
Scanner myReader = new Scanner(categoryFile);
|
||||
ArrayList<Category> categories = new ArrayList<Category>();
|
||||
while (myReader.hasNextLine()) {
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
1. Wer wird nie von zuhause ausziehen? (Schüler)
|
||||
1. Wer ist der/die kreativste Zuspätkommer/in (Schüler)
|
||||
1. Mit wem wird man am ehesten in der Zukunft angeben zur Schule gegangen zu sein? (Schüler)
|
||||
1. Wer wohnt im Fittnessstudio? (Schüler)
|
||||
1. Wer ist der coolste Leherer?
|
||||
1. Wer ist die coolste Lehrerin?
|
||||
1. Wer macht den besten Matheunterricht?
|
||||
1. Welcher Lehrer hat den Beruf verfehlt?
|
||||
1. Welcher Lehrer ist nie da?
|
||||
1. Wer hat das Internet erfunden?
|
||||
1. Wer sponsort Schollin? (Schüler)
|
||||
1. Wer ist am engagiertesten? (Schüler)
|
||||
1. Wer wird Bundeskanzler? (Schüler)
|
||||
1. Wer hat das Kimpeltum gegründet? (Schüler)
|
||||
1. Wer saß am längsten im Klassenschrank? (Schüler)
|
||||
1. Wer hat die gößte Sauklaue? (Leherer)
|
||||
1. Wer gründet das nächste Google? (Schüler)
|
||||
1. Wer kommt am schnellsten in den Knast? (Schüler)
|
||||
1. Top 3-Pärchen? (Schüler)
|
||||
1. Top 3 Lehrergespanne? (Schüler)
|
||||
1. Wer ist der motiviertester Lehrer?
|
||||
1. Wer ist Google auf zwei Beinen(Schüler)?
|
||||
1. Wer hat den besten Style (Schüler)?
|
||||
1. Wer hat den besten Style (Lehrer)?
|
||||
1. Wer währe ein gutes Pärchen (Lehrer)?
|
||||
1. Wer trinkt am meisten Kaffe (Schüler)?
|
||||
1. Wer trinkt am meisten Kaffe (Lehrer)?
|
||||
1. Tischflip?
|
||||
1. Wer wird Harzer?
|
||||
1. Wer hat Wiedererkennungswert (Schüler)?
|
||||
1. Wen erkennt man an der Lache (Schüler)?
|
||||
1. Wer bringt die dümmsten Witze? (Lehrer)
|
||||
1. Wer hat den meisten Schwachsinn erzählt? (Lehrer)
|
||||
1. Welche Lehrer machen nie das, was die Schüler wollten? (Lehrer)
|
||||
1. Wer isst immer? (Lehrer)
|
||||
1. Wer hat die meisten peinlichen Momente gebracht?
|
||||
Wer wird nie von zuhause ausziehen?
|
||||
Wer ist der/die kreativste Zuspätkommer/in?
|
||||
Mit wem wird man am ehesten in der Zukunft angeben zur Schule gegangen zu sein?
|
||||
Wer wohnt im Fittnessstudio? (Schüler)
|
||||
Wer ist der coolste Leherer?
|
||||
Wer ist die coolste Lehrerin?
|
||||
Wer macht den besten Matheunterricht?
|
||||
Welcher Lehrer hat den Beruf verfehlt?
|
||||
Welcher Lehrer ist nie da?
|
||||
Wer hat das Internet erfunden?
|
||||
Wer sponsort Schollin? (Schüler)
|
||||
Wer ist am engagiertesten? (Schüler)
|
||||
Wer wird Bundeskanzler? (Schüler)
|
||||
Wer hat das Kimpeltum gegründet? (Schüler)
|
||||
Wer saß am längsten im Klassenschrank? (Schüler)
|
||||
Wer hat die gößte Sauklaue? (Leherer)
|
||||
Wer gründet das nächste Google? (Schüler)
|
||||
Wer kommt am schnellsten in den Knast? (Schüler)
|
||||
Top 3-Pärchen? (Schüler)
|
||||
Top 3 Lehrergespanne? (Schüler)
|
||||
Wer ist der motiviertester Lehrer?
|
||||
Wer ist Google auf zwei Beinen(Schüler)?
|
||||
Wer hat den besten Style (Schüler)?
|
||||
Wer hat den besten Style (Lehrer)?
|
||||
Wer währe ein gutes Pärchen (Lehrer)?
|
||||
Wer trinkt am meisten Kaffe (Schüler)?
|
||||
Wer trinkt am meisten Kaffe (Lehrer)?
|
||||
Tischflip?
|
||||
Wer wird Harzer?
|
||||
Wer hat Wiedererkennungswert (Schüler)?
|
||||
Wen erkennt man an der Lache (Schüler)?
|
||||
Wer bringt die dümmsten Witze? (Lehrer)
|
||||
Wer hat den meisten Schwachsinn erzählt? (Lehrer)
|
||||
Welche Lehrer machen nie das, was die Schüler wollten? (Lehrer)
|
||||
Wer isst immer? (Lehrer)
|
||||
Wer hat die meisten peinlichen Momente gebracht?
|
||||
@@ -25,7 +25,7 @@ h1 {
|
||||
margin-bottom: 5%;
|
||||
}
|
||||
|
||||
h2.categoryHeader {
|
||||
h2 {
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ input {
|
||||
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;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
|
||||
@@ -2,7 +2,9 @@ td.voted {
|
||||
background-color: #f05048;
|
||||
}
|
||||
|
||||
td.submitted {}
|
||||
td.submitted {
|
||||
background-color: #dbc95e;
|
||||
}
|
||||
|
||||
td.notVoted {
|
||||
background-color: #76ed6b;
|
||||
|
||||
@@ -35,12 +35,26 @@
|
||||
if (!this.value && ev.key === "Backspace" && i) $inp.eq(i - 1).focus();
|
||||
}
|
||||
});
|
||||
|
||||
function getCode() {
|
||||
groupInputs = document.querySelectorAll(".passInput");
|
||||
var code = "";
|
||||
groupInputs.forEach(input => {
|
||||
console.log("Input: " + input.value);
|
||||
code += input.value;
|
||||
});
|
||||
console.log("Code: " + code);
|
||||
output = document.getElementById("authCode");
|
||||
output.value = code;
|
||||
document.getElementById("passForm").submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1 th:text="|Dir wurde eine Email an ${name} gesendet!|"></h1>
|
||||
<h2>Gebe den enthaltenen Authentifizierungscode ein</h2>
|
||||
<h1 th:text="|Dir wurde ein Code an ${name} gesendet!|"></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}" />
|
||||
<input id="authCode" type="hidden" name="code" value="" />
|
||||
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}" autofocus>
|
||||
<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}">
|
||||
@@ -48,8 +62,15 @@
|
||||
<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}">
|
||||
|
||||
<button type="submit" id="signup_button">Abstimmen</button>
|
||||
</form>
|
||||
<button class="submitButton" id="signup_button" onclick="getCode()">Abstimmen</button>
|
||||
<div th:if="${codeExpired}">
|
||||
<h2 class="errorCode">Der Code ist nicht mehr gültig!<br>Fordere einen neuen an</h2>
|
||||
</div>
|
||||
|
||||
<div th:if="${codeFalse}">
|
||||
<h2 class="errorCode">Der eingegebene Code ist falsch</h2>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
@@ -18,31 +18,30 @@
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="voter : ${voters}">
|
||||
<div th:if="${voter.candidatesubmit_status}">
|
||||
<td class="submitted" th:text="${voter.id}"></td>
|
||||
<td class="submitted" th:text="${voter.email}"></td>
|
||||
<td class="submitted" th:text="Candidates submitted"></td>
|
||||
</div>
|
||||
|
||||
<!-- If voter has voted -->
|
||||
<div th:if="${voter.vote_status}">
|
||||
<td class="voted" th:text="${voter.id}"></td>
|
||||
<td class="voted" th:text="${voter.email}"></td>
|
||||
<td class="voted" th:text="Voted"></td>
|
||||
</div>
|
||||
|
||||
<!-- ELSE -->
|
||||
<div th:unless="${voter.vote_status}">
|
||||
<td class="notVoted" th:text="${voter.id}"></td>
|
||||
<td class="notVoted" th:text="${voter.email}"></td>
|
||||
<td class="notVoted" th:text="$Not voted"></td>
|
||||
<div th:if="${voter.candidatesubmit_status}">
|
||||
<td class="submitted" th:text="${voter.id}"></td>
|
||||
<td class="submitted" th:text="${voter.email}"></td>
|
||||
</div>
|
||||
<div th:unless="${voter.candidatesubmit_status}">
|
||||
<td class="notVoted" th:text="${voter.id}"></td>
|
||||
<td class="notVoted" th:text="${voter.email}"></td>
|
||||
</div>
|
||||
</div>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<h1>Kandidaten Liste</h1>
|
||||
|
||||
Reference in New Issue
Block a user