Skip to content

Commit

Permalink
Merge pull request #90 from MatsMoll/develop
Browse files Browse the repository at this point in the history
[Feide.User] Added Feide login and other small improvements
  • Loading branch information
MatsMoll authored Jan 6, 2021
2 parents 8acbc12 + fc2ac0c commit 2303820
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3
5.3
21 changes: 2 additions & 19 deletions Public/assets/js/subject/create.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
let descriptionEditor = editorForID("create-subject-description");

function createSubject() {
var url = "/api/subjects";

var name = $("#create-subject-name").val();
var description = descriptionEditor.value();
if (descriptionEditor.lenght < 1) {
description = null;
}
var category = $("#create-subject-category").val();
var colorClass = $('input[name=color-class]:checked').attr('id');

var data = JSON.stringify({
"name": name,
"colorClass": colorClass,
"description": description,
"category": category,
});
let url = "/api/subjects";

fetch(url, {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: data
body: createSubjectData()
})
.then(function (response) {
if (response.ok) {
Expand Down
8 changes: 3 additions & 5 deletions Public/assets/js/subject/delete.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
function deleteSubject() {
function deleteSubject(subjectID) {

var xhr = new XMLHttpRequest();
var url = "/api" + window.location.pathname.replace("creator/", "");
console.log(url);
var url = "/api/subjects/" + subjectID
xhr.open("DELETE", url, true);
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;

if (this.status == 200) {
window.location.href = "../subjects";
window.location.href = "/subjects";
}
};

xhr.send();
}
66 changes: 27 additions & 39 deletions Public/assets/js/subject/edit.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
$("#edit-subject-description").summernote({
minHeight : 100,
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline']],
['font', ['strikethrough', 'superscript', 'subscript']],
['para', ['ul', 'ol', 'paragraph']],
['insert', ['link', 'hr']],
['misc', ['undo', 'redo', 'help']]
]
});


function editSubject() {
function editSubject(subjectID) {

var xhr = new XMLHttpRequest();
var url = "/api" + window.location.pathname.replace("creator/", "");
xhr.open("PUT", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;

if (this.status == 200) {
window.location.reload();
let url = "/api/subjects/" + subjectID
fetch(url, {
method: "PUT",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: createSubjectData()
})
.then(function (response) {
if (response.ok) {
window.location.reload()
} else if (response.status == 400) {
throw new Error("Sjekk at all nødvendig info er fylt ut");
} else {
throw new Error(response.statusText);
}
})
.catch(function (error) {
$("#submitButton").attr("disabled", false);
$("#error-massage").text(error.message);
if ($("#error-div").css("display") == "block") {
$("#error-div").shake();
} else {
$("#error-div").fadeIn();
$("#error-div").removeClass("d-none");
}
};

var name = $("#edit-subject-name").val();
var description = null;
if (!$('#edit-subject-description').summernote("isEmpty")) {
description = $("#edit-subject-description").summernote("code");
}
var category = $("#create-subject-category").val();
var colorClass = $("#create-subject-color-class").val();

var data = JSON.stringify({
"name": name,
"colorClass": colorClass,
"description": description,
"category": category,
});
xhr.send(data);
}
19 changes: 19 additions & 0 deletions Public/assets/js/subject/json-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function createSubjectData() {

let name = $("#subject-name").val();
let description = subjectdescription.value();
if (description.lenght < 1) {
description = null;
}
let category = $("#subject-category").val();
let colorClass = $('input[name=color-class]:checked').attr('id');
let code = $("#subject-code").val();

return JSON.stringify({
"name": name,
"colorClass": colorClass,
"description": description,
"category": category,
"code": code
});
}
30 changes: 30 additions & 0 deletions Public/assets/js/subject/mark-potensial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

function markPotensialSubjects() {

let url = "/api/subjects/mark-potensial"

let responses = Array.from(document.querySelectorAll(".rel-switch")).map(node => {
return {
id: parseInt(node.querySelector("input").getAttribute("id")),
isActive: node.querySelector("input").checked
}
})
let data = JSON.stringify(responses)
fetch(url, {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: data
})
.then(function (response) {
if (response.ok) {
window.location.reload();
} else if (response.status == 400) {
throw new Error("Sjekk at all nødvendig info er fylt ut");
} else {
throw new Error(response.statusText);
}
})
}
6 changes: 3 additions & 3 deletions Sources/App/Subject Test/SubjectTestWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class SubjectTestWebController: SubjectTestWebControlling {
static func enter(on req: Request) throws -> EventLoopFuture<Response> {

try req.controllers.subjectTestController
.end(req: req)
.flatMapThrowing { _ in
try req.redirect(to: "/test-sessions/\(req.parameters.get(SubjectTest.self))")
.enter(on: req)
.map { session in
req.redirect(to: "/test-sessions/\(session.id)")
}
.flatMapErrorThrowing { error in
switch error {
Expand Down
9 changes: 8 additions & 1 deletion Sources/App/User/UserWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ final class UserWebController: RouteCollection {
}

func logout(_ req: Request) throws -> Response {
guard let user = req.auth.get(User.self) else { return req.redirect(to: "/") }
req.auth.logout(User.self)
return req.redirect(to: "/")
if req.cookies.isFeideLogin {
let response = req.feide.endSession(for: req)
response.cookies.isFeideLogin = false
return response
} else {
return req.redirect(to: "/")
}
}

func startResetPasswordForm(on req: Request) throws -> Response {
Expand Down

0 comments on commit 2303820

Please sign in to comment.