diff --git a/src/views/errors.js b/src/views/errors.js new file mode 100644 index 0000000000000000000000000000000000000000..8cd0124eadee5065c18fd2c687977580c683ada3 --- /dev/null +++ b/src/views/errors.js @@ -0,0 +1,13 @@ +const m = require('mithril'); + +export class Error401 { + static view() { + return m('div', 'This page is only accessible for authenticated users. Please log in.'); + } +} + +export class Error404 { + static view() { + return m('div', 'This page does not exist.'); + } +} diff --git a/src/views/studydocList.js b/src/views/studydocList.js index 107b0164f5ee00a660c44c6c9b732d3f8d0b951b..bf404e1d6f2c4851bf1301cdd3786772875ee8fa 100644 --- a/src/views/studydocList.js +++ b/src/views/studydocList.js @@ -1,5 +1,7 @@ import * as studydocs from '../models/studydocs'; import { apiUrl } from '../models/config'; +import { isLoggedIn } from '../models/auth'; +import { Error401 } from './errors'; const m = require('mithril'); @@ -18,16 +20,18 @@ export default class studydocList { } static view() { + if (!isLoggedIn()) return m(Error401); + return m('div', [ m('form', { onsubmit: (e) => { e.preventDefault(); const query = { $or: [ - { title: { $regex: `.*${this.search}.*` } }, - { lecture: { $regex: `.*${this.search}.*` } }, - { professor: { $regex: `.*${this.search}.*` } }, - { author: { $regex: `.*${this.search}.*` } }, + { title: { $regex: `^(?i).*${this.search}.*` } }, + { lecture: { $regex: `^(?i).*${this.search}.*` } }, + { professor: { $regex: `^(?i).*${this.search}.*` } }, + { author: { $regex: `^(?i).*${this.search}.*` } }, ], }; studydocs.load(query); @@ -45,7 +49,7 @@ export default class studydocList { m('td', doc.professor), m('td', doc.semester), m('td', doc.author), - m('td', m('a', { href: apiUrl + doc.files[0].file }, 'download')), + m('td', doc.files.map(item => m('a', { href: `${apiUrl}${item.file}`, target: '_blank' }, item.name))), ]))), ]), diff --git a/src/views/studydocNew.js b/src/views/studydocNew.js index 10abec5a8788f839b3ac0f4cb3e5f0a129e628f4..1b76b5791115899abbc207be62c12dcad5c98115 100644 --- a/src/views/studydocNew.js +++ b/src/views/studydocNew.js @@ -1,7 +1,9 @@ // import Ajv from 'ajv'; import * as studydocs from '../models/studydocs'; // import { apiUrl } from '../models/config'; +import { isLoggedIn } from '../models/auth'; import { log } from '../models/log'; +import { Error401 } from './errors'; const m = require('mithril'); @@ -25,6 +27,8 @@ export default class studydocNew { } view() { + if (!isLoggedIn()) return m(Error401); + return m('div', [ m('form', { onsubmit: (e) => {