Have to go to bed now need to write
This commit is contained in:
3864
logs/Voting.log
3864
logs/Voting.log
File diff suppressed because it is too large
Load Diff
26
pom.xml
26
pom.xml
@@ -1,19 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.3.4.RELEASE</version>
|
<version>2.3.4.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/>
|
||||||
|
<!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.github.cato447</groupId>
|
<groupId>com.github.cato447</groupId>
|
||||||
<artifactId>AbizeitungVotingSystem</artifactId>
|
<artifactId>AbiVoting</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>1.0</version>
|
||||||
<name>AbizeitungVotingSystem</name>
|
<name>AbizeitungVotingSystem</name>
|
||||||
<description>A Voting System to get voting information for our graduating book</description>
|
<description>A Voting System to get voting information for our graduating book</description>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>ssh-repository</id>
|
||||||
|
<url>scpexe://81.169.149.143/program</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -74,6 +82,14 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
<extensions>
|
||||||
|
<!-- Enabling the use of SSH -->
|
||||||
|
<extension>
|
||||||
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
|
<artifactId>wagon-ssh-external</artifactId>
|
||||||
|
<version>2.10</version>
|
||||||
|
</extension>
|
||||||
|
</extensions>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.github.cato447.AbizeitungVotingSystem;
|
package com.github.cato447.AbizeitungVotingSystem;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
|
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableJpaRepositories
|
@EnableJpaRepositories
|
||||||
public class AbizeitungVotingSystemApplication {
|
public class AbizeitungVotingSystemApplication {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.github.cato447.AbizeitungVotingSystem.controller;
|
package com.github.cato447.AbizeitungVotingSystem.controller;
|
||||||
|
|
||||||
import com.github.cato447.AbizeitungVotingSystem.entities.AuthCode;
|
import com.github.cato447.AbizeitungVotingSystem.entities.*;
|
||||||
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
|
||||||
import com.github.cato447.AbizeitungVotingSystem.entities.PossibleCandidate;
|
|
||||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
|
||||||
import com.github.cato447.AbizeitungVotingSystem.helper.PossibleCandidateWrapper;
|
import com.github.cato447.AbizeitungVotingSystem.helper.PossibleCandidateWrapper;
|
||||||
import com.github.cato447.AbizeitungVotingSystem.helper.RandomNumber;
|
import com.github.cato447.AbizeitungVotingSystem.helper.RandomNumber;
|
||||||
import com.github.cato447.AbizeitungVotingSystem.repositories.*;
|
import com.github.cato447.AbizeitungVotingSystem.repositories.*;
|
||||||
@@ -26,8 +23,9 @@ import java.util.*;
|
|||||||
@Controller
|
@Controller
|
||||||
public class VotingController {
|
public class VotingController {
|
||||||
|
|
||||||
|
private boolean votingPhase;
|
||||||
private boolean votingPhase = false;
|
private boolean mottoPhase;
|
||||||
|
private boolean addingPhase;
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(VotingController.class);
|
private static final Logger LOGGER = LogManager.getLogger(VotingController.class);
|
||||||
private TableAction tableAction = new TableAction();
|
private TableAction tableAction = new TableAction();
|
||||||
@@ -41,6 +39,9 @@ public class VotingController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
CategoryRepository categoryRepository;
|
CategoryRepository categoryRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MottoRepository mottoRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
PossibleCandidateRepository possibleCandidateRepository;
|
PossibleCandidateRepository possibleCandidateRepository;
|
||||||
|
|
||||||
@@ -54,16 +55,31 @@ public class VotingController {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
try {
|
||||||
String mode = System.getProperty("votingPhase");
|
String votingPhaseConfig = System.getProperty("votingPhase");
|
||||||
if (mode.equalsIgnoreCase("true")) {
|
if (votingPhaseConfig.equalsIgnoreCase("true")) {
|
||||||
votingPhase = true;
|
votingPhase = true;
|
||||||
} else {
|
}
|
||||||
votingPhase = false;
|
|
||||||
|
String mottoVotingConfig = System.getProperty("mottoVoting");
|
||||||
|
if (mottoVotingConfig.equalsIgnoreCase("true")) {
|
||||||
|
mottoPhase = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String addingPhaseConfig = System.getProperty("addingPhase");
|
||||||
|
if (addingPhaseConfig.equalsIgnoreCase("true")){
|
||||||
|
addingPhase = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
votingPhase = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// //TODO: TESTING REMOVE ON SHIPPING
|
||||||
|
// votingPhase = false;
|
||||||
|
// mottoPhase = true;
|
||||||
|
// addingPhase = false;
|
||||||
|
|
||||||
|
LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoVoting=" + mottoPhase + " addingPhase=" + addingPhase);
|
||||||
|
|
||||||
if (voterRepository.findAll().size() == 0) {
|
if (voterRepository.findAll().size() == 0) {
|
||||||
tableAction.setUpVoters(voterRepository);
|
tableAction.setUpVoters(voterRepository);
|
||||||
LOGGER.info("Voters successfully set up");
|
LOGGER.info("Voters successfully set up");
|
||||||
@@ -74,11 +90,15 @@ public class VotingController {
|
|||||||
LOGGER.info("Categories successfully set up");
|
LOGGER.info("Categories successfully set up");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mottoRepository.findAll().size() == 0){
|
||||||
|
tableAction.setUpMottos(mottoRepository);
|
||||||
|
LOGGER.info("Mottos successfully set up");
|
||||||
|
}
|
||||||
|
|
||||||
if (candidateRepository.findAll().size() == 0 && votingPhase == true && possibleCandidateRepository.findAll().size() != 0) {
|
if (candidateRepository.findAll().size() == 0 && votingPhase == true && possibleCandidateRepository.findAll().size() != 0) {
|
||||||
tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository);
|
tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository);
|
||||||
LOGGER.info("Candidates successfully set up");
|
LOGGER.info("Candidates successfully set up");
|
||||||
}
|
}
|
||||||
LOGGER.info(votingPhase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
@@ -86,8 +106,7 @@ public class VotingController {
|
|||||||
return "start.html";
|
return "start.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendSimpleMessage(
|
public void sendSimpleMessage(String to, String subject, String text) {
|
||||||
String to, String subject, String text) {
|
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
SimpleMailMessage message = new SimpleMailMessage();
|
||||||
message.setTo(to);
|
message.setTo(to);
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
@@ -101,14 +120,18 @@ public class VotingController {
|
|||||||
try {
|
try {
|
||||||
LOGGER.warn(name);
|
LOGGER.warn(name);
|
||||||
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
Voter voter = voterRepository.findByEmail(name.toLowerCase().strip());
|
||||||
if (voter.getVote_status()) {
|
if (voter.getVote_status() && votingPhase) {
|
||||||
LOGGER.warn(name + " has already voted");
|
LOGGER.warn(name + " has already voted");
|
||||||
return "errors/alreadyVoted.html";
|
return "errors/alreadyVoted.html";
|
||||||
} else if (voter.getCandidatesubmit_status() && votingPhase == false) {
|
} else if (voter.getCandidatesubmit_status() && addingPhase) {
|
||||||
LOGGER.warn(name + " has already submitted its candidates");
|
LOGGER.warn(name + " has already submitted its candidates");
|
||||||
return "errors/alreadysubmittedcandidates.html";
|
return "errors/alreadysubmittedcandidates.html";
|
||||||
|
} else if (voter.getMotto_status() && mottoPhase){
|
||||||
|
LOGGER.warn(name + " has already chose their motto");
|
||||||
|
return "errors/alreadyVotedForMotto.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()){
|
||||||
@@ -132,37 +155,43 @@ 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) {
|
||||||
switch (tableAction.checkToken(name, code, authCodesRepository)) {
|
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
||||||
case "matched":
|
|
||||||
LOGGER.warn("matched");
|
if (tokenStatus.equals("matched")){
|
||||||
if (votingPhase) {
|
LOGGER.warn("matched");
|
||||||
List<Category> categories = categoryRepository.findAll();
|
if (mottoPhase){
|
||||||
model.addAttribute("categories", categories);
|
List<Motto> mottos = mottoRepository.findAll();
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("mottos", mottos);
|
||||||
return "voting.html";
|
model.addAttribute("name", name);
|
||||||
} else {
|
return "mottoVoting.html";
|
||||||
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
} else if (addingPhase) {
|
||||||
List<Category> categories = categoryRepository.findAll();
|
PossibleCandidateWrapper possibleCandidates = new PossibleCandidateWrapper();
|
||||||
for (int i = 0; i < categories.size(); i++) {
|
List<Category> categories = categoryRepository.findAll();
|
||||||
possibleCandidates.addPossibleCandidate(new PossibleCandidate());
|
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";
|
|
||||||
}
|
}
|
||||||
|
model.addAttribute("categories", categories);
|
||||||
case "expired":
|
model.addAttribute("form", possibleCandidates);
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
model.addAttribute("codeExpired", true);
|
return "addingCandidates.html";
|
||||||
model.addAttribute("codeFalse", false);
|
} else if (votingPhase) {
|
||||||
return "authenticate.html";
|
List<Category> categories = categoryRepository.findAll();
|
||||||
|
model.addAttribute("categories", categories);
|
||||||
case "wrong":
|
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
model.addAttribute("codeExpired", false);
|
return "voting.html";
|
||||||
model.addAttribute("codeFalse", true);
|
}
|
||||||
return "authenticate.html";
|
} else if (tokenStatus.equals("expired")){
|
||||||
|
LOGGER.warn("expired");
|
||||||
|
model.addAttribute("name", name);
|
||||||
|
model.addAttribute("codeExpired", true);
|
||||||
|
model.addAttribute("codeFalse", false);
|
||||||
|
return "authenticate.html";
|
||||||
|
} else if (tokenStatus.equals("wrong")){
|
||||||
|
LOGGER.warn("wrong");
|
||||||
|
model.addAttribute("name", name);
|
||||||
|
model.addAttribute("codeExpired", false);
|
||||||
|
model.addAttribute("codeFalse", true);
|
||||||
|
return "authenticate.html";
|
||||||
}
|
}
|
||||||
return "fatalError";
|
return "fatalError";
|
||||||
}
|
}
|
||||||
@@ -192,6 +221,19 @@ public class VotingController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/saveMotto")
|
||||||
|
public String mottoSaving(@RequestParam String name, @RequestParam String voteValue){
|
||||||
|
LOGGER.info(name);
|
||||||
|
if (voterRepository.findByEmail(name).getMotto_status()){
|
||||||
|
return "errors/alreadySubmitted.html";
|
||||||
|
} else {
|
||||||
|
tableAction.voteForMotto(voteValue, mottoRepository);
|
||||||
|
tableAction.updateMottoStatus(name, voterRepository);
|
||||||
|
LOGGER.info(name + " has choose his motto");
|
||||||
|
}
|
||||||
|
return "voteSuccessful.html";
|
||||||
|
}
|
||||||
|
|
||||||
@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).getCandidatesubmit_status()) {
|
||||||
@@ -199,7 +241,7 @@ public class VotingController {
|
|||||||
} else {
|
} else {
|
||||||
String[] partVoteValues = voteValues.split(",");
|
String[] partVoteValues = voteValues.split(",");
|
||||||
for (String s : partVoteValues) {
|
for (String s : partVoteValues) {
|
||||||
tableAction.voteFor(s, candidateRepository);
|
tableAction.voteForCandidate(s, candidateRepository);
|
||||||
}
|
}
|
||||||
tableAction.updateVotingStatus(name, voterRepository);
|
tableAction.updateVotingStatus(name, voterRepository);
|
||||||
LOGGER.info(name + " has voted!");
|
LOGGER.info(name + " has voted!");
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "mottos")
|
||||||
|
public class Motto implements Comparable<Motto>{
|
||||||
|
|
||||||
|
public Motto() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Motto(String name) {
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
this.votes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer votes;
|
||||||
|
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getVotes() {
|
||||||
|
return votes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVotes(Integer votes) {
|
||||||
|
this.votes = votes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void voteFor() {
|
||||||
|
this.votes += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Motto m) {
|
||||||
|
if (getVotes() == null || m.getVotes() == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return m.getVotes().compareTo(getVotes());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ public class Voter {
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
this.vote_status = false;
|
this.vote_status = false;
|
||||||
this.candidatesubmit_status = false;
|
this.candidatesubmit_status = false;
|
||||||
|
this.motto_status = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@@ -21,6 +22,7 @@ public class Voter {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private String email;
|
private String email;
|
||||||
private Boolean vote_status;
|
private Boolean vote_status;
|
||||||
|
private Boolean motto_status;
|
||||||
private Boolean candidatesubmit_status;
|
private Boolean candidatesubmit_status;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@@ -39,6 +41,10 @@ public class Voter {
|
|||||||
return candidatesubmit_status;
|
return candidatesubmit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getMotto_status() {
|
||||||
|
return motto_status;
|
||||||
|
}
|
||||||
|
|
||||||
public void vote(){
|
public void vote(){
|
||||||
vote_status = true;
|
vote_status = true;
|
||||||
}
|
}
|
||||||
@@ -46,4 +52,6 @@ public class Voter {
|
|||||||
public void submitCandidates() {
|
public void submitCandidates() {
|
||||||
candidatesubmit_status = true;
|
candidatesubmit_status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void voteMotto() { motto_status = true;}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||||
|
|
||||||
|
import com.github.cato447.AbizeitungVotingSystem.entities.Motto;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface MottoRepository extends JpaRepository<Motto, Integer> {
|
||||||
|
|
||||||
|
public Motto findByName(String name);
|
||||||
|
|
||||||
|
Optional<Motto> findById(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import java.lang.reflect.Array;
|
|||||||
import java.net.JarURLConnection;
|
import java.net.JarURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.Buffer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class TableAction {
|
public class TableAction {
|
||||||
@@ -30,6 +31,12 @@ public class TableAction {
|
|||||||
voterRepository.save(voter);
|
voterRepository.save(voter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateMottoStatus(String email, VoterRepository voterRepository){
|
||||||
|
Voter voter = voterRepository.findByEmail(email);
|
||||||
|
voter.voteMotto();
|
||||||
|
voterRepository.save(voter);
|
||||||
|
}
|
||||||
|
|
||||||
public AuthCode generateToken(String name, String code, AuthCodesRepository authCodesRepository) {
|
public AuthCode generateToken(String name, String code, AuthCodesRepository authCodesRepository) {
|
||||||
AuthCode authCode = new AuthCode(name, code);
|
AuthCode authCode = new AuthCode(name, code);
|
||||||
try{
|
try{
|
||||||
@@ -45,16 +52,19 @@ public class TableAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String checkToken(String name, String code, AuthCodesRepository authCodesRepository){
|
public String checkToken(String name, String code, AuthCodesRepository authCodesRepository){
|
||||||
AuthCode authCode = authCodesRepository.findByName(name);
|
try {
|
||||||
if (authCode.getCode().equals(code) && !fiveMinutesPassed(authCode.getTime())){
|
AuthCode authCode = authCodesRepository.findByName(name);
|
||||||
authCodesRepository.delete(authCode);
|
if (authCode.getCode().equals(code) && !authCode.isExpired()) {
|
||||||
return "matched";
|
authCodesRepository.delete(authCode);
|
||||||
} else if(fiveMinutesPassed(authCode.getTime())) {
|
return "matched";
|
||||||
authCodesRepository.delete(authCode);
|
} else if (authCode.isExpired()) {
|
||||||
return "expired";
|
authCodesRepository.delete(authCode);
|
||||||
} else {
|
return "expired";
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
return "wrong";
|
return "wrong";
|
||||||
}
|
}
|
||||||
|
return "wrong";
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fiveMinutesPassed(Long time){
|
private boolean fiveMinutesPassed(Long time){
|
||||||
@@ -65,13 +75,20 @@ public class TableAction {
|
|||||||
return possibleCandidates.size() <= 5 ? possibleCandidates.size() : 5;
|
return possibleCandidates.size() <= 5 ? possibleCandidates.size() : 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void voteFor(String id, CandidateRepository candidateRepository){
|
public void voteForCandidate(String id, CandidateRepository candidateRepository){
|
||||||
long candidateID = Long.valueOf(id);
|
long candidateID = Long.valueOf(id);
|
||||||
Candidate candidate = candidateRepository.findById(candidateID).get();
|
Candidate candidate = candidateRepository.findById(candidateID).get();
|
||||||
candidate.votedFor();
|
candidate.votedFor();
|
||||||
candidateRepository.save(candidate);
|
candidateRepository.save(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void voteForMotto(String id, MottoRepository mottoRepository){
|
||||||
|
long mottoID = Long.valueOf(id);
|
||||||
|
Motto motto = mottoRepository.findById(mottoID).get();
|
||||||
|
motto.voteFor();
|
||||||
|
mottoRepository.save(motto);
|
||||||
|
}
|
||||||
|
|
||||||
public void setUpVoters(VoterRepository voterRepository){
|
public void setUpVoters(VoterRepository voterRepository){
|
||||||
try (InputStream inputStream = getClass().getResourceAsStream("/Q2_emails.txt");
|
try (InputStream inputStream = getClass().getResourceAsStream("/Q2_emails.txt");
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
@@ -130,4 +147,20 @@ public class TableAction {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUpMottos(MottoRepository mottoRepository){
|
||||||
|
try (InputStream inputStream = getClass().getResourceAsStream("/Mottos.txt");
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
String line = "";
|
||||||
|
ArrayList<Motto> mottos = new ArrayList<>();
|
||||||
|
while ((line = reader.readLine())!= null){
|
||||||
|
String name = line;
|
||||||
|
Motto motto = new Motto(name);
|
||||||
|
mottos.add(motto);
|
||||||
|
}
|
||||||
|
mottoRepository.saveAll(mottos);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/main/resources/Mottos.txt
Normal file
11
src/main/resources/Mottos.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
CannABIs - wir haben es durchgezogen!
|
||||||
|
ABI 2,010 ‰ - Meist dichter als Denker
|
||||||
|
KABItän Blaubär - Immer blau und trotzdem schlau
|
||||||
|
HABI Potter - Wir verlassen die Kammer des Schreckens
|
||||||
|
A BItch - Für einen Punkt tue ich alles!
|
||||||
|
ABIthur - Wenn das Elite von die Gymnahsium gehen tut
|
||||||
|
LABIrinth - Planlos zum Ziel
|
||||||
|
ABIcrombie & Fitch - Models gehen, Elche bleiben (Abercrombie & Fitch)
|
||||||
|
SemipermeABIlität - Nur die Besten kommen durch
|
||||||
|
KohlrABI - Wir machen uns vom Acker
|
||||||
|
ABIgasmus - Aber das war nur das Vorspiel
|
||||||
66
src/main/resources/static/styles/mottoVoting.css
Normal file
66
src/main/resources/static/styles/mottoVoting.css
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
body {
|
||||||
|
background-color: rgb(44, 49, 54);
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center-screen {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
background: transparent;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
width: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: #FFF;
|
||||||
|
font-size: 75px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2.mottoHeader {
|
||||||
|
color: #FFF;
|
||||||
|
font-size: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: #FFF;
|
||||||
|
font-size: 35px;
|
||||||
|
font-weight: normal;
|
||||||
|
letter-spacing: .125rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
transition: opacity .25s .5s;
|
||||||
|
margin: 0.5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
margin-top: 5%;
|
||||||
|
padding: .25em 0;
|
||||||
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
|
background: #bb1515;
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
font-size: 2rem;
|
||||||
|
width: 500px;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-image: linear-gradient(to bottom right, #111E25 0%, #111 100%);
|
||||||
|
font-family: 'Lato', sans-serif;
|
||||||
|
}
|
||||||
65
src/main/resources/templates/mottoVoting.html
Normal file
65
src/main/resources/templates/mottoVoting.html
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
<link th:href="@{/styles/mottoVoting.css}" rel="stylesheet" />
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
<body class="center-screen">
|
||||||
|
|
||||||
|
<div class="centered">
|
||||||
|
<h1>Wähle das Abimotto:</h1>
|
||||||
|
<div id="votingButtons">
|
||||||
|
<div th:each="motto : ${mottos}" class="voteDiv">
|
||||||
|
<button class="inputButton" th:id="|motto${motto.id}|" th:text="${motto.name}" th:onclick="|setColor(motto${motto.id})|"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="#" th:action="@{/saveMotto}" method="post" id="mottoForm">
|
||||||
|
<input id="voteValue" type="hidden" name="voteValue" value="" />
|
||||||
|
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
||||||
|
<button class="submitButton" id="btnNext" onclick=getVotes()>Auswahl bestätigen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
function setColor(button) {
|
||||||
|
console.log(button);
|
||||||
|
groupButtons = document.querySelectorAll('[id^=motto]');
|
||||||
|
groupButtons.forEach(button => {
|
||||||
|
button.style.background = 'transparent';
|
||||||
|
button.style.fontWeight = 'normal';
|
||||||
|
});
|
||||||
|
button.style.background = "#bb1515";
|
||||||
|
button.style.fontWeight = 'bold';
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgbToHex(rgb) {
|
||||||
|
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
|
||||||
|
var color = (rgb && rgb.length === 4) ? "#" +
|
||||||
|
("0" + parseInt(rgb[1], 10).toString(16)).slice(-2) +
|
||||||
|
("0" + parseInt(rgb[2], 10).toString(16)).slice(-2) +
|
||||||
|
("0" + parseInt(rgb[3], 10).toString(16)).slice(-2) : '';
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVotes() {
|
||||||
|
groupButtons = document.querySelectorAll(".inputButton");
|
||||||
|
var voteID;
|
||||||
|
groupButtons.forEach(button => {
|
||||||
|
if (button.style.fontWeight == 'bold') {
|
||||||
|
voteID = 5;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input = document.getElementById("voteValue");
|
||||||
|
input.value = voteID;
|
||||||
|
document.getElementById("mottoForm").submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user