Commit 525a9cd7 authored by Jesper Zedlitz's avatar Jesper Zedlitz

noch fehlende Methoden des SnippetController migriert

parent a652aa01
Pipeline #1536 failed with stages
in 2 minutes and 37 seconds
......@@ -10,6 +10,7 @@ import net.genealogy.des.repository.MyKeyRepository;
import net.genealogy.des.repository.SnippetRepository;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
......@@ -19,13 +20,16 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ConcurrentModel;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.*;
@Controller
@RequiredArgsConstructor
......@@ -36,17 +40,27 @@ public class SnippetController {
private final MyKeyRepository myKeyRepository;
private final SnippetRepository snippetRepository;
@Autowired
private TemplateEngine textTemplateEngine;
@Value("${thumbnailDirectory}")
private String thumbnailDirectory;
@GetMapping("/snippet/javascript")
public String javascript() {
return "javascript";
@GetMapping(value = "/snippet/javascript", produces = "application/javascript")
@ResponseBody
public String javascript(Locale locale, HttpServletRequest request) {
final Context ctx = new Context(locale);
final String baseURL = ServletUriComponentsBuilder.fromCurrentContextPath().path("/").build().toUriString();
ctx.setVariable("baseURL", baseURL);
return this.textTemplateEngine.process("snippet/javascript.js", ctx);
}
@GetMapping("/snippet/help")
public String help() {
return "help";
return "snippet/help";
}
//belongs to this Server, gets requests from 'third parties'
......
<html>
<head>
<meta name="layout" content="main"/>
<title>Hilfe zu Decaptcha</title>
</head>
<body>
<p>Das Projekt "Decaptcha" ist an der Christian-Albrecht-Universität entstanden und hilft dabei, Geburtsdaten von Soldaten aus dem ersten Weltkrieg aus alten Unterlagen zu erfassen. Um das Captcha zu lösen, müssen Sie das Geburtsdatum der Person im ersten Textausschnitt in das erste Textfeld und das Geburtsdatum der Person im zweiten Textausschnitts in das zweite Textfeld eintragen.</p>
<p>Wenn Sie eines der Textausschnitte nicht lesen oder erkennen können, können Sie mit dem grünen Knopf andere Textausschnitte anfordern.</p>
<p>Vielen Dank für Ihre Mithilfe.</p>
</body>
</html>
function Decaptcha() {
var self = this;
var opt;
var unreadable;
var x = Math.round(Math.random()); //deciding order of snippets
var y;
var obj;
this.create = function (options) { //
opt = options;
if (x === 0) {
y = 1;
} else {
y = 0;
}
var head = $('head');
head.append("<link rel='stylesheet' type='text/css' href='[(${baseURL})]css/BoxDesign.css' />");
switch (options.theme) {
case "custom" :
break;
case "clean":
head.append("<link rel='stylesheet' type='text/css' href='[(${baseURL})]css/whiteDesign.css' />");
break;
case "blue":
head.append("<link rel='stylesheet' type='text/css' href='[(${baseURL})]css/blueDesign.css' />");
break;
default:
head.append("<link rel='stylesheet' type='text/css' href='[(${baseURL})]css/blueDesign.css' />");
}
get_challenge(opt.p_key);
createBox(obj, x, y);
$("#decaptcha-reload").click(function (event) {
event.preventDefault(); //stopping this event to not trigger this event again
self.reload();
});
if (options.callback != null) {
focus_response_field();
}
$("#decaptcha-help").click(function (event) {
event.preventDefault();
showHelp();
});
};
this.destroy = function () {
};
var get_challenge = function (p_key) {
$.ajax({
url: "[(${baseURL})]/snippet/obtainSnippets",
type: 'POST',
data: "publickey=" + p_key,
success: function (data) {
obj = data;
unreadable = obj.snippets[1].name;
},
async: false //because everything afterwards builds up on 'obj'
});
};
var focus_response_field = function () {
$('#decaptcha_response_field').focus();
};
var reload = function () {
var json = {
"snippets": [
{"name": unreadable}]
};
$.ajax({
url: "[(${baseURL})]/unreadableSnippets",
type: 'POST',
data: "data=" + JSON.stringify(json),
async: false //because of the window.location.reload() will be used too early
});
window.location.reload();
};
var createBox = function (obj, x, y) {
if (obj != null) {
var div01 = "<div class='decaptcha-div'><input type='hidden' id='decaptcha_challenge_field' name='decaptcha_challenge_field' value='" + obj.challenge[0].name + "'/>" +
"<div class='decaptcha-imgWrapper'><img alt='Captchabild 1' class='decaptcha-img' " +
"id ='decaptcha-snippet-img' src='[(${baseURL})]snippet/image/" +
obj.snippets[x].name + ".jpeg'/>" +
"<img class='decaptcha-img' alt='Captchabild 2' id ='decaptcha-snippet-img2' src='[(${baseURL})]snippet/image/" + obj.snippets[y].name + ".jpeg'/></div>";
var div2 = "<div class='decaptcha-wrapper'>";
var div3 = "<div class='decaptcha-input'><label class='decaptcha-label' for='decaptcha_response_field'>Geburtsdatum:</label>" +
"<input class='decaptcha-input-text' type='text' id='decaptcha_response_field' name='decaptcha_response_field' placeholder='" + obj.snippets[x].lastName + ", " + obj.snippets[x].firstName + "'><br/>" +
"<label class='decaptcha-label' for='decaptcha_response_field2'>Geburtsdatum:</label>" +
"<input class='decaptcha-input-text' type='text' id='decaptcha_response_field2' name='decaptcha_response_field2' placeholder='" + obj.snippets[y].lastName + ", " + obj.snippets[y].firstName + "'></div>";
var div4 = "<div class='decaptcha-buttons'><div class='decaptcha-button-wrapper'></div><button class='decaptcha-button decaptcha-button-green' id='decaptcha-reload'>" +
"<img class='decaptcha-logo' src='[(${baseURL})]images/reload.png' alt='Neues Captcha abrufen'/></button>" +
"<button id='decaptcha-help' class='decaptcha-button decaptcha-button-red'>Hilfe</button><div class='decaptcha-clear'></div></div><div class='decaptcha-clear'></div> </div>";
var decaptchaDiv = $('#decaptcha');
var formsUsingDecaptcha = $('form.decaptcha');
if (decaptchaDiv && formsUsingDecaptcha) {
// User wants more control over the intput forms. There are possibly multiple input forms.
decaptchaDiv.append(div01 + div2 + div3 + div4);
$.each(formsUsingDecaptcha, function () {
// add hidden fields
$(this).append('<input type="hidden" class="decaptcha_response_field" name="decaptcha_response_field" />');
$(this).append('<input type="hidden" class="decaptcha_response_field2" name="decaptcha_response_field2" />');
$(this).append('<input type="hidden" class="decaptcha_challenge_field" name="decaptcha_challenge_field" />');
// register the copy function
$(this).submit(function () {
$(this).find('.decaptcha_response_field').val($('#decaptcha_response_field').val());
$(this).find('.decaptcha_response_field2').val($('#decaptcha_response_field2').val());
$(this).find('.decaptcha_challenge_field').val($('#decaptcha_challenge_field').val());
return true;
});
});
} else {
// simple case, user did not annotate forms with class="decaptcha" -> add the DeCaptcha box to the first
// form that contains an input type=submit element.
$("input[type=submit]").before(div01 + div2 + div3 + div4);
$("#decaptcha_response_field2").keypress(function (event) {
if (event.which === 13) {
event.preventDefault();
$("input[type=submit]").click();
}
});
}
}
};
var showHelp = function () {
var helpWindow = window.open("[(${baseURL})]/snippet/help", "Popupfenster", "width=600,height=350,resizable=yes");
helpWindow.focus();
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" th:replace="~{layout :: layout(title=#{statistics.title}, content=~{::section})}"
xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
<section>
<table>
<tbody>
<tr class="prop">
<td class="name">fertig bearbeitete Schnipsel</td>
<td class="value" th:text="${numberOfVerifiedSnipptes}">2.500</td>
</tr>
<tr class="prop">
<td class="name">zur Verfügung stehende Schnipsel</td>
<td class="value" th:text="${numberOfOpenSnippets}">607</td>
</tr>
<tr class="prop">
<td class="name">Laufende Captcha-Vorgänge</td>
<td class="value" th:text="${numberOfChallenges}">35</td>
</tr>
</tbody>
</table>
</section>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment