Skip to content
Snippets Groups Projects
Commit 101938cc authored by Axel's avatar Axel
Browse files

feat: get Token from url and reach it to next page works for overview-docent and -student.

fix: userToken was not written to url during login
parent 2e9d400f
No related branches found
No related tags found
No related merge requests found
Showing
with 126 additions and 34 deletions
package unipotsdam.gf.core.management.user; package unipotsdam.gf.core.management.user;
import unipotsdam.gf.core.management.Management;
import unipotsdam.gf.core.management.ManagementImpl; import unipotsdam.gf.core.management.ManagementImpl;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -8,19 +9,41 @@ import javax.servlet.jsp.JspWriter; ...@@ -8,19 +9,41 @@ import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext; import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport; import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException; import java.io.IOException;
//todo: isStudent is false for docents. use this for dynamic menus
public class Menu extends SimpleTagSupport { public class Menu extends SimpleTagSupport {
public void doTag() throws JspException, IOException { public void doTag() throws JspException, IOException {
Management management = new ManagementImpl();
PageContext pageContext = (PageContext) getJspContext();
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
String token = request.getParameter("token");
User user = management.getUser(token);
JspWriter out = getJspContext().getOut(); JspWriter out = getJspContext().getOut();
out.println("<div id=\"sidebar-wrapper\">\n" + Boolean isStudent = user.getStudent();
" <ul class=\"sidebar-nav\">\n" + if (isStudent){
" <li class=\"sidebar-brand\"><a href=\"project-student.jsp\">overview</a></li>\n" + out.println("<div id=\"sidebar-wrapper\">\n" +
" <li><a href=\"takeQuiz.jsp\">Quizfrage</a></li>\n" + " <ul class=\"sidebar-nav\">\n" +
" <li><a href=\"#\">ePortfolio</a></li>\n" + " <li class=\"sidebar-brand\"><a href=\"overview-student.html\">overview</a></li>\n" +
" <li><a href=\"#\">Beitrag</a></li>\n" + " <li><a href=\"takeQuiz.jsp\">Quizfrage</a></li>\n" +
" <li><a href=\"finalAssessments.jsp\">Bewertung</a></li>\n" + " <li><a href=\"#\">ePortfolio</a></li>\n" +
" <li><a href=\"../index.jsp\">Logout</a></li>\n" + " <li><a href=\"#\">Beitrag</a></li>\n" +
" </ul>\n" + " <li><a href=\"finalAssessments.jsp\">Bewertung</a></li>\n" +
" </div>"); " <li><a href=\"../index.jsp\">Logout</a></li>\n" +
" </ul>\n" +
" </div>");
} else {
out.println("<div id=\"sidebar-wrapper\">\n" +
" <ul class=\"sidebar-nav\">\n" +
" <li class=\"sidebar-brand\"><a href=\"overview-docent.html\">overview</a></li>\n" +
" <li><a href=\"createQuiz.jsp\">Quizfrage</a></li>\n" +
" <li><a href=\"#\">ePortfolio</a></li>\n" +
" <li><a href=\"#\">Beitrag</a></li>\n" +
" <li><a href=\"#\">Gruppen erstellen</a></li>\n" +
" <li><a href=\"#\">Projektphase ändern</a></li>\n" +
" <li><a href=\"finalAssessments.jsp\">Bewertung</a></li>\n" +
" <li><a href=\"../index.jsp\">Logout</a></li>\n" +
" </ul>\n" +
" </div>");
}
} }
} };
\ No newline at end of file
...@@ -87,6 +87,9 @@ public class UserService { ...@@ -87,6 +87,9 @@ public class UserService {
ManagementImpl management = new ManagementImpl(); ManagementImpl management = new ManagementImpl();
if (management.exists(user)) { if (management.exists(user)) {
if (!createUser) { if (!createUser) {
ManagementImpl m = new ManagementImpl();
String token = m.getUserToken(user);
user = m.getUser(token);
return redirectToProjectPage(user, management); return redirectToProjectPage(user, management);
} }
String existsUrl = "../register.jsp?userExists=true"; String existsUrl = "../register.jsp?userExists=true";
...@@ -98,6 +101,9 @@ public class UserService { ...@@ -98,6 +101,9 @@ public class UserService {
String existsUrl = "../index.jsp?userExists=false"; String existsUrl = "../index.jsp?userExists=false";
return forwardToLocation(existsUrl); return forwardToLocation(existsUrl);
} }
ManagementImpl m = new ManagementImpl();
String token = m.getUserToken(user);
user = m.getUser(token); //todo: write query to get user isStudent
return redirectToProjectPage(user, management); return redirectToProjectPage(user, management);
} }
} }
......
...@@ -32,17 +32,18 @@ public class PeerAssessmentDummy implements IPeerAssessment { ...@@ -32,17 +32,18 @@ public class PeerAssessmentDummy implements IPeerAssessment {
} }
public ArrayList<Quiz> getQuiz(String projectId) { public ArrayList<Quiz> getQuiz(String projectId) {
String[] correctAnswers = new String[2]; String[] correctAnswers1 = new String[2];
ArrayList<Quiz> sampleQuiz = new ArrayList<Quiz>(); ArrayList<Quiz> sampleQuiz = new ArrayList<Quiz>();
correctAnswers[0] = "42"; correctAnswers1[0] = "42";
correctAnswers[1] = "" + projectId + " 24"; correctAnswers1[1] = "" + projectId + " 24";
String[] wrongAnswers = {"a god created creature", "a sum of my mistakes"}; String[] wrongAnswers = {"a god created creature", "a sum of my mistakes"};
sampleQuiz.add(new Quiz("multiple", "Who am I and if so, how many?", correctAnswers, wrongAnswers)); sampleQuiz.add(new Quiz("multiple", "Who am I and if so, how many?", correctAnswers1, wrongAnswers));
correctAnswers[0] = "ja, nicht?!"; String[] correctAnswers2 = new String[2];
correctAnswers[1] = "nee, oder doch?!"; correctAnswers2[0] = "ja, nicht?!";
correctAnswers2[1] = "nee, oder doch?!";
wrongAnswers = new String[]{"Mephistopheles", "Der alte Hexenmeister!?", "Der Schimmelreiter", "alle beide"}; wrongAnswers = new String[]{"Mephistopheles", "Der alte Hexenmeister!?", "Der Schimmelreiter", "alle beide"};
sampleQuiz.add(new Quiz("multiple", "Ist das nun des Pudels wahrer Kern?", correctAnswers, wrongAnswers)); sampleQuiz.add(new Quiz("multiple", "Ist das nun des Pudels wahrer Kern?", correctAnswers2, wrongAnswers));
return sampleQuiz; return sampleQuiz;
} }
......
...@@ -104,6 +104,10 @@ table .tableTd{ ...@@ -104,6 +104,10 @@ table .tableTd{
font-size: 27px; font-size: 27px;
} }
.questionTd{
margin: auto;
}
table .table-striped{ table .table-striped{
margin-left:2%; margin-left:2%;
font-size:24px; font-size:24px;
......
$(document).ready(function () { //todo: paths should be relative $(document).ready(function () { //todo: paths should be relative
$("#giveItBack").on("click", function () { $("#giveItBack").on("click", function () {
$.ajax({ $.ajax({
url: "http://localhost:8080/gemeinsamforschen/rest/assessments/total/project/" + "gemeinsamForschen" + "/student/" + "Bela", url: "../rest/assessments/total/project/" + "gemeinsamForschen" + "/student/" + "Bela",
type: 'GET', type: 'GET',
success: function (data) { success: function (data) {
alert("here is the TotalPerformance: " + data); alert("here is the TotalPerformance: " + data);
location.href="http://localhost:8080/gemeinsamforschen/pages/project-student.jsp?token="+getUserTokenFromUrl(); location.href="../pages/project-student.jsp?token="+getUserTokenFromUrl();
}, },
error: function (a, b, c) { error: function (a, b, c) {
alert('some error' + a); alert('some error' + a);
...@@ -64,7 +64,7 @@ $(document).ready(function () { //todo: paths should be relative ...@@ -64,7 +64,7 @@ $(document).ready(function () { //todo: paths should be relative
]; ];
$.ajax({ $.ajax({
url: "http://localhost:8080/gemeinsamforschen/rest/assessments/calculate", url: "../rest/assessments/calculate",
type: 'POST', type: 'POST',
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
......
...@@ -20,7 +20,7 @@ function assessPeer(){ ...@@ -20,7 +20,7 @@ function assessPeer(){
} }
dataP.push(peerRating); dataP.push(peerRating);
$.ajax({ $.ajax({
url:'http://localhost:8080/gemeinsamforschen/rest/assessments/peer/project/1/group/1', url:'../rest/assessments/peer/project/1/group/1',
type: 'POST', type: 'POST',
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
......
$(document).ready(function(){
$('#project1Link').on('click', function(){
location.href="project-docent.jsp?token="+getUserTokenFromUrl();
});
});
\ No newline at end of file
$(document).ready(function(){
$('#project1Link').on('click', function(){
location.href="project-student.jsp?token="+getUserTokenFromUrl();
});
});
\ No newline at end of file
$(document).ready(function () { $(document).ready(function () {
var loading = $('#loadbar').hide();
$(document)
.ajaxStart(function () {
loading.show();
}).ajaxStop(function () {
loading.hide();
});
$("label.btn").on('click',function () {
var choice = $(this).find('input:radio').val();
$('#loadbar').show();
$('#quiz').fadeOut();
setTimeout(function(){
$( "#answer" ).html( $(this).checking(choice) );
$('#quiz').show();
$('#loadbar').fadeOut();
/* something else */
}, 1500);
});
$ans = 3;
$.fn.checking = function(ck) {
if (ck != $ans)
return 'INCORRECT';
else
return 'CORRECT';
};
$.ajax({ $.ajax({
url: 'http://localhost:8080/gemeinsamforschen/rest/assessments/project/1/quiz/', url: '../rest/assessments/project/1/quiz/',
type: 'GET', type: 'GET',
success: function (data) { success: function (data) {
var table = document.getElementById('tableQuiz'); var table = document.getElementById('tableQuiz');
...@@ -8,15 +37,17 @@ $(document).ready(function () { ...@@ -8,15 +37,17 @@ $(document).ready(function () {
var answers = data[quiz].correctAnswers.concat(data[quiz].incorrectAnswers); var answers = data[quiz].correctAnswers.concat(data[quiz].incorrectAnswers);
var colspan = answers.length; var colspan = answers.length;
var trQuestion = document.createElement('TR'); var trQuestion = document.createElement('TR');
var question = '<td colspan="' + colspan + '" class="questionTd">' + data[quiz].question + '</td>'; var question = '<td colspan="' + colspan + '">' + data[quiz].question + '</td>';
trQuestion.innerHTML = question; trQuestion.innerHTML = question;
var trAnswers = document.createElement('TR'); var trAnswers = document.createElement('TR');
answers = shuffle(answers); answers = shuffle(answers);
var answersTd='<td style="display: block;">'; var answersTd='<div class="quiz" id="quiz" data-toggle="buttons"><td style="display: block;">';
for (var i = 0; i < answers.length; i++) { for (var i = 0; i < answers.length; i++) {
answersTd = answersTd + '<div><label><input type="checkbox">' + answers[i] + '</label></div>'; answersTd = answersTd + '<div><label class="element-animation1 btn btn-lg btn-primary btn-block"><span class="btn-label"><i class="glyphicon glyphicon-chevron-right"></i></span><input type="checkbox">' + answers[i] + '</label></div>';
} }
trAnswers.innerHTML = answersTd+'</td>'; question ="";
answers=[];
trAnswers.innerHTML = answersTd+'</div></td>';
table.appendChild(trQuestion); table.appendChild(trQuestion);
table.appendChild(trAnswers); table.appendChild(trAnswers);
} }
......
<%--
Created by IntelliJ IDEA.
User: fides-WHK
Date: 21.06.2018
Time: 12:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>gemeinsam Forschen</title>
</head>
<body>
<h1>hier werden quizzes vom Dozenten oder Studenten erstellt</h1>
</body>
</html>
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<table id="projects"> <!-- getElementById('projects').append um neue Projekte anzufügen --> <table id="projects"> <!-- getElementById('projects').append um neue Projekte anzufügen -->
<tr style="cursor:pointer" role="button"> <tr style="cursor:pointer" role="button">
<td> <td>
<a href="project-docent.html"> <a id="project1Link">
<h1>dummy Projekt1</h1> <h1>dummy Projekt1</h1>
</a> </a>
</td> </td>
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
<link rel="stylesheet" href="../assets/css/styles.css"> <link rel="stylesheet" href="../assets/css/styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="../assets/js/utility.js"></script>
<script src="../assets/js/overview-student.js"></script>
</head> </head>
<body> <body>
...@@ -20,7 +23,7 @@ ...@@ -20,7 +23,7 @@
<table id="projects"> <!-- getElementById('projects').append um neue Projekte anzufügen --> <table id="projects"> <!-- getElementById('projects').append um neue Projekte anzufügen -->
<tr style="cursor:pointer" role="button"> <tr style="cursor:pointer" role="button">
<td> <td>
<a href="project-docent.html"> <a id="project1Link">
<h1>dummy Projekt1</h1> <h1>dummy Projekt1</h1>
</a> </a>
</td> </td>
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
<h1>Quiz for project1 </h1> <h1>Quiz for project1 </h1>
<!-- here will be all the content --> <!-- here will be all the content -->
<table class="table-striped"> <table class="table-striped">
<tbody id="tableQuiz"> <tbody id="tableQuiz">
...@@ -110,10 +112,6 @@ ...@@ -110,10 +112,6 @@
</div> </div>
</div> </div>
</div> </div>
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/js/Sidebar-Menu.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment