initial commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories
|
||||
public class AbizeitungVotingSystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AbizeitungVotingSystemApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.controller;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CategoryRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.VoterRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.table.TableAction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
|
||||
@Controller
|
||||
public class VotingController {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(VotingController.class);
|
||||
|
||||
private TableAction tableAction = new TableAction();
|
||||
|
||||
List<String> ipAddresses = new ArrayList<String>();
|
||||
|
||||
@Autowired
|
||||
VoterRepository voterRepository;
|
||||
|
||||
@Autowired
|
||||
CandidateRepository candidateRepository;
|
||||
|
||||
@Autowired
|
||||
CategoryRepository categoryRepository;
|
||||
|
||||
@RequestMapping("/")
|
||||
public String WelcomeSite() {
|
||||
|
||||
if (voterRepository.findAll().size() == 0) {
|
||||
tableAction.setUpVoters(voterRepository);
|
||||
LOGGER.info("Voters successfully set up");
|
||||
}
|
||||
if (candidateRepository.findAll().size() == 0) {
|
||||
tableAction.setUpCandidates(candidateRepository);
|
||||
LOGGER.info("Candidates successfully set up");
|
||||
}
|
||||
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
|
||||
.getRequest();
|
||||
|
||||
String currentIpAddress = request.getRemoteAddr();
|
||||
if (!this.ipAddresses.contains(currentIpAddress)) {
|
||||
LOGGER.info("User IP: " + request.getRemoteAddr());
|
||||
ipAddresses.add(currentIpAddress);
|
||||
}
|
||||
|
||||
tableAction.logVoters(voterRepository);
|
||||
tableAction.logCandidates(candidateRepository);
|
||||
tableAction.logCategories(categoryRepository);
|
||||
|
||||
return "start.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/vote")
|
||||
public String VerifyName(@RequestParam String name, Model model) {
|
||||
try {
|
||||
Voter voter = voterRepository.findByEmail(name);
|
||||
if (voter.getVote_status()) {
|
||||
LOGGER.warn(name + " has already voted");
|
||||
return "errors/alreadyVoted.html";
|
||||
} else {
|
||||
List<Candidate> candidates = candidateRepository.findAll();
|
||||
model.addAttribute("candidates", candidates);
|
||||
LOGGER.info(name + " is voting now");
|
||||
return "voting.html";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(name + " is not allowed to vote");
|
||||
return "errors/notRegistered.html";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/processVote")
|
||||
public String ProcessVote(@RequestParam String name) {
|
||||
LOGGER.info(name + " has voted");
|
||||
return "success.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/dashboard")
|
||||
public String AccessDashboard(@RequestParam String name, @RequestParam String password, Model model){
|
||||
try {
|
||||
if (name.equals("admin")) {
|
||||
if (password.equals("admin")) {
|
||||
List<Voter> voters = voterRepository.findAll();
|
||||
List<Candidate> candidates = candidateRepository.findAll();
|
||||
model.addAttribute("voters", voters);
|
||||
model.addAttribute("candidates", candidates);
|
||||
return "dashboard.html";
|
||||
} else{
|
||||
LOGGER.error("Wrong Password");
|
||||
}
|
||||
LOGGER.error("Wrong Username");
|
||||
}
|
||||
} catch (Exception e){
|
||||
LOGGER.fatal("voters table is not existing!");
|
||||
}
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "candidates")
|
||||
public class Candidate {
|
||||
|
||||
public Candidate() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Candidate(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.votes = 0;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "category_id")
|
||||
private Category category;
|
||||
|
||||
private Integer votes;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getVotes() {
|
||||
return votes;
|
||||
}
|
||||
|
||||
public String getCategory() {return category.getName();}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name="categories")
|
||||
public class Category {
|
||||
|
||||
public Category(){
|
||||
super();
|
||||
}
|
||||
|
||||
public Category(String name, List<Candidate> candidateList) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.candidateList = candidateList;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy= GenerationType.IDENTITY)
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
|
||||
private List<Candidate> candidateList;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<Candidate> getCandidateList() {
|
||||
return candidateList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="voters")
|
||||
public class Voter {
|
||||
|
||||
public Voter(){
|
||||
super();
|
||||
}
|
||||
|
||||
public Voter(String email, boolean vote_status) {
|
||||
this.email = email;
|
||||
this.vote_status= vote_status;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
private String email;
|
||||
private Boolean vote_status;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public Boolean getVote_status() {
|
||||
return vote_status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CandidateRepository extends JpaRepository<Candidate, Integer> {
|
||||
|
||||
public Candidate findByName(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CategoryRepository extends JpaRepository<Category, Long> {
|
||||
|
||||
public Category findByName(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.repositories;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface VoterRepository extends JpaRepository<Voter, Integer> {
|
||||
|
||||
public Voter findByEmail(String email);
|
||||
|
||||
public Voter findById(Long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem.table;
|
||||
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Candidate;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Category;
|
||||
import com.github.cato447.AbizeitungVotingSystem.entities.Voter;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CandidateRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.CategoryRepository;
|
||||
import com.github.cato447.AbizeitungVotingSystem.repositories.VoterRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.*;
|
||||
|
||||
public class TableAction {
|
||||
|
||||
public TableAction(){
|
||||
|
||||
}
|
||||
|
||||
public void addCandidate(String name, CandidateRepository candidateRepository){
|
||||
Candidate candidate = new Candidate(name);
|
||||
candidateRepository.save(candidate);
|
||||
}
|
||||
|
||||
public void setUpVoters(VoterRepository voterRepository){
|
||||
try {
|
||||
File emailFile = new File("src/main/resources/Q2_emails.txt");
|
||||
Scanner myReader = new Scanner(emailFile);
|
||||
ArrayList<Voter> voters = new ArrayList<Voter>();
|
||||
while (myReader.hasNextLine()) {
|
||||
String email = myReader.nextLine();
|
||||
Voter voter = new Voter(email, false);
|
||||
voters.add(voter);
|
||||
}
|
||||
voterRepository.saveAll(voters);
|
||||
myReader.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("An error occurred.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpCandidates(CandidateRepository candidateRepository){
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
Collections.addAll(names, "Greta Bentgens", "Laura König", "Aaron Glos", "Lukas Boy", "Frau Meyering"
|
||||
, "Frau Adams", "Herr Petering", "Frau Milde", "Frau Meyer");
|
||||
|
||||
ArrayList<Candidate> candidates = new ArrayList<>();
|
||||
for (String name: names) {
|
||||
Candidate candidate = new Candidate(name);
|
||||
candidates.add(candidate);
|
||||
}
|
||||
candidateRepository.saveAll(candidates);
|
||||
}
|
||||
|
||||
public String logCategories(CategoryRepository categoryRepository){
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
List<String> headers = Arrays.asList("Id", "Name", "Candidates");
|
||||
rows.add(headers);
|
||||
|
||||
for (Category category: categoryRepository.findAll()) {
|
||||
String candidateNames = "";
|
||||
for (Candidate candidate: category.getCandidateList()){
|
||||
candidateNames += candidate.getName() + "; ";
|
||||
}
|
||||
rows.add(Arrays.asList(""+category.getId(), category.getName(), candidateNames));
|
||||
}
|
||||
return formatAsTable(rows);
|
||||
}
|
||||
|
||||
public String logVoters(VoterRepository voterRepository){
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
List<String> headers = Arrays.asList("Id", "E-Mail", "Vote_status");
|
||||
rows.add(headers);
|
||||
for (Voter voter: voterRepository.findAll()) {
|
||||
rows.add(Arrays.asList(""+voter.getId(), voter.getEmail(), ""+voter.getVote_status()));
|
||||
}
|
||||
|
||||
return formatAsTable(rows);
|
||||
|
||||
}
|
||||
|
||||
public String logCandidates(CandidateRepository candidateRepository){
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
List<String> headers = Arrays.asList("Id", "Name", "Votes");
|
||||
rows.add(headers);
|
||||
for (Candidate candidate: candidateRepository.findAll()) {
|
||||
rows.add(Arrays.asList(""+candidate.getId(), candidate.getName(), ""+candidate.getVotes()));
|
||||
}
|
||||
|
||||
return formatAsTable(rows);
|
||||
}
|
||||
|
||||
private String formatAsTable(List<List<String>> rows) {
|
||||
int[] maxLengths = new int[rows.get(0).size()];
|
||||
for (List<String> row : rows)
|
||||
{
|
||||
for (int i = 0; i < row.size(); i++)
|
||||
{
|
||||
maxLengths[i] = Math.max(maxLengths[i], row.get(i).length());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder formatBuilder = new StringBuilder();
|
||||
for (int maxLength : maxLengths)
|
||||
{
|
||||
formatBuilder.append("%-").append(maxLength + 2).append("s");
|
||||
}
|
||||
String format = formatBuilder.toString();
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("\n");
|
||||
for (List<String> row : rows)
|
||||
{
|
||||
result.append(String.format(format, row.toArray(new String[0]))).append("\n");
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
156
src/main/resources/Q2_emails.txt
Normal file
156
src/main/resources/Q2_emails.txt
Normal file
@@ -0,0 +1,156 @@
|
||||
negar.barzegar@adolfinum.de
|
||||
simon.berger@adolfinum.de
|
||||
nicolas.cunha@adolfinum.de
|
||||
joline.hackstein@adolfinum.de
|
||||
philip.heckhoff@adolfinum.de
|
||||
simon.hormes@adolfinum.de
|
||||
benjamin.vogt@adolfinum.de
|
||||
taycan.arslan@adolfinum.de
|
||||
luca.boom@adolfinum.de
|
||||
leon.borgerding@adolfinum.de
|
||||
lukas.boy@adolfinum.de
|
||||
lukas.corell@adolfinum.de
|
||||
cedric.damerow@adolfinum.de
|
||||
amelie.david@adolfinum.de
|
||||
zeynep.efe@adolfinum.de
|
||||
melinda.hirschelmann@adolfinum.de
|
||||
lars.hogardt@adolfinum.de
|
||||
malin.kalnins@adolfinum.de
|
||||
victor.kocksnchez@adolfinum.de
|
||||
kamil.kowalczyk@adolfinum.de
|
||||
romyna.gurny@adolfinum.de
|
||||
noelia.kocksnchez@adolfinum.de
|
||||
lili.schweitzer@adolfinum.de
|
||||
jerome.laukamp@adolfinum.de
|
||||
elisa.bahl@adolfinum.de
|
||||
lisa.baumeister@adolfinum.de
|
||||
johanna.boeckmann@adolfinum.de
|
||||
svenja.fischer@adolfinum.de
|
||||
lena.goehlich@adolfinum.de
|
||||
paula.haub@adolfinum.de
|
||||
daria.horstmann@adolfinum.de
|
||||
melina.kascha@adolfinum.de
|
||||
pia.kleinwegen@adolfinum.de
|
||||
lauramarie.koenig@adolfinum.de
|
||||
yarkin.kulaksiz@adolfinum.de
|
||||
amelie.laake@adolfinum.de
|
||||
noemi.malaponti@adolfinum.de
|
||||
yara.mueser@adolfinum.de
|
||||
paul.nowack@adolfinum.de
|
||||
luca.ofiera@adolfinum.de
|
||||
timo.otto@adolfinum.de
|
||||
linnea.paulukuhn@adolfinum.de
|
||||
isabelle.schneider@adolfinum.de
|
||||
nico.scholzen@adolfinum.de
|
||||
manon.schroff@adolfinum.de
|
||||
carlotta.tueckmantel@adolfinum.de
|
||||
simon.bussmann@adolfinum.de
|
||||
luis.erpenbach@adolfinum.de
|
||||
meret.fass@adolfinum.de
|
||||
anna.feldmann@adolfinum.de
|
||||
alina.fuenderich@adolfinum.de
|
||||
joline.gilles@adolfinum.de
|
||||
karolina.hein@adolfinum.de
|
||||
robin.heldt@adolfinum.de
|
||||
annika.koch@adolfinum.de
|
||||
dusanka.djukanovic@adolfinum.de
|
||||
aaron.glos@adolfinum.de
|
||||
ayseguel.guelten@adolfinum.de
|
||||
hamza.hasoumi@adolfinum.de
|
||||
evelyn.hofmann@adolfinum.de
|
||||
burakmustafa.kulac@adolfinum.de
|
||||
dominik.kwitowski@adolfinum.de
|
||||
julia.lener@adolfinum.de
|
||||
paula.may@adolfinum.de
|
||||
luca.mueller@adolfinum.de
|
||||
mathieu.mueller@adolfinum.de
|
||||
marie.puetter@adolfinum.de
|
||||
hendrik.herffs@adolfinum.de
|
||||
greta.bentgens@adolfinum.de
|
||||
sven.mittmann@adolfinum.de
|
||||
jan.hoevel@adolfinum.de
|
||||
tim.krichel@adolfinum.de
|
||||
milo.lehnen@adolfinum.de
|
||||
lewis.lehner@adolfinum.de
|
||||
nico.lipinski@adolfinum.de
|
||||
luise.lu@adolfinum.de
|
||||
maike.nawarotzky@adolfinum.de
|
||||
rabea.peters@adolfinum.de
|
||||
patrick.preuss@adolfinum.de
|
||||
julius.preusser@adolfinum.de
|
||||
marie.scheidung@adolfinum.de
|
||||
lena.schlayer@adolfinum.de
|
||||
emma.sprenger@adolfinum.de
|
||||
klaudia.kapala@adolfinum.de
|
||||
gabriel.schacht@adolfinum.de
|
||||
delia.schmitz@adolfinum.de
|
||||
katharina.schmitz@adolfinum.de
|
||||
laurin.severith@adolfinum.de
|
||||
julian.sievers@adolfinum.de
|
||||
anna.siewert@adolfinum.de
|
||||
chiara.welter@adolfinum.de
|
||||
kira.winzen@adolfinum.de
|
||||
tim.zentzis@adolfinum.de
|
||||
justus.boesken@adolfinum.de
|
||||
finia.brinkmann@adolfinum.de
|
||||
anesa.cavcic@adolfinum.de
|
||||
antonia.eigemann@adolfinum.de
|
||||
nico.hahn@adolfinum.de
|
||||
timo.kohlmann@adolfinum.de
|
||||
alexander.kupillas@adolfinum.de
|
||||
alexander.neumann@adolfinum.de
|
||||
sophie.osterloh@adolfinum.de
|
||||
clemens.palinsky@adolfinum.de
|
||||
oliver.palinsky@adolfinum.de
|
||||
hendrik.pierlo@adolfinum.de
|
||||
lilly.schmidtke@adolfinum.de
|
||||
mara.spicker@adolfinum.de
|
||||
anhtrung.vo@adolfinum.de
|
||||
ben.schwarz@adolfinum.de
|
||||
luca.urbanczyk@adolfinum.de
|
||||
helena.neukirch@adolfinum.de
|
||||
nikita.lauff@adolfinum.de
|
||||
jennifer.lengard@adolfinum.de
|
||||
julia.mueller@adolfinum.de
|
||||
philipp.nothers@adolfinum.de
|
||||
judith.oppenberg@adolfinum.de
|
||||
dilan.oeztuerk@adolfinum.de
|
||||
malo.soulier@adolfinum.de
|
||||
mery.stern@adolfinum.de
|
||||
nouel.verberkt@adolfinum.de
|
||||
leon.viktora@adolfinum.de
|
||||
pia.anthes@adolfinum.de
|
||||
eray.arici@adolfinum.de
|
||||
christian.beutel@adolfinum.de
|
||||
mara.blanke@adolfinum.de
|
||||
lilly.ventzke@adolfinum.de
|
||||
luzi.weichert@adolfinum.de
|
||||
moritz.weihnacht@adolfinum.de
|
||||
leony.wittmann@adolfinum.de
|
||||
annika.lieblang@adolfinum.de
|
||||
leonie.wallusch@adolfinum.de
|
||||
felix.kirsten@adolfinum.de
|
||||
moritz.liebisch@adolfinum.de
|
||||
christian.pickardt@adolfinum.de
|
||||
jan.schliekmann@adolfinum.de
|
||||
elsa.piplack@adolfinum.de
|
||||
jolan.gerritzen@adolfinum.de
|
||||
lorena.garau@adolfinum.de
|
||||
matthias.karl@adolfinum.de
|
||||
justin.kauschke@adolfinum.de
|
||||
leonie.kramer@adolfinum.de
|
||||
laura.kurreck@adolfinum.de
|
||||
maya.lueck@adolfinum.de
|
||||
sean.mccormick-silex@adolfinum.de
|
||||
tim.mueller@adolfinum.de
|
||||
lana.peric@adolfinum.de
|
||||
jan.pintostrohhaeusl@adolfinum.de
|
||||
laura.ruettershoff@adolfinum.de
|
||||
charlotte.schirmer@adolfinum.de
|
||||
lavinia.schmitz@adolfinum.de
|
||||
victor.schroers@adolfinum.de
|
||||
gerrit.schulz@adolfinum.de
|
||||
clemens.spoo@adolfinum.de
|
||||
simon.stavroulakis@adolfinum.de
|
||||
ioannis.boerner@adolfinum.de
|
||||
marwa.nafouti@adolfinum.de
|
||||
5
src/main/resources/application.properties
Normal file
5
src/main/resources/application.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
spring.datasource.url=jdbc:mysql://localhost/VotingSystem
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=Cr@ckTh15
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
41
src/main/resources/logback.xml
Normal file
41
src/main/resources/logback.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<property name="LOGS" value="./logs" />
|
||||
|
||||
<appender name="Console"
|
||||
class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>
|
||||
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
|
||||
</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="RollingFile"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOGS}/Voting.log</file>
|
||||
<encoder
|
||||
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<Pattern>%d %p [%t] %m%n</Pattern>
|
||||
</encoder>
|
||||
|
||||
<rollingPolicy
|
||||
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- rollover daily and when the file reaches 10 MegaBytes -->
|
||||
<fileNamePattern>${LOGS}/archived/%d{yyyy-MM-dd}.%i.log
|
||||
</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<!-- LOG everything at INFO level -->
|
||||
<root level="info">
|
||||
<appender-ref ref="RollingFile" />
|
||||
<appender-ref ref="Console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
6
src/main/resources/static/scripts/test.js
Normal file
6
src/main/resources/static/scripts/test.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function Quadrat() {
|
||||
var Eingabe = document.getElementsByName("name");
|
||||
var Ergebnis = Eingabe.value;
|
||||
alert("Das Quadrat von " + Eingabe.value + " = " + Ergebnis);
|
||||
Eingabe.value = "Aaron";
|
||||
}
|
||||
7
src/main/resources/static/styles/dashboard.css
Normal file
7
src/main/resources/static/styles/dashboard.css
Normal file
@@ -0,0 +1,7 @@
|
||||
td.voted {
|
||||
background-color: #f05048;
|
||||
}
|
||||
|
||||
td.notVoted {
|
||||
background-color: #76ed6b;
|
||||
}
|
||||
18
src/main/resources/static/styles/start.css
Normal file
18
src/main/resources/static/styles/start.css
Normal file
@@ -0,0 +1,18 @@
|
||||
body {
|
||||
background-color: rgb(44, 49, 54);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: whitesmoke;
|
||||
font-size: 2em;
|
||||
font-family: Georgia, 'Times New Roman', Times, serif;
|
||||
border-bottom: 5px dotted #e3e7ec;
|
||||
border-top: 5px dotted white;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
form {
|
||||
color: #3cff00;
|
||||
font-weight: bold;
|
||||
}
|
||||
58
src/main/resources/templates/dashboard.html
Normal file
58
src/main/resources/templates/dashboard.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/dashboard.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Wähler Liste</h1>
|
||||
|
||||
<div class="voterTable">
|
||||
<table class="tableVoters" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Vote status</th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="voter : ${voters}">
|
||||
<!-- 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="${voter.vote_status}"></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="${voter.vote_status}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<h1>Kandidaten Liste</h1>
|
||||
<div class="candidateTable">
|
||||
<table class="tableCandidates" border="5">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Name</th>
|
||||
<th>Votes</th>
|
||||
<th>Category</th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="candidate: ${candidates}">
|
||||
<td th:text="${candidate.id}"></td>
|
||||
<td th:text="${candidate.name}"></td>
|
||||
<td th:text="${candidate.votes}"></td>
|
||||
<td th:text="${candidate.category}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
11
src/main/resources/templates/errors/alreadyVoted.html
Normal file
11
src/main/resources/templates/errors/alreadyVoted.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="color: red;"> Jeder darf nur einmal abstimmen! </h1>
|
||||
<a href="http://localhost:8080">Return to Login-Site</a>
|
||||
</body>
|
||||
</html>
|
||||
13
src/main/resources/templates/errors/notRegistered.html
Normal file
13
src/main/resources/templates/errors/notRegistered.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
</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="http://localhost:8080">Try again</a>
|
||||
</body>
|
||||
</html>
|
||||
25
src/main/resources/templates/start.html
Normal file
25
src/main/resources/templates/start.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" xmlns:th="http://thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
<link th:href="@{/styles/start.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Gebe deine Adolfinum E-Mail Adresse ein</h2>
|
||||
<form action="#" th:action="@{/vote}" method="post">
|
||||
<input type="text" name="name" />
|
||||
<input type="submit" value="submit" />
|
||||
</form>
|
||||
|
||||
<h2>Admin-Console Passwort</h2>
|
||||
<form action="#" th:action="@{/dashboard}" method="post">
|
||||
<input type="text" name="name" />
|
||||
<input type="password" name="password" />
|
||||
<input type="submit" value="login" />
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
66
src/main/resources/templates/test.html
Normal file
66
src/main/resources/templates/test.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de-DE" xmlns:th="http://thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Abizeitung 2020/2021 Voting</title>
|
||||
<link th:href="@{/styles/first.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Paragraphes</h2>
|
||||
<p>This is a paragraph.</p>
|
||||
<p>This is another paragraph.</p>
|
||||
|
||||
<h2>Links</h2>
|
||||
<a href="https://www.w3schools.com">This is a link</a>
|
||||
|
||||
<h2>HTML Images</h2>
|
||||
<p>HTML images are defined with the img tag:</p>
|
||||
<img src="https://www.lifewire.com/thmb/-27LpEPPTgNRUORa_mIczKDkWh0=/1280x905/filters:fill(auto,1)/what-is-binary-and-how-does-it-work-4692749-1-1eaec2e636424e71bb35419ef8d5005b.png" alt="Binary example picture" width="400" height="400">
|
||||
|
||||
<h2>Line breaks</h2>
|
||||
<p>This is a <br> paragraph with a line break.</p>
|
||||
|
||||
<h2>Styling</h2>
|
||||
<p style="color:red;">This is a red paragraph.</p>
|
||||
|
||||
<h2>Title attribute</h2>
|
||||
<p title="I'm a tooltip">This is a paragraph.</p>
|
||||
|
||||
<h2>Quotes in attributes</h2>
|
||||
<p title='John "ShotGun" Nelson'>Example 1</p>
|
||||
<p title="John 'ShotGun' Nelson">Example 2</p>
|
||||
|
||||
<h2>Bigger headings</h2>
|
||||
<h1>Heading 1</h1>
|
||||
|
||||
<h2>HTML Display</h2>
|
||||
<p>
|
||||
This paragraph contains a lot of lines in the source code, but the browser ignores it.
|
||||
</p>
|
||||
<p>
|
||||
This paragraph contains a lot of spaces in the source code, but the browser ignores it.
|
||||
</p>
|
||||
|
||||
<h2>Poem Problem</h2>
|
||||
<p>
|
||||
My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnie lies over the ocean. Oh, bring back my Bonnie to me.
|
||||
</p>
|
||||
|
||||
<h5>Solution:</h5>
|
||||
<pre>
|
||||
My Bonnie lies over the ocean.
|
||||
|
||||
My Bonnie lies over the sea.
|
||||
|
||||
My Bonnie lies over the ocean.
|
||||
|
||||
Oh, bring back my Bonnie to me.
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
23
src/main/resources/templates/voting.html
Normal file
23
src/main/resources/templates/voting.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<link th:href="@{/styles/voting.css}" rel="stylesheet" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Wähle deine Kandidaten:</h1>
|
||||
|
||||
<div th:each="candidate: ${candidates}">
|
||||
<p th:text="${candidate.id}"></p>
|
||||
<p th:text="${candidate.name}"></p>
|
||||
<p th:text="${candidate.votes}"></p>
|
||||
<p th:text="${candidate.category}"></p>
|
||||
<!-- <input type="checkbox" id="${candidate.id}" name="${candidate.name}" unchecked>
|
||||
<label for="${candidate.id}" th:text="${candidate.name}"></label> -->
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.cato447.AbizeitungVotingSystem;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class AbizeitungVotingSystemApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user