initial commit
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
|||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2007-present the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import java.net.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.channels.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class MavenWrapperDownloader {
|
||||||
|
|
||||||
|
private static final String WRAPPER_VERSION = "0.5.6";
|
||||||
|
/**
|
||||||
|
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||||
|
*/
|
||||||
|
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||||
|
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||||
|
* use instead of the default one.
|
||||||
|
*/
|
||||||
|
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||||
|
".mvn/wrapper/maven-wrapper.properties";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path where the maven-wrapper.jar will be saved to.
|
||||||
|
*/
|
||||||
|
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||||
|
".mvn/wrapper/maven-wrapper.jar";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the property which should be used to override the default download url for the wrapper.
|
||||||
|
*/
|
||||||
|
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
System.out.println("- Downloader started");
|
||||||
|
File baseDirectory = new File(args[0]);
|
||||||
|
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||||
|
|
||||||
|
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||||
|
// wrapperUrl parameter.
|
||||||
|
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||||
|
String url = DEFAULT_DOWNLOAD_URL;
|
||||||
|
if(mavenWrapperPropertyFile.exists()) {
|
||||||
|
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||||
|
try {
|
||||||
|
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||||
|
Properties mavenWrapperProperties = new Properties();
|
||||||
|
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||||
|
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if(mavenWrapperPropertyFileInputStream != null) {
|
||||||
|
mavenWrapperPropertyFileInputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Ignore ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("- Downloading from: " + url);
|
||||||
|
|
||||||
|
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||||
|
if(!outputFile.getParentFile().exists()) {
|
||||||
|
if(!outputFile.getParentFile().mkdirs()) {
|
||||||
|
System.out.println(
|
||||||
|
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
downloadFileFromURL(url, outputFile);
|
||||||
|
System.out.println("Done");
|
||||||
|
System.exit(0);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
System.out.println("- Error downloading");
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||||
|
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||||
|
String username = System.getenv("MVNW_USERNAME");
|
||||||
|
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||||
|
Authenticator.setDefault(new Authenticator() {
|
||||||
|
@Override
|
||||||
|
protected PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
return new PasswordAuthentication(username, password);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
URL website = new URL(urlString);
|
||||||
|
ReadableByteChannel rbc;
|
||||||
|
rbc = Channels.newChannel(website.openStream());
|
||||||
|
FileOutputStream fos = new FileOutputStream(destination);
|
||||||
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
fos.close();
|
||||||
|
rbc.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Vendored
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
|||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||||
|
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?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"
|
||||||
|
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>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.3.4.RELEASE</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.github.cato447</groupId>
|
||||||
|
<artifactId>AbizeitungVotingSystem</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>AbizeitungVotingSystem</name>
|
||||||
|
<description>A Voting System to get voting information for our graduating book</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>11</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+15
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+116
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
+12
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
spring.datasource.url=jdbc:mysql://localhost/VotingSystem
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=***REMOVED***
|
||||||
|
|
||||||
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
@@ -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>
|
||||||
@@ -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";
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
td.voted {
|
||||||
|
background-color: #f05048;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.notVoted {
|
||||||
|
background-color: #76ed6b;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
+13
@@ -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