added
This commit is contained in:
@@ -6,6 +6,7 @@ import com.github.cato447.AbizeitungVotingSystem.helper.RandomNumber;
|
|||||||
import com.github.cato447.AbizeitungVotingSystem.repositories.*;
|
import com.github.cato447.AbizeitungVotingSystem.repositories.*;
|
||||||
import com.github.cato447.AbizeitungVotingSystem.table.TableAction;
|
import com.github.cato447.AbizeitungVotingSystem.table.TableAction;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -23,9 +24,15 @@ import java.util.*;
|
|||||||
@Controller
|
@Controller
|
||||||
public class VotingController {
|
public class VotingController {
|
||||||
|
|
||||||
private boolean votingPhase;
|
@Value("$(voting)")
|
||||||
private boolean mottoPhase;
|
private String voting;
|
||||||
private boolean addingPhase;
|
@Value("$(motto)")
|
||||||
|
private String motto;
|
||||||
|
@Value("$(adding)")
|
||||||
|
private String adding;
|
||||||
|
|
||||||
|
private Boolean votingPhase = false, mottoPhase = false, addingPhase = false;
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
@@ -54,31 +61,19 @@ public class VotingController {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
if (voting != null) {
|
||||||
String votingPhaseConfig = System.getProperty("votingPhase");
|
|
||||||
if (votingPhaseConfig.equalsIgnoreCase("true")) {
|
|
||||||
votingPhase = true;
|
votingPhase = true;
|
||||||
}
|
} else if (adding != null) {
|
||||||
|
addingPhase = true;
|
||||||
String mottoVotingConfig = System.getProperty("mottoVoting");
|
} else if (motto != null) {
|
||||||
if (mottoVotingConfig.equalsIgnoreCase("true")) {
|
|
||||||
mottoPhase = true;
|
mottoPhase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String addingPhaseConfig = System.getProperty("addingPhase");
|
|
||||||
if (addingPhaseConfig.equalsIgnoreCase("true")){
|
|
||||||
addingPhase = true;
|
|
||||||
}
|
|
||||||
} catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// //TODO: TESTING REMOVE ON SHIPPING
|
// //TODO: TESTING REMOVE ON SHIPPING
|
||||||
// votingPhase = false;
|
// votingPhase = false;
|
||||||
// mottoPhase = true;
|
// mottoPhase = true;
|
||||||
// addingPhase = false;
|
// addingPhase = false;
|
||||||
|
|
||||||
LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoVoting=" + mottoPhase + " addingPhase=" + addingPhase);
|
LOGGER.info("Program started with arguments: votingPhase=" + votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase);
|
||||||
|
|
||||||
if (voterRepository.findAll().size() == 0) {
|
if (voterRepository.findAll().size() == 0) {
|
||||||
tableAction.setUpVoters(voterRepository);
|
tableAction.setUpVoters(voterRepository);
|
||||||
@@ -90,7 +85,7 @@ public class VotingController {
|
|||||||
LOGGER.info("Categories successfully set up");
|
LOGGER.info("Categories successfully set up");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mottoRepository.findAll().size() == 0){
|
if (mottoRepository.findAll().size() == 0) {
|
||||||
tableAction.setUpMottos(mottoRepository);
|
tableAction.setUpMottos(mottoRepository);
|
||||||
LOGGER.info("Mottos successfully set up");
|
LOGGER.info("Mottos successfully set up");
|
||||||
}
|
}
|
||||||
@@ -126,7 +121,7 @@ public class VotingController {
|
|||||||
} else if (voter.getCandidatesubmit_status() && addingPhase) {
|
} 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){
|
} else if (voter.getMotto_status() && mottoPhase) {
|
||||||
LOGGER.warn(name + " has already chose their motto");
|
LOGGER.warn(name + " has already chose their motto");
|
||||||
return "errors/alreadyVotedForMotto.html";
|
return "errors/alreadyVotedForMotto.html";
|
||||||
} else {
|
} else {
|
||||||
@@ -134,7 +129,7 @@ public class VotingController {
|
|||||||
LOGGER.warn("no code");
|
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()) {
|
||||||
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());
|
||||||
}
|
}
|
||||||
@@ -157,9 +152,9 @@ public class VotingController {
|
|||||||
public String voting_adding(@RequestParam String code, @RequestParam String name, Model model) {
|
public String voting_adding(@RequestParam String code, @RequestParam String name, Model model) {
|
||||||
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
String tokenStatus = tableAction.checkToken(name, code, authCodesRepository);
|
||||||
|
|
||||||
if (tokenStatus.equals("matched")){
|
if (tokenStatus.equals("matched")) {
|
||||||
LOGGER.warn("matched");
|
LOGGER.warn("matched");
|
||||||
if (mottoPhase){
|
if (mottoPhase) {
|
||||||
List<Motto> mottos = mottoRepository.findAll();
|
List<Motto> mottos = mottoRepository.findAll();
|
||||||
model.addAttribute("mottos", mottos);
|
model.addAttribute("mottos", mottos);
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
@@ -180,13 +175,13 @@ public class VotingController {
|
|||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
return "voting.html";
|
return "voting.html";
|
||||||
}
|
}
|
||||||
} else if (tokenStatus.equals("expired")){
|
} else if (tokenStatus.equals("expired")) {
|
||||||
LOGGER.warn("expired");
|
LOGGER.warn("expired");
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
model.addAttribute("codeExpired", true);
|
model.addAttribute("codeExpired", true);
|
||||||
model.addAttribute("codeFalse", false);
|
model.addAttribute("codeFalse", false);
|
||||||
return "authenticate.html";
|
return "authenticate.html";
|
||||||
} else if (tokenStatus.equals("wrong")){
|
} else if (tokenStatus.equals("wrong")) {
|
||||||
LOGGER.warn("wrong");
|
LOGGER.warn("wrong");
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
model.addAttribute("codeExpired", false);
|
model.addAttribute("codeExpired", false);
|
||||||
@@ -222,9 +217,9 @@ public class VotingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/saveMotto")
|
@RequestMapping("/saveMotto")
|
||||||
public String mottoSaving(@RequestParam String name, @RequestParam String voteValue){
|
public String mottoSaving(@RequestParam String name, @RequestParam String voteValue) {
|
||||||
LOGGER.info(name);
|
LOGGER.info(name);
|
||||||
if (voterRepository.findByEmail(name).getMotto_status()){
|
if (voterRepository.findByEmail(name).getMotto_status()) {
|
||||||
return "errors/alreadySubmitted.html";
|
return "errors/alreadySubmitted.html";
|
||||||
} else {
|
} else {
|
||||||
tableAction.voteForMotto(voteValue, mottoRepository);
|
tableAction.voteForMotto(voteValue, mottoRepository);
|
||||||
|
|||||||
Reference in New Issue
Block a user