@@ -1,10 +1,12 @@ | |||
db.user.insert([ | |||
db.users.insert([ | |||
// author,OHMNEWS2019 | |||
{"_id":"author","name":"Test Author","type":"author","roles":["user","author"],"hash":"sha256","salt":"cy5CkPrplcEze6o4psURhw==","pwd":"Gc8ozlxjEGITkS+fW9tz2xLROzws44s04EOCWuP04qE=","tags":["wichtig","th"],"bookmarks":["th"],}, | |||
// admin,oZuse1 | |||
{"_id":"admin","name":"Test Admin","type":"admin","roles":["user","author","admin"],"hash":"sha256","salt":"PoIUHbDp7tP34ji31iQ0zw==","pwd":"mJpIfIksYs6LJJwYRBemFKqR6TacsSl2E0ZtpO1GMuk=","tags":["wichtig","th"],"bookmarks":["wichtig"],}, | |||
]) | |||
db.users.insert({"name":"mustermannmax", "roles":["user"],"abos":[],"bookmarks":[]}) | |||
//var c = require('./server/crypto.js'), | |||
// e = {"_id":"writer","hash":"sha256"}; | |||
//c.fillLocalAuth(e,"pwd"); |
@@ -5,6 +5,8 @@ function clearAuthState() { | |||
auth.mail = ''; // Full mail address | |||
auth.roles = {}; // Role authorizations e.g. {user: true} | |||
auth.gender = ''; // Gender (e.g. Frau) | |||
auth.bookmarks = []; // Ids of bookmarks | |||
auth.abos = []; // Abos | |||
} | |||
clearAuthState(); | |||
@@ -1,120 +1,68 @@ | |||
const BookmarkRouter = { | |||
template: ` | |||
<div class="content"> | |||
<div class="is-hidden-desktop"> | |||
<div class="bookmark-headline"><h4>Gepeicherte Beiträge</h4></div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 1 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 2 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 3 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
<div id="om-msg-cards" class="is-hidden-desktop"> | |||
<MsgCard | |||
v-for="id in msgDisplay" | |||
:key="id" | |||
:msg="messages[id] || {}" | |||
></MsgCard> | |||
</div> | |||
<div class="column is-three-quarters is-pulled-right is-hidden-touch content-desktop"> | |||
<div class="bookmark-headline"><h4>Gepeicherte Beiträge</h4></div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 1 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 2 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>Betreff</b> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. <br><br> | |||
<a href="#">#beispiel #tag</a> | |||
<div class="om-card-footer"> | |||
<div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von User 3 | |||
</div> | |||
<i class="material-icons" @click="myFilter" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter" v-else="isActive">bookmark</i> | |||
</div> | |||
</div> | |||
</div> | |||
</div>`, | |||
data: function () { | |||
return { | |||
messagelist: _messagelist, | |||
messages: _messages, | |||
isActive: false, | |||
isActive: true, | |||
messageId: '', | |||
} | |||
}, | |||
computed:{ | |||
msgDisplay: function(){ | |||
return (this.messagelist.slice().reverse()); | |||
} | |||
}, | |||
methods: { | |||
myFilter () { | |||
myFilter: function() { | |||
this.isActive = !this.isActive; | |||
}, | |||
getMessageId: function(){ | |||
}, | |||
getMessages: function(){ | |||
var _usrid = "5d360f06b8f3ce67d12ccc92"; | |||
$.ajax({ | |||
url: "api/usr/id/" + _usrid, | |||
method: "GET" | |||
}) | |||
.done(have_result).fail(have_error); | |||
function have_result(res) { | |||
var str = JSON.stringify(res[0].bookmarks).split(","); | |||
_messagelist.splice(0, _messagelist.length); | |||
for (var e in str) { | |||
if (!_messages[str[e]]) { | |||
str[e] =str[e].replace(/\[/g, '').replace(/\"/g, '').replace(/\]/g, '') | |||
get_insert_message(str[e]); | |||
} | |||
} | |||
_messagelist.push.apply(_messagelist, str); | |||
//console.log("bookmark str: "+str); | |||
} | |||
function have_error(err) { | |||
console.log("error: " + err.responseText); | |||
console.log(err); | |||
} | |||
} | |||
}, | |||
mounted: function (){ | |||
this.getMessages(); | |||
} | |||
}; |
@@ -2,6 +2,7 @@ Vue.component('MsgCard', { | |||
template: `<div class="om-card card"> | |||
<h6 class="msg-head"> | |||
<b>{{ msg.subject }}</b> | |||
<div id="msgid">{{msg._id}}</div> | |||
<img src="favicon.ico" width=20px height=20px> | |||
</h6> | |||
{{ msg.message }}<br> | |||
@@ -11,8 +12,8 @@ Vue.component('MsgCard', { | |||
<div class="om-card-footer"> <div class="om-user-line"> | |||
<i class="material-icons">account_circle</i> | |||
Erstellt von {{ msg.user }}</div> | |||
<i class="material-icons" @click="myFilter()" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter()" v-else="isActive">bookmark</i> | |||
<i class="material-icons" @click="myFilter(msg._id)" v-if="!isActive">bookmark_border</i> | |||
<i class="material-icons" @click="myFilter(msg._id)" v-else="isActive">bookmark</i> | |||
</div></div>`, | |||
props: ['msg'], | |||
@@ -23,8 +24,33 @@ Vue.component('MsgCard', { | |||
}, | |||
methods: { | |||
myFilter: function() { | |||
myFilter: function(_messageid) { | |||
//var _messageid = $("#msgid").text(); | |||
var _bookmark = auth.bookmarks; | |||
_bookmark.push(_messageid); | |||
console.log("msgid"+_bookmark); | |||
var _userid = "5d360f06b8f3ce67d12ccc92"; | |||
this.isActive = !this.isActive; | |||
if(this.isActive){ | |||
$.ajax({ | |||
url: "api/usr", | |||
data: { | |||
userid: _userid, | |||
bookmark: _bookmark | |||
}, | |||
method: "PUT" | |||
}).done(have_result).fail(have_error); | |||
function have_result(res) { | |||
console.log(res); | |||
} | |||
function have_error(err) { | |||
console.log("error: " + err.responseText); | |||
console.log(err); | |||
} | |||
} | |||
}, | |||
filterForTag: function(tag) { | |||
console.log("link: " +tag); |
@@ -16,20 +16,22 @@ const dbs = { | |||
* -> Array of message schema object ids | |||
* Get ALL known message ids | |||
*/ | |||
get: function(req, res) { | |||
model.Messages.find({},{_id: true}).exec() | |||
get: function (req, res) { | |||
model.Messages.find({}, { | |||
_id: true | |||
}).exec() | |||
.then(results => { | |||
//selects id from message: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push (results[i]._id); | |||
} | |||
res.send(parsed); | |||
} ) | |||
.catch(err => { | |||
console.log (err); | |||
res.status(500).json(err); | |||
}); | |||
//selects id from message: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push(results[i]._id); | |||
} | |||
res.send(parsed); | |||
}) | |||
.catch(err => { | |||
console.log(err); | |||
res.status(500).json(err); | |||
}); | |||
}, | |||
}, | |||
"msg/id": { | |||
@@ -38,10 +40,10 @@ const dbs = { | |||
* -> Message schema | |||
* Get a particular message | |||
*/ | |||
get: function(req, res) { | |||
model.Messages.findById(req.params.id) .exec(function(err, result) { | |||
get: function (req, res) { | |||
model.Messages.findById(req.params.id).exec(function (err, result) { | |||
if (err) { | |||
console.log (err); | |||
console.log(err); | |||
res.status(404).json(err); | |||
} else { | |||
//console.log(JSON.stringify(result)); | |||
@@ -56,22 +58,56 @@ const dbs = { | |||
* -> Message schema | |||
* Get a particular message | |||
*/ | |||
get: function(req, res) { | |||
model.Messages.find( | |||
{$text: {$search: req.params.phrase}}) | |||
.sort({tag:-1}) | |||
.exec().then(results => { | |||
//selects id from message: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push (results[i]._id); | |||
} | |||
res.send(parsed); | |||
} ) | |||
.catch(err => { | |||
console.log (err); | |||
res.status(500).json(err); | |||
}); | |||
get: function (req, res) { | |||
model.Messages.find({ | |||
$text: { | |||
$search: req.params.phrase | |||
} | |||
}) | |||
.sort({ | |||
tag: -1 | |||
}) | |||
.exec().then(results => { | |||
//selects id from message: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push(results[i]._id); | |||
} | |||
res.send(parsed); | |||
}) | |||
.catch(err => { | |||
console.log(err); | |||
res.status(500).json(err); | |||
}); | |||
}, | |||
}, | |||
"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": { | |||
@@ -80,7 +116,7 @@ const dbs = { | |||
* -> Message schema | |||
* Create a new message | |||
*/ | |||
post: function(req, res) { | |||
post: function (req, res) { | |||
/* | |||
if ( !(req.body.tags instanceof Array) ) { | |||
return res.status(400).json({ error: "bad request" }); | |||
@@ -92,11 +128,13 @@ const dbs = { | |||
message: req.body.message, | |||
user: req.body.user, | |||
tag: req.body.tag | |||
}, function(err, result) { | |||
}, function (err, result) { | |||
if (err) { | |||
return res.status(401).json(err.message); | |||
} else { | |||
res.json({message: "Message created!!"}); | |||
res.json({ | |||
message: "Message created!!" | |||
}); | |||
} | |||
if (result == null) { | |||
return res.status(500).json("Can not create message.") | |||
@@ -115,20 +153,22 @@ const dbs = { | |||
* -> Array of tag schema object ids | |||
* Get ALL known tag ids | |||
*/ | |||
get: function(req, res) { | |||
model.Tags.find({},{_id: true}).exec() | |||
get: function (req, res) { | |||
model.Tags.find({}, { | |||
_id: true | |||
}).exec() | |||
.then(results => { | |||
//selects id from tag: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push (results[i]._id); | |||
} | |||
res.send(parsed); | |||
} ) | |||
.catch(err => { | |||
console.log (err); | |||
res.status(500).json(err); | |||
}); | |||
//selects id from tag: | |||
var parsed = []; | |||
for (var i in results) { | |||
parsed.push(results[i]._id); | |||
} | |||
res.send(parsed); | |||
}) | |||
.catch(err => { | |||
console.log(err); | |||
res.status(500).json(err); | |||
}); | |||
}, | |||
}, | |||
"tag/id": { | |||
@@ -137,17 +177,17 @@ const dbs = { | |||
* -> Tag schema | |||
* Get a particular tag | |||
*/ | |||
get: function(req, res) { | |||
get: function (req, res) { | |||
model.Tags.findById(req.params.id) | |||
.exec(function(err, result) { | |||
if (err) { | |||
console.log (err); | |||
res.status(404).json(err); | |||
} else { | |||
//console.log(JSON.stringify(result)); | |||
res.json(result); | |||
} | |||
}); | |||
.exec(function (err, result) { | |||
if (err) { | |||
console.log(err); | |||
res.status(404).json(err); | |||
} else { | |||
//console.log(req.params.id); | |||
res.json(result); | |||
} | |||
}); | |||
}, | |||
}, | |||
"usr/id": { | |||
@@ -156,17 +196,19 @@ const dbs = { | |||
* -> User Schema | |||
* Get a particular user | |||
*/ | |||
get: function(req, res) { | |||
model.Users.findById(req.params.id) | |||
.exec(function(err, result) { | |||
if (err) { | |||
console.log(err); | |||
res.status(404).json(err); | |||
} else { | |||
//console.log(JSON.stringify(result)); | |||
res.json(result); | |||
} | |||
}); | |||
get: function (req, res) { | |||
model.Users.find({ | |||
_id: req.params.id | |||
}) | |||
.exec(function (err, result) { | |||
if (err) { | |||
console.log(err); | |||
res.status(404).json(err); | |||
} else { | |||
console.log(result); | |||
res.json(result); | |||
} | |||
}); | |||
}, | |||
}, | |||
"usr": { | |||
@@ -175,8 +217,8 @@ const dbs = { | |||
* -> User schema | |||
* Create a new user | |||
*/ | |||
post: function(req, res) { | |||
model.User.create({ | |||
post: function (req, res) { | |||
model.Users.create({ | |||
_id: req.body.id, | |||
name: req.body.name, | |||
type: req.body.type, | |||
@@ -186,12 +228,14 @@ const dbs = { | |||
pwd: req.body.pwd, | |||
abos: req.body.abos, | |||
bookmarks: req.body.bookmarks, | |||
}, function(err, result) { | |||
}, function (err, result) { | |||
if (err) { | |||
console.log (err); | |||
console.log(err); | |||
return res.status(401).json(err.message); | |||
} else { | |||
res.json({message: "User created!!"}); | |||
res.json({ | |||
message: "User created!!" | |||
}); | |||
} | |||
if (result == null) { | |||
return res.status(500).json("Can not create user.") | |||
@@ -203,15 +247,41 @@ const dbs = { | |||
* -> User schema | |||
* Change a user | |||
*/ | |||
put: function(req, res) { | |||
model.Users.findById(reg.body._id) | |||
.exec(function(err, entry) { | |||
if (err) | |||
console.log (err); | |||
if (entry == null) | |||
return res.status(404).json(err.message); | |||
// TODO Catch edge cases | |||
entry.save(function(err, data) { | |||
put: function (req, res) { | |||
model.Users.find({ | |||
_id: req.body.userid | |||
}) | |||
.exec(function (err, entry) { | |||
if (err) { | |||
console.log(err); | |||
} else { | |||
model.Users.update({ | |||
_id: req.body.userid | |||
}, { | |||
bookmarks: req.body.bookmark | |||
}, function (err, data) { | |||
if (err) { | |||
console.log(err); | |||
} else { | |||
res.json({ | |||
id: "Bookmark saved" | |||
}); | |||
} | |||
if (data == null) { | |||
return res.status(404).json(err.message); | |||
} | |||
}); | |||
} | |||
if (entry == null) | |||
return res.status(404).json(err.message); | |||
// TODO Catch edge cases | |||
// TODO Save/Update user | |||
/* | |||
_id: req.body.id, | |||
@@ -224,9 +294,8 @@ const dbs = { | |||
abos: req.body.abos, | |||
bookmarks: req.body.bookmarks, | |||
*/ | |||
res.json(data); | |||
// res.json(data); | |||
}); | |||
}); | |||
}, | |||
}, | |||
}, | |||
@@ -241,7 +310,7 @@ const dbs = { | |||
* Local db: common.config.dbLocalConn | |||
* TH db: common.config.dbConn | |||
*/ | |||
common.mongoose.connect (common.config.dbLocalConn, { | |||
common.mongoose.connect(common.config.dbLocalConn, { | |||
useNewUrlParser: true | |||
}).then(() => { | |||
console.log("Database connected successfully."); | |||
@@ -258,47 +327,83 @@ const dbs = { | |||
* - per entry: _comment: Comment for Admin UI - TODO: not working yet | |||
*/ | |||
var messageSchema = common.mongoose.Schema({ | |||
subject: { type: String, required: true, | |||
_comment: "" }, | |||
message: { type: String, required: true, | |||
_comment: "" }, | |||
user: { type: String, required: true, | |||
_comment: "" }, | |||
tag: { type: [String], | |||
_comment: "" }, | |||
subject: { | |||
type: String, | |||
required: true, | |||
_comment: "" | |||
}, | |||
message: { | |||
type: String, | |||
required: true, | |||
_comment: "" | |||
}, | |||
user: { | |||
type: String, | |||
required: true, | |||
_comment: "" | |||
}, | |||
tag: { | |||
type: [String], | |||
_comment: "" | |||
}, | |||
//createtime: { type: Date, default: Date.now }, | |||
}); | |||
messageSchema.index({ "$**":'text' }); | |||
messageSchema.index({ | |||
"$**": 'text' | |||
}); | |||
model.Messages = common.mongoose.model('messages', messageSchema); | |||
model.Messages._list = [ "" ]; | |||
model.Messages._list = [""]; | |||
var tagSchema = common.mongoose.Schema({ | |||
name: { type: String, required: true, | |||
_comment: "" }, //unique | |||
name: { | |||
type: String, | |||
required: true, | |||
_comment: "" | |||
}, //unique | |||
}); | |||
model.Tags = common.mongoose.model('tags', messageSchema); | |||
model.Tags._list = [ "" ]; | |||
model.Tags._list = [""]; | |||
var userSchema = common.mongoose.Schema({ | |||
_id: { type: String }, | |||
name: { type: String, required: true, | |||
_comment: "" }, | |||
pwd: { type: String, | |||
_comment: "" }, | |||
hash: { type: String }, | |||
salt: { type: String }, | |||
type: { type: String }, | |||
roles: { type: [String], required: true, | |||
_comment: "" }, | |||
abos: { type: [String], | |||
_comment: "" }, | |||
/*_id: { | |||
type: String | |||
},*/ | |||
name: { | |||
type: String, | |||
required: true, | |||
_comment: "" | |||
}, | |||
pwd: { | |||
type: String, | |||
_comment: "" | |||
}, | |||
hash: { | |||
type: String | |||
}, | |||
salt: { | |||
type: String | |||
}, | |||
type: { | |||
type: String | |||
}, | |||
roles: { | |||
type: [String], | |||
required: true, | |||
_comment: "" | |||
}, | |||
abos: { | |||
type: [String], | |||
_comment: "" | |||
}, | |||
//deactivated: { type: Boolean }, | |||
//host: { type: Boolean }, | |||
bookmarks: { type: [String], | |||
_comment: "" }, | |||
bookmarks: { | |||
type: [String], | |||
_comment: "" | |||
}, | |||
}); | |||
model.Users = common.mongoose.model('users', userSchema); | |||
model.Users._list = [ "" ]; | |||
model.Users._list = [""]; | |||
}, | |||
models: model, | |||
}; |