From 6a69bbcaf7f825f5c7befa3a9a6d8e1a02f5c367 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 12:36:43 +0200 Subject: [PATCH 01/15] Global refactor --- mong_usr.js | 8 ++-- public/index.html | 7 ++- public/routes/auth.js | 2 +- public/routes/createMessage.js | 72 ++++++++++++++-------------- public/routes/home.js | 69 ++++++++++++++++++--------- public/routes/initGlobals.js | 78 +++++++++++++++++++++++++++---- public/routes/majorData.js | 46 ------------------ public/routes/navRoutes.js | 15 ++---- public/routes/profilCard.js | 48 +++++++++++++------ public/search.js | 85 ++++++++++++++++++++-------------- public/style/style.css | 4 +- public/style/style.less | 4 +- server/authorization.js | 5 +- server/dbs.js | 57 +++++++++++------------ 14 files changed, 286 insertions(+), 214 deletions(-) delete mode 100644 public/routes/majorData.js diff --git a/mong_usr.js b/mong_usr.js index 21dc06d..83ee6cb 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,8 +1,8 @@ db.users.insert([ - // author,OHMNEWS2019 - {"_id":"author","name":"Test Author","type":"author","roles":{"user":true,"author":true},"hash":"sha256","salt":"cy5CkPrplcEze6o4psURhw==","pwd":"Gc8ozlxjEGITkS+fW9tz2xLROzws44s04EOCWuP04qE=","abos":["wichtig","th"],"bookmarks":["th"],}, - // admin,oZuse1 - {"_id":"admin","name":"Test Admin","type":"admin","roles":{"user":true,"author":true,"admin":true},"hash":"sha256","salt":"PoIUHbDp7tP34ji31iQ0zw==","pwd":"mJpIfIksYs6LJJwYRBemFKqR6TacsSl2E0ZtpO1GMuk=","abos":["wichtig","th"],"bookmarks":["wichtig"],}, + // User: author, Pwd: author + {"_id":"author","name":"Author","type":"MA@EFI;","roles":'{"user":true,"author":true}',"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":["nulla","tempor","veniam","ipsum"],"bookmarks":[],}, + // User: admin, Pwd: SwenMho + {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) //var c = require('./server/crypto.js'), diff --git a/public/index.html b/public/index.html index ca4ec59..8c9a3af 100644 --- a/public/index.html +++ b/public/index.html @@ -77,7 +77,6 @@ - @@ -88,13 +87,13 @@
- +
- +
@@ -104,8 +103,8 @@ router, el: '#api', data: { - // Locally registered variables vueRender : vueRender, + auth: auth, }, }); diff --git a/public/routes/auth.js b/public/routes/auth.js index 8f56f72..9feb1d0 100644 --- a/public/routes/auth.js +++ b/public/routes/auth.js @@ -152,7 +152,7 @@ Vue.component('login-panel', { function successful_login(res) { console.info("Re-Auth: Correct credentials"); this.closeLoginPanel; - vueForceRender(); + vueForceRender('key'); //console.log(res); router.push('/home') diff --git a/public/routes/createMessage.js b/public/routes/createMessage.js index 1a4048f..6fa1571 100644 --- a/public/routes/createMessage.js +++ b/public/routes/createMessage.js @@ -4,10 +4,11 @@ const CreateMsgRouter = {

Neue Nachricht erstellen

- - - + + @@ -38,6 +39,7 @@ const CreateMsgRouter = { data: function () { return { + auth: auth, isDisabled: false, selected: [], searchtext : "", @@ -45,13 +47,16 @@ const CreateMsgRouter = { }; }, computed:{ - filteredDataArray() { + filteredDataArray: function() { return this.taglist.filter((option) => { return option .toString() .toLowerCase() .indexOf(this.searchtext.toLowerCase()) >= 0 }) + }, + userName: function() { + return 'User: '+auth.name; } }, methods: { @@ -62,8 +67,19 @@ const CreateMsgRouter = { createMsg: function () { var _subject = $("#subject").val(); var _message = $("#message").val(); - var _tag = tagArray; - var _user = auth.name != '' ? auth.name : $("#user").val(); + var tmpArr = []; + tagArray.forEach(function(tag) { + console.info(tag); + tmpArr.push(tag.replace(/#/g, '')); + }); + tagArray = tmpArr; + var _tag = tagArray; + var _user = auth.name.split(' '); + if (_user.length < 2) { + _user = _user[0]; + } else { + _user = _user[1] + ', ' + _user[0]; + } //console.log("Message Created: " + _tag + " " + _message + " " + _user); $.ajax({ url: "api/msg", @@ -95,38 +111,26 @@ const CreateMsgRouter = { }) }, list_tags: function () { - $.ajax({url: "api/tag/ids",method: "GET"}) - .done(jd => { - // NICHT SO wg. Vue: _messagelist = jd; - console.log("DATA: "+data); - if(data == ""){ - _taglist.splice(0, _taglist.length); - _taglist.push.apply(_taglist, jd); - console.log("tag: jd: " + jd); - for (var e in jd) { - if (!_tags[jd[e]]) { - get_insert_tag(jd[e]); - } + $.ajax({url: "api/tag/ids",method: "GET"}) + .done(jd => { + // NICHT SO wg. Vue: _messagelist = jd; + console.log("DATA: "+data); + if(data == ""){ + _taglist.splice(0, _taglist.length); + _taglist.push.apply(_taglist, jd); + console.log("tag: jd: " + jd); + for (var e in jd) { + if (!_tags[jd[e]]) { + get_insert_tag(jd[e]); } } - }).fail(function (e, f, g) { - console.log("err: " + e + f + g); - }); - } + } + }).fail(function (e, f, g) { + console.log("err: " + e + f + g); + }); + }, }, mounted: function () { - var userField = $('#user'); - if (auth != null && auth.mail != '') { -// userField.prop('placeholder',auth.name); - var authorName = auth.name.split(' '); - authorName = authorName[1] + ', ' + authorName[0]; - userField.val(authorName); - userField.prop('disabled',true); - } else { - userField.prop('placeholder','User'); - userField.prop('disabled',false); - } - //this.list_tags(); if ($(this).bootstrapMaterialDesign) $(this).bootstrapMaterialDesign(); diff --git a/public/routes/home.js b/public/routes/home.js index 7947838..c5999b5 100644 --- a/public/routes/home.js +++ b/public/routes/home.js @@ -1,16 +1,26 @@ const HomeRouter = { template: `
- +
+ + zurück zu allen Einträgen + +

+ + +
`, data: function () { return { @@ -18,34 +28,51 @@ const HomeRouter = { messages: _messages, isSearchActiv: _isSearchActiv, isSubscripeButtonActiv: _isSubscripeButtonActiv, + isSubscriped: false, + subscripeTagName: '', bookmarkArray: auth.bookmarks, + vueRender: vueRender, }; }, methods: { + updateHomeAboButton: function(content) { + this.subscripeTagName = content; + console.info( this.subscripeTagName); + vueForceRender('key'); + }, + toggleEscapeSearchLink: function() { + console.info('got called'); + this.isSearchActive = !this.isSearchActive; + vueForceRender('key'); + console.info( this.isSearchActive); + }, list_messages: function() { messages(); }, goBackToDashboard: function() { - vueForceRender(); - $("#escape-search-link").css("visibility", "hidden"); - $("#subscribe-btn").css("visibility", "hidden"); + _isSearchActiv = false; + this.$emit('reset-searchtext',''); +// $("#escape-search-link").css("visibility", "hidden"); +// $("#subscribe-btn").css("visibility", "hidden"); + _isSubscripeButtonActiv = false; + vueForceRender('key'); + vueForceRender('search'); }, changeSubscribtion: function(){ var btnString = $("#btn-text").text(); console.log(btnString); - if($("#btn-text").hasClass("subscribed")){ - $("#btn-text").removeClass("subscribed"); - var newBtnString = btnString.replace(/deabonnieren/g, '') + "abonnieren"; + if(this.isSubscriped){ + this.subscripeTagName.replace(/deabonnieren/g, '') + "abonnieren"; //console.log(btnString); - $("#btn-text").text(newBtnString); +// $("#btn-text").text(newBtnString); }else{ - $("#btn-text").addClass("subscribed"); - var newBtnString = btnString.replace(/abonnieren/g, '') + "deabonnieren"; + this.subscripeTagName.replace(/abonnieren/g, '') + "deabonnieren"; //console.log(newBtnString); - $("#btn-text").text(newBtnString); - +// $("#btn-text").text(newBtnString); } + this.isSubscriped = !this.isSubscriped; + vueForceRender('key'); } }, diff --git a/public/routes/initGlobals.js b/public/routes/initGlobals.js index 89425ab..f5ed5a2 100644 --- a/public/routes/initGlobals.js +++ b/public/routes/initGlobals.js @@ -1,7 +1,6 @@ // Global Variables // User var auth = {}, - majorList = [], // Message _messagelist = [], @@ -14,19 +13,82 @@ var auth = {}, // Search _isSearchActiv = false, - _isSubscripeButtonActiv = true, + _isSubscripeButtonActiv = false, data = [], search_data = [], // Vue Rerender Key - vueRender = { key:0 }; + vueRender = { + key: 0, + search: 0, + }; -const authorRole = 'author'; +const authorRole = 'author', + majorList = [ + {id:'B-AC',name:'Bachelor Angewandte Chemie'}, + {id:'B-AMP',name:'Bachelor Angewandte Mathematik und Physik'}, + {id:'B-TJ',name:'Bachelor Technikjournalismus/Technik-PR'}, + {id:'B-AR',name:'Bachelor Architektur'}, + {id:'B-BI',name:'Bachelor Bauingenieurwesen'}, + {id:'B-BW',name:'Bachelor Betriebswirtschaft'}, + {id:'B-BIO',name:'Bachelor Management in der Biobranche'}, + {id:'B-IB',name:'Bachelor International Business'}, + {id:'B-IBT',name:'Bachelor International Business and Technology'}, + {id:'B-DE',name:'Bachelor Design'}, + {id:'B-EI',name:'Bachelor Elektrotechnik und Informationstechnik'}, + {id:'B-MED',name:'Bachelor Medizintechnik'}, + {id:'B-MF',name:'Bachelor Mechatronik/Feinwerktechnik'}, + {id:'B-ME',name:'Bachelor Media Engineering'}, + {id:'B-IN',name:'Bachelor Informatik'}, + {id:'B-MIN',name:'Bachelor Medieninformatik'}, + {id:'B-WIN',name:'Bachelor Wirtschaftsinformatik'}, + {id:'B-MB',name:'Bachelor Maschinenbau'}, + {id:'B-EGT',name:'Bachelor Energie- und Gebäudetechnik'}, + {id:'B-EBL',name:'Bachelor Soziale Arbeit: Erziehung und Bildung im Lebenslauf'}, + {id:'B-SA',name:'Bachelor Soziale Arbeit'}, + {id:'B-EPT',name:'Bachelor Energieprozesstechnik'}, + {id:'B-VT',name:'Bachelor Verfahrenstechnik'}, + {id:'B-WT',name:'Bachelor Werkstofftechnik'}, + {id:'M-AMP',name:'Master Angewandte Mathematik und Physik'}, + {id:'M-AR',name:'Master Architektur'}, + {id:'M-BI',name:'Master Internationales Bauwesen'}, + {id:'M-URB',name:'Master Urbane Mobilität (Verkehrsingenieurwesen)'}, + {id:'M-BW',name:'Master Betriebswirtschaft'}, + {id:'M-TAX',name:'Master Steuerberatung'}, + {id:'M-WR',name:'Master Wirtschaftsrecht'}, + {id:'M-IFE',name:'Master International Finance and Economics'}, + {id:'M-IMA',name:'Master International Marketing'}, + {id:'M-APR',name:'Master Applied Research in Engineering Sciences'}, + {id:'M-SY',name:'Master Elektronische und Mechatronische Systeme'}, + {id:'M-IN',name:'Master Informatik'}, + {id:'M-MIN',name:'Master Medieninformatik'}, + {id:'M-WIN',name:'Master Wirtschaftsinformatik'}, + {id:'M-MB',name:'Master Maschinenbau'}, + {id:'M-EE',name:'Master Energiemanagement und Energietechnik'}, + {id:'M-GT',name:'Master Gebäudetechnik'}, + {id:'M-SA',name:'Master Soziale Arbeit'}, + {id:'M-VT',name:'Master Chemieingenieurwesen und Verfahrenstechnik'}, + {id:'M-WT',name:'Master Werkstofftechnik'}, + ], + facultyList = [ + {id:'AC',name:'Angewandte Chemie'}, + {id:'AMP',name:'Angewandte Mathematik, Physik und Allgemeinwissenschaften'}, + {id:'AR',name:'Architektur'}, + {id:'BI',name:'Bauingeneurwesen'}, + {id:'BW',name:'Betriebswirtschaft'}, + {id:'D',name:'Design'}, + {id:'EFI',name:'Elektrotechnik Feinwerktechnik Informationstechnik'}, + {id:'IN',name:'Informatik'}, + {id:'MB-VS',name:'Maschinenbau und Versorgungstechnik'}, + {id:'SW',name:'Sozialwissenschaften'}, + {id:'VT',name:'Verfahrenstechnik'}, + {id:'WT',name:'Werkstofftechnik'}, + ]; // Global Functions -function vueForceRender() { - if (vueRender.key >= 10) { - vueRender.key = 0; +function vueForceRender(keyName) { + if (vueRender[keyName] >= 10) { + vueRender[keyName] = 0; } - vueRender.key++; + vueRender[keyName]++; } diff --git a/public/routes/majorData.js b/public/routes/majorData.js deleted file mode 100644 index f9779ba..0000000 --- a/public/routes/majorData.js +++ /dev/null @@ -1,46 +0,0 @@ -majorList = [ - {id:'B-AC',name:'Bachelor Angewandte Chemie'}, - {id:'B-AMP',name:'Bachelor Angewandte Mathematik und Physik'}, - {id:'B-TJ',name:'Bachelor Technikjournalismus/Technik-PR'}, - {id:'B-AR',name:'Bachelor Architektur'}, - {id:'B-BI',name:'Bachelor Bauingenieurwesen'}, - {id:'B-BW',name:'Bachelor Betriebswirtschaft'}, - {id:'B-BIO',name:'Bachelor Management in der Biobranche'}, - {id:'B-IB',name:'Bachelor International Business'}, - {id:'B-IBT',name:'Bachelor International Business and Technology'}, - {id:'B-DE',name:'Bachelor Design'}, - {id:'B-EI',name:'Bachelor Elektrotechnik und Informationstechnik'}, - {id:'B-MED',name:'Bachelor Medizintechnik'}, - {id:'B-MF',name:'Bachelor Mechatronik/Feinwerktechnik'}, - {id:'B-ME',name:'Bachelor Media Engineering'}, - {id:'B-IN',name:'Bachelor Informatik'}, - {id:'B-MIN',name:'Bachelor Medieninformatik'}, - {id:'B-WIN',name:'Bachelor Wirtschaftsinformatik'}, - {id:'B-MB',name:'Bachelor Maschinenbau'}, - {id:'B-EGT',name:'Bachelor Energie- und Gebäudetechnik'}, - {id:'B-EBL',name:'Bachelor Soziale Arbeit: Erziehung und Bildung im Lebenslauf'}, - {id:'B-SA',name:'Bachelor Soziale Arbeit'}, - {id:'B-EPT',name:'Bachelor Energieprozesstechnik'}, - {id:'B-VT',name:'Bachelor Verfahrenstechnik'}, - {id:'B-WT',name:'Bachelor Werkstofftechnik'}, - {id:'M-AMP',name:'Master Angewandte Mathematik und Physik'}, - {id:'M-AR',name:'Master Architektur'}, - {id:'M-BI',name:'Master Internationales Bauwesen'}, - {id:'M-URB',name:'Master Urbane Mobilität (Verkehrsingenieurwesen)'}, - {id:'M-BW',name:'Master Betriebswirtschaft'}, - {id:'M-TAX',name:'Master Steuerberatung'}, - {id:'M-WR',name:'Master Wirtschaftsrecht'}, - {id:'M-IFE',name:'Master International Finance and Economics'}, - {id:'M-IMA',name:'Master International Marketing'}, - {id:'M-APR',name:'Master Applied Research in Engineering Sciences'}, - {id:'M-SY',name:'Master Elektronische und Mechatronische Systeme'}, - {id:'M-IN',name:'Master Informatik'}, - {id:'M-MIN',name:'Master Medieninformatik'}, - {id:'M-WIN',name:'Master Wirtschaftsinformatik'}, - {id:'M-MB',name:'Master Maschinenbau'}, - {id:'M-EE',name:'Master Energiemanagement und Energietechnik'}, - {id:'M-GT',name:'Master Gebäudetechnik'}, - {id:'M-SA',name:'Master Soziale Arbeit'}, - {id:'M-VT',name:'Master Chemieingenieurwesen und Verfahrenstechnik'}, - {id:'M-WT',name:'Master Werkstofftechnik'}, -]; diff --git a/public/routes/navRoutes.js b/public/routes/navRoutes.js index 0b3f526..0339d1b 100644 --- a/public/routes/navRoutes.js +++ b/public/routes/navRoutes.js @@ -11,7 +11,7 @@ Vue.component('nav-router', { search - + add_circle @@ -37,7 +37,7 @@ Vue.component('nav-router', { search Search -
  • +
  • add_circle Create Message
  • @@ -55,18 +55,9 @@ Vue.component('nav-router', {
    `, data: function() { return { - isAuthor: this.isAuthorCheck(), + auth: auth, }; }, - methods: { - isAuthorCheck: function() { - console.info(auth.roles.author === authorRole); - return (auth.roles.author === authorRole); - }, - }, - updated: function() { - this.isAuthorChecked(); - } }); const routes = [ diff --git a/public/routes/profilCard.js b/public/routes/profilCard.js index bf0662b..2090a1e 100644 --- a/public/routes/profilCard.js +++ b/public/routes/profilCard.js @@ -11,7 +11,9 @@ Vue.component('profil-card', {
    {{ auth.name }}

    - {{ major }} + {{ labelMajorOrFaculty }} +
    + {{ majorOrFaculty }}

    @@ -57,25 +59,45 @@ Vue.component('profil-card', { }; }, computed: { - major: function() { + majorOrFaculty: function() { // e.g. ST@B-ME;ST@EFI; - var majorID = auth.type.split(';')[0].split('@')[1]; - //console.info(majorID); - //console.info(majorList); - var majorName = 'Studiengang Unbekannt'; - majorList.forEach(function(major) { - if (major.id == majorID) { - majorName = major.name; - } - }); - return majorName; + if (auth.roles.author) { + var facultyID = auth.type.split(';'); + console.info(facultyID[facultyID.length-2]); + facultyID = facultyID[facultyID.length-2].split('@')[1]; + var facultyName = ''; + facultyList.forEach(function(faculty) { + if (faculty.id == facultyID) { + facultyName = faculty.name; + } + }); + return facultyName; + } else { + var majorID = auth.type.split(';')[0].split('@')[1]; + //console.info(majorID); + //console.info(majorList); + var majorName = 'Studiengang Unbekannt'; + majorList.forEach(function(major) { + if (major.id == majorID) { + majorName = major.name; + } + }); + return majorName; + } }, + labelMajorOrFaculty: function() { + if (auth.roles.author) { + return 'Fakultät:' + } else { + return 'Studiengang:' + } + } }, methods: { logout: function() { clearAuthState(); $.ajax({ url: "api/logout", method: "POST" }); - vueForceRender(); + vueForceRender('key'); router.push('/profil'); }, } diff --git a/public/search.js b/public/search.js index c18f95f..1151be0 100644 --- a/public/search.js +++ b/public/search.js @@ -8,30 +8,34 @@ Vue.component('search',{ :data="filteredDataArray" placeholder="suche..." icon="magnify" + @reset-searchtext="resetSearchtext($event)" @select="option => selected = option"> `, data: function() { - return{ + return { searchtext: "", selected: [], taglist: data, }; }, computed:{ - filteredDataArray() { + filteredDataArray: function() { return this.taglist.filter((option) => { return option .toString() .toLowerCase() .indexOf(this.searchtext.toLowerCase()) >= 0 - }) - } + }); + }, }, methods: { - getFilteredTags(text) { + resetSearchtext: function(param) { + this.searchtext = param; + }, + getFilteredTags: function(text) { this.taglist = data.filter((option) => { return option .toString() @@ -41,7 +45,12 @@ Vue.component('search',{ this.search(); }, search: function() { - searching(this.searchtext); + var btnString = ''; + btnString = searching(this.searchtext, btnString); + console.info(btnString); + this.$emit('update-home-abo-button', btnString); + vueForceRender('key'); + }, saveTagsToArray: function() { tagArray = this.selected; @@ -69,13 +78,17 @@ Vue.component('search',{ }); }, clear: function() { - //_isSearchActiv = false; this.searchtext = ""; this.list_messages(); //router.push('/files') //router.push('/home') - $("#escape-search-link").css("visibility", "hidden"); - $("#subscribe-btn").css("visibility", "hidden"); + _isSearchActiv = false; + _isSubscripeButtonActiv = false; + this.$emit('toggle-escape-search-link'); + vueForceRender('key'); + console.info('done'); +// $("#escape-search-link").css("visibility", "hidden"); +// $("#subscribe-btn").css("visibility", "hidden"); }, }, mounted: function() { @@ -90,44 +103,46 @@ function get_insert_tag(id) { url: "api/tag/id/" + id, method: "GET" }).done(function(tag) { - data.push("#" + tag.name); + data.push('#'+tag.name); }).fail(function(e, f, g) { console.log("cannot load " + id + ".json: " + e + f + g); }) } -function searching(searchtext) { +function searching(searchtext,btnString) { _isSearchActiv = true; - $("#escape-search-link").css("visibility", "visible"); +// $("#escape-search-link").css("visibility", "visible"); //console.log(_tags); - console.log(data); - +// console.log(data); if(data.indexOf(searchtext) > -1){ - var btnString = "#" + searchtext.replace(/#/g, '') + " abonnieren"; - $("#btn-text").text(btnString); - $("#subscribe-btn").css("visibility", "visible"); + btnString = searchtext + " abonnieren"; +// $("#btn-text").text(btnString); +// $("#subscribe-btn").css("visibility", "visible"); + _isSubscripeButtonActiv = true; }else{ - $("#subscribe-btn").css("visibility", "hidden"); +// $("#subscribe-btn").css("visibility", "hidden"); + _isSubscripeButtonActiv = false; } - - $.ajax({ - url: "api/msg/search/" + searchtext.replace(/#/g, ''), - method: "GET" - }).done(jd => { - // NICHT SO wg. Vue: _messagelist = jd; - _messagelist.splice(0, _messagelist.length); - _messagelist.push.apply(_messagelist, jd); - //console.log("jd: "+jd); - for (var e in jd) { - if (!_messages[jd[e]]) { - get_insert_message(jd[e]); + if (searchtext !== '') { + $.ajax({ + url: "api/msg/search/" + searchtext.replace(/#/g, ''), + method: "GET" + }).done(jd => { + // NICHT SO wg. Vue: _messagelist = jd; + _messagelist.splice(0, _messagelist.length); + _messagelist.push.apply(_messagelist, jd); + //console.log("jd: "+jd); + for (var e in jd) { + if (!_messages[jd[e]]) { + get_insert_message(jd[e]); + } } - } - }).fail(function(e, f, g) { - console.log("searching: err: " + e + f + g); - }) - + }).fail(function(e, f, g) { + console.log("searching: err: " + e + f + g); + }) + } + return btnString; } function messages() { diff --git a/public/style/style.css b/public/style/style.css index b4078e9..d80046c 100644 --- a/public/style/style.css +++ b/public/style/style.css @@ -243,10 +243,10 @@ button.clearButton { } #subscribe-btn { float: right; - visibility: hidden; + -visibility: hidden; } #escape-search-link { - visibility: hidden; + -visibility: hidden; } #bockmark-not-active { visibility: visible; diff --git a/public/style/style.less b/public/style/style.less index 7db16f5..4c20586 100644 --- a/public/style/style.less +++ b/public/style/style.less @@ -287,10 +287,10 @@ button.clearButton{ #subscribe-btn{ float: right; - visibility: hidden; + -visibility: hidden; } #escape-search-link{ - visibility: hidden; + -visibility: hidden; } #bockmark-not-active{ visibility: visible; diff --git a/server/authorization.js b/server/authorization.js index 7138add..bc66afa 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -20,7 +20,7 @@ function getUserRole(found) { // Mail contains no number roles += ',"author"'; } - return roles; + return JSON.stringify('{'+roles+'}'); } // Fill in session object @@ -37,6 +37,7 @@ function fillSession (req, user, roles, cb) { req.session.user = user._id; } req.session.roles = roles; + console.info(req.session); } return cb (err); }); @@ -128,7 +129,7 @@ const authorization = { if (entry != null && entry.pwd) { if (crypto.checkLocalAuth (entry, req.body.pwd)) { console.info(entry.roles); - return fillSession (req, entry, JSON.stringify(entry.roles), returnSession); + return fillSession (req, entry, JSON.parse(entry.roles), returnSession); } return returnError (); } diff --git a/server/dbs.js b/server/dbs.js index 8054f61..fddfe9b 100644 --- a/server/dbs.js +++ b/server/dbs.js @@ -81,35 +81,6 @@ const dbs = { }); }, }, - - "usr/bookmark/ids": { - /* GET /api/usr/bookmark/ids [no args] - * -> Array of message schema object ids - * Get bookmark message ids - */ - - get: function (req, res) { - - model.Users.find({ - - }, - function (err, result) { - if (err) { - return res.status(401).json(err.message); - } else { - var parsed = []; - for (var i in result) { - parsed.push(result[i].bookmarks); - } - console.log("bookmarks:" + JSON.stringify(parsed)); - res.send(parsed); - } - if (result == null) { - return res.status(500).json("Can save bookmark.") - } - }); - }, - }, "msg": { /* POST /api/msg * <- Message schema @@ -190,6 +161,32 @@ const dbs = { }); }, }, + "usr/bookmark/ids": { + /* GET /api/usr/bookmark/ids [no args] + * -> Array of message schema object ids + * Get bookmark message ids + */ + + get: function (req, res) { + model.Users.find({ + }, + function (err, result) { + if (err) { + return res.status(401).json(err.message); + } else { + var parsed = []; + for (var i in result) { + parsed.push(result[i].bookmarks); + } + console.log("bookmarks:" + JSON.stringify(parsed)); + res.send(parsed); + } + if (result == null) { + return res.status(500).json("Can save bookmark.") + } + }); + }, + }, "usr/id": { params: ":id", /* GET /api/usr/[usr-id] @@ -380,7 +377,7 @@ const dbs = { bookmarks: { type: [String], _comment: "" }, sessionid: { type: String }, - roles: { type: [String], required: true, + roles: { type: String, required: true, _comment: "" }, }); model.Users = common.mongoose.model('users', userSchema); From dda5e89990148d5b89fdad60fb03c1ec676884b3 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 16:12:04 +0200 Subject: [PATCH 02/15] Demo: comment out session store --- server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index d96c84f..d6b434a 100644 --- a/server.js +++ b/server.js @@ -60,10 +60,10 @@ app.use(session({ secure: true, // true for https only (since our app works only with https) }, name: 'om.sid', - store: new MongoStore({ - mongooseConnection: mong.connection, - ttl: 30 * 24 * 3600, - }), // mongoose + connect-mongo +// store: new MongoStore({ +// mongooseConnection: mong.connection, +// ttl: 30 * 24 * 3600, +// }), // mongoose + connect-mongo //store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore })); From 31ba4a0b8bac29eb7bfce6e9848ff869707bb271 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 16:28:20 +0200 Subject: [PATCH 03/15] Demo: out comment route validator only-login --- server.js | 2 +- server/dbs.js | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/server.js b/server.js index d6b434a..c5e5f5e 100644 --- a/server.js +++ b/server.js @@ -112,7 +112,7 @@ app.use('/api', api_routes); app.use(express.static(__dirname + '/public')); // Other stuff is NOT authorized unless logged in -app.use (authorize.genCheckAuthorized ('user')); +//app.use (authorize.genCheckAuthorized ('user')); // No error so far? Then it's a 404! app.use(function (req, res, next) { diff --git a/server/dbs.js b/server/dbs.js index fddfe9b..3e18c30 100644 --- a/server/dbs.js +++ b/server/dbs.js @@ -386,18 +386,4 @@ const dbs = { models: model, }; - -/* -app.get ("/api/msg/search/:phrase", function (req, res) { - Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){ - if (err) { - console.log (err); - res .status(404) .json (err); - } else { - console.log(JSON.stringify(results)); - res.json(results); - } - }); -}); -*/ module.exports = dbs; From 84e73466e1b4162432a88eef4347ba8c87e3ce79 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 16:37:22 +0200 Subject: [PATCH 04/15] Demo: out comment mong.js; changes for remote mongoDB --- mong.js | 12 ++++++------ mong_usr.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mong.js b/mong.js index 34e8da9..9b20229 100644 --- a/mong.js +++ b/mong.js @@ -1,13 +1,13 @@ -var db = db.getSiblingDB('omdb'); +var db = db.getSiblingDB('om'); // Delete all collections + all records -db.messages.deleteMany({}); -db.tags.deleteMany({}); -db.users.deleteMany({}); -db.sessions.deleteMany({}); +//db.messages.deleteMany({}); +//db.tags.deleteMany({}); +//db.users.deleteMany({}); +//db.sessions.deleteMany({}); // Insert data in collections -load('mong_msg.js'); +//load('mong_msg.js'); load('mong_tag.js'); load('mong_usr.js'); diff --git a/mong_usr.js b/mong_usr.js index 83ee6cb..bc6369d 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,8 +1,8 @@ db.users.insert([ // User: author, Pwd: author - {"_id":"author","name":"Author","type":"MA@EFI;","roles":'{"user":true,"author":true}',"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":["nulla","tempor","veniam","ipsum"],"bookmarks":[],}, + {"_id":"author","name":"Author","type":"PF@EFI;","roles":'{"user":true,"author":true}',"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[],}, // User: admin, Pwd: SwenMho - {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, +// {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) //var c = require('./server/crypto.js'), From 389a744ebe74e9b51d556b94ba202b3d0afe2d62 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 16:54:35 +0200 Subject: [PATCH 05/15] Demo: changes for remote mongoDB --- server/dbs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/dbs.js b/server/dbs.js index 3e18c30..9a45fc8 100644 --- a/server/dbs.js +++ b/server/dbs.js @@ -305,7 +305,7 @@ const dbs = { * Local db: common.config.dbLocalConn * TH db: common.config.dbConn */ - common.mongoose.connect(common.config.dbLocalConn, { + common.mongoose.connect(common.config.dbConn, { useNewUrlParser: true }).then(() => { console.log("Database connected successfully."); From 81e6a60def8ad53ef22ca46bd20b902978bcc0fa Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 16:55:02 +0200 Subject: [PATCH 06/15] Demo: Changes for ohm-server --- server/authorization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/authorization.js b/server/authorization.js index bc66afa..9b88055 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -129,7 +129,7 @@ const authorization = { if (entry != null && entry.pwd) { if (crypto.checkLocalAuth (entry, req.body.pwd)) { console.info(entry.roles); - return fillSession (req, entry, JSON.parse(entry.roles), returnSession); + return fillSession (req, entry, entry.roles, returnSession); } return returnError (); } From 2686af2208155c4c0b29e61770527372302fcaca Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 17:22:34 +0200 Subject: [PATCH 07/15] Demo: Update Connection to MongoDB --- server_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_config.json b/server_config.json index bd0f6aa..42e52b3 100644 --- a/server_config.json +++ b/server_config.json @@ -1,5 +1,5 @@ { - "dbConn": "mongodb://127.0.0.1:27017/om", + "dbConn": "mongodb://om:aeg1phuKeDaixese@127.0.0.1:27017/om", "dbLocalConn": "mongodb://localhost:27017/omdb", "dbUser": "om", "dbPwd": "aeg1phuKeDaixese", From e063535127862903d6da446b4d2d19a94fe517a6 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 17:42:51 +0200 Subject: [PATCH 08/15] Demo: Update author role --- mong_usr.js | 2 +- server.js | 10 +++++----- server/authorization.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mong_usr.js b/mong_usr.js index bc6369d..5f4b8c8 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,6 +1,6 @@ db.users.insert([ // User: author, Pwd: author - {"_id":"author","name":"Author","type":"PF@EFI;","roles":'{"user":true,"author":true}',"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[],}, + {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[],}, // User: admin, Pwd: SwenMho // {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) diff --git a/server.js b/server.js index c5e5f5e..7754ab1 100644 --- a/server.js +++ b/server.js @@ -60,11 +60,11 @@ app.use(session({ secure: true, // true for https only (since our app works only with https) }, name: 'om.sid', -// store: new MongoStore({ -// mongooseConnection: mong.connection, -// ttl: 30 * 24 * 3600, -// }), // mongoose + connect-mongo - //store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore + store: new MongoStore({ + mongooseConnection: mong.connection, + ttl: 30 * 24 * 3600, + }), // mongoose + connect-mongo + store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore })); // Favicon for Desktop diff --git a/server/authorization.js b/server/authorization.js index 9b88055..4124aef 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -14,13 +14,13 @@ const clientVisibleSession = { user: true, name: true, type: true, mail: true, r // Return user role, query from found.mail function getUserRole(found) { - var roles = "user"; + var roles = {user:true}; var mail = found.mail; if (!/\d/.test(mail)) { // Mail contains no number - roles += ',"author"'; + roles.author = true; } - return JSON.stringify('{'+roles+'}'); + return roles; } // Fill in session object From 675b9051dcb402a54d78bcfdff508e2a5a2c4ddd Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 17:45:55 +0200 Subject: [PATCH 09/15] Demo: exclude MemoryStore --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 7754ab1..c4c861c 100644 --- a/server.js +++ b/server.js @@ -64,7 +64,7 @@ app.use(session({ mongooseConnection: mong.connection, ttl: 30 * 24 * 3600, }), // mongoose + connect-mongo - store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore +// store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore })); // Favicon for Desktop From 90c5362a5726b194a6f543a94bc2dd956907e2f7 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 17:56:30 +0200 Subject: [PATCH 10/15] Demo: fix --- server/authorization.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/authorization.js b/server/authorization.js index 4124aef..5add695 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -14,13 +14,13 @@ const clientVisibleSession = { user: true, name: true, type: true, mail: true, r // Return user role, query from found.mail function getUserRole(found) { - var roles = {user:true}; + var roles = "user"; var mail = found.mail; if (!/\d/.test(mail)) { // Mail contains no number - roles.author = true; + roles += ",author"; } - return roles; + return ('{'+roles+'}'); } // Fill in session object From 0a3a45107a54fa7e766dea216bf4713ec141e417 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 18:40:23 +0200 Subject: [PATCH 11/15] Demo: fix --- server/authorization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/authorization.js b/server/authorization.js index 5add695..dead7fc 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -151,7 +151,7 @@ const authorization = { entry.type = found.type; if (! entry.orclgender || entry.orclgender === "") entry.orclgender = found.orclgender; - return fillSession (req, entry, entry.roles.length > 0 ? common.arrayToHash(entry.roles) : {user:true}, returnSession); + return fillSession (req, entry, entry.roles.length > 0 ? entry.roles : {user:true}, returnSession); } // Otherwise create standard user entry From b891d8f516916c58779bd646e68c88ac40069e63 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 18:46:08 +0200 Subject: [PATCH 12/15] Demo: fix3 --- server/authorization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/authorization.js b/server/authorization.js index dead7fc..dc9fb05 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -127,8 +127,8 @@ const authorization = { Users.findById (req.body.user) .exec (function (err, entry) { // If there is a local user AND it has a password associated, test against this, and only this if (entry != null && entry.pwd) { + console.info(entry); if (crypto.checkLocalAuth (entry, req.body.pwd)) { - console.info(entry.roles); return fillSession (req, entry, entry.roles, returnSession); } return returnError (); From 1165918cd67fff6fca35c184b83591e3ffdd3473 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 18:50:30 +0200 Subject: [PATCH 13/15] Demo: fix --- mong_usr.js | 2 +- server/authorization.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mong_usr.js b/mong_usr.js index 5f4b8c8..54c73b5 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,6 +1,6 @@ db.users.insert([ // User: author, Pwd: author - {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[],}, + {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]}, // User: admin, Pwd: SwenMho // {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) diff --git a/server/authorization.js b/server/authorization.js index dc9fb05..0004b79 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -18,7 +18,7 @@ function getUserRole(found) { var mail = found.mail; if (!/\d/.test(mail)) { // Mail contains no number - roles += ",author"; + roles += ',"author"'; } return ('{'+roles+'}'); } From f727a5c44ac7a41ad67a8d1921b2f5a5e598bbfc Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 18:53:48 +0200 Subject: [PATCH 14/15] Demo:fix --- mong_usr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mong_usr.js b/mong_usr.js index 54c73b5..8747c8c 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,6 +1,6 @@ db.users.insert([ // User: author, Pwd: author - {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]}, + {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user","author"},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]}, // User: admin, Pwd: SwenMho // {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) From 9e3981a7b1b2eda0b16433bebe104fbc5cd5a9b4 Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Wed, 24 Jul 2019 19:00:53 +0200 Subject: [PATCH 15/15] Demo:fix --- mong_usr.js | 2 +- server/authorization.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mong_usr.js b/mong_usr.js index 8747c8c..54c73b5 100644 --- a/mong_usr.js +++ b/mong_usr.js @@ -1,6 +1,6 @@ db.users.insert([ // User: author, Pwd: author - {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user","author"},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]}, + {"_id":"author","name":"Author","type":"PF@EFI;","roles":{"user":true,"author":true},"hash":"sha256","salt":"SIzKNsNKsCRVr8a9U90q6A==","pwd":"HZly68TSAKHioz6Kz0QCbXVTHpT6hMmabUbFYVlCMeE=","abos":[],"bookmarks":[]}, // User: admin, Pwd: SwenMho // {"_id":"admin","name":"Test Admin","type":"MA@AMP;","roles":'{"user":true,"author":true,"admin":true}',"hash":"sha256","salt":"z3PNXGmQaWvaT7m2ZlT+0w==","pwd":"nfUfNv032J745xj3Hzya3Mkk43Dz/H0BmNTZhtx8UM0=","abos":["veniam","ipsum"],"bookmarks":[],}, ]) diff --git a/server/authorization.js b/server/authorization.js index 0004b79..ebb7c2d 100644 --- a/server/authorization.js +++ b/server/authorization.js @@ -14,11 +14,11 @@ const clientVisibleSession = { user: true, name: true, type: true, mail: true, r // Return user role, query from found.mail function getUserRole(found) { - var roles = "user"; + var roles = "user:true"; var mail = found.mail; if (!/\d/.test(mail)) { // Mail contains no number - roles += ',"author"'; + roles += ',"author:true"'; } return ('{'+roles+'}'); }