-
-
-
+Vue.component('profil-card', {
+ template: `
+
+
-
exit_to_app
+
+
+ exit_to_app
+ Logout
+
-
-
Benutzername:
- {{ profil.user }}
- Studiengang:
- {{ profil.major }}
- Semester:
- {{ profil.semester }}
-
+
+ {{ auth.name }}
+ {{ major }}
+
+
-
+
-
- Abonniert: {{ profil.abos }}
- Gespeichert: {{ profil.saved }}
-
+
+ Abonniert: {{ abo }}
+ Gespeichert: {{ saved }}
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ `,
-
- props: ['profil'],
-
+
+
+
+
+
+
`,
data: function () {
return {
- isCardModalActive: false
+ auth: auth,
+ abo: 7,
+ saved: 3,
+ isCardModalActive: false,
};
},
+ computed: {
+ major: 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;
+ },
+ },
methods: {
- close: function () {
-
- }
+ logout: function() {
+ clearAuthState();
+ $.ajax({ url: "api/logout", method: "POST" });
+ router.push('/profil');
+ },
}
});
diff --git a/public/routes/profilData.js b/public/routes/profilData.js
deleted file mode 100644
index dcc9bac..0000000
--- a/public/routes/profilData.js
+++ /dev/null
@@ -1,10 +0,0 @@
-_profilcard = [
- {
- id: 1,
- user: '',
- major: '',
- semester: '',
- abos: '7',
- saved: '3',
- },
-];
diff --git a/public/search.js b/public/search.js
new file mode 100644
index 0000000..dd86a98
--- /dev/null
+++ b/public/search.js
@@ -0,0 +1,144 @@
+var isSearchActive = false,
+ tagArray = ["lorem"];
+
+const dat=[
+ 'th',
+ 'efi',
+ 'wichtig',
+ ],
+ search_data = [];
+
+Vue.component('search',{
+ template: `
+
`,
+ data: function() {
+ return{
+ searchtext: "",
+ selected: [],
+ taglist: dat,
+ };
+ },
+ computed:{
+ filteredDataArray() {
+ return this.taglist.filter((option) => {
+ return option
+ .toString()
+ .toLowerCase()
+ .indexOf(this.searchtext.toLowerCase()) >= 0
+ })
+ }
+ },
+ methods: {
+ getFilteredTags(text) {
+ this.taglist = dat.filter((option) => {
+ return option
+ .toString()
+ .toLowerCase()
+ .indexOf(text.toLowerCase()) >= 0
+ })
+ this.search();
+ },
+ search: function() {
+ searching(this.searchtext);
+ },
+ saveTagsToArray: function() {
+ tagArray = this.selected;
+// console.info(tagArray);
+ },
+ list_messages: function() {
+ messages();
+ },
+ list_tags: function () {
+ $.ajax({url: "api/tag/ids", method: "GET"})
+ .done(jd => {
+ // NICHT SO wg. Vue: _messagelist = jd;
+ _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);
+ });
+ },
+ clear: function() {
+ console.log("clear");
+
+ isSearchActiv = false;
+ this.searchtext = "";
+ this.list_messages();
+ },
+ },
+ mounted: function() {
+ //this.search();
+ this.list_tags();
+ },
+});
+
+// Global Functions !!!
+function get_insert_tag(id) {
+ $.ajax({
+ url: "api/tag/id/" + id,
+ method: "GET"
+ }).done(function(tag) {
+ dat.push("#" + tag.name);
+ }).fail(function(e, f, g) {
+ console.log("cannot load " + id + ".json: " + e + f + g);
+ })
+}
+
+function searching(searchtext) {
+ isSearchActiv = true;
+ console.log("Searchtext: " + searchtext.replace(/#/g, ''));
+ $.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);
+ })
+}
+
+function messages() {
+ $.ajax({
+ url: "api/msg/ids",
+ 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("list_msg: err: " + e + f + g);
+ });
+}
diff --git a/public/style/style.css b/public/style/style.css
index 3282eb7..6f18b0a 100644
--- a/public/style/style.css
+++ b/public/style/style.css
@@ -27,12 +27,17 @@
margin: 10px;
margin-top: 80px;
margin-bottom: 80px;
+ width: auto;
+ overflow: hidden;
}
.om-content a {
- color: #0046a0;
+ color: white;
}
.om-content a:hover {
- color: #0046a0;
+ color: white;
+}
+.content-desktop {
+ margin-right: 30px;
}
.om-nav {
position: fixed;
@@ -216,3 +221,15 @@ label.checkbox-inline input[type=checkbox]:checked + .checkbox-decorator .check
margin-top: 30%;
font-size:140%;
}*/
+.om-searchbar input.input {
+ border-radius: 0 !important;
+ box-shadow: none !important;
+ border-right: white;
+}
+button.clearButton {
+ border-radius: 0 !important;
+ background-color: white;
+ margin-left: -5px;
+ border-color: #dbdbdb;
+ border-left: white;
+}
diff --git a/public/style/style.less b/public/style/style.less
index 4089208..2f667b3 100644
--- a/public/style/style.less
+++ b/public/style/style.less
@@ -34,12 +34,18 @@
margin: 10px;
margin-top: 80px;
margin-bottom: 80px;
+ width: auto;
+ overflow: hidden;
a{
- color: @color;
- &:hover{color:@color;}
+ color: white;
+ &:hover{color:white;}
}
}
+.content-desktop {
+ margin-right: 30px;
+}
+
//footer
.om-nav{
position:fixed;
@@ -254,3 +260,18 @@ hr.first {
font-size:140%;
}*/
+.om-searchbar input.input{
+ border-radius: 0 !important;
+ box-shadow: none !important;
+ border-right: white;
+}
+
+button.clearButton{
+ border-radius: 0 !important;
+ background-color: white;
+ margin-left: -5px;
+ border-color: #dbdbdb;
+ border-left: white;
+
+}
+
diff --git a/server.js b/server.js
index d5ac4f7..305ce44 100644
--- a/server.js
+++ b/server.js
@@ -6,12 +6,11 @@
* Requires express >= 4
*/
var common = require('./server/common'),
+ //admin = require ('./server/admin'),
authorize = require('./server/authorization'),
dbs = require('./server/dbs');
-/*
- dbs = require ('./server/dbs'),
- files = require ('./server/files');
-*/
+ //files = require ('./server/files');
+
const fs = common.fs, // file sync, read certificates
http = common.http, // http handler
https = require('https'), // https handler
@@ -19,7 +18,7 @@ const fs = common.fs, // file sync, read certificates
session = require('express-session'), // session management (security)
morgan = require('morgan'), // logger
mong = common.mongoose, // mongoose
-// serveFavicon = require('serve-favicon'), // provide favicon
+ serveFavicon = require('serve-favicon'), // provide favicon
bodyParser = require('body-parser'), // post request bodyparser
MongoStore = require('connect-mongo')(session); // use mongodb as session storage
@@ -29,8 +28,9 @@ var app = express();
* Init
*/
common .init();
+dbs .init (common);
authorize .init(common);
-dbs .init (common);
+//admin .init (common);
//files .init (common);
mong.Promise = global.Promise;
@@ -62,13 +62,13 @@ app.use(session({
name: 'om.sid',
store: new MongoStore({
mongooseConnection: mong.connection,
- ttl: 30 * 24 * 3600
+ ttl: 30 * 24 * 3600,
}), // mongoose + connect-mongo
//store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore
}));
-// TODO Favicon for Desktop
-//app.use (serveFavicon (__dirname + '/public/favicon.ico'));
+// Favicon for Desktop
+app.use (serveFavicon(__dirname + '/public/img/favicon.ico'));
// Minimal Logging
//app.use (morgan ('dev'));
@@ -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) {
@@ -125,19 +125,20 @@ app.use(function (req, res, next) {
*/
// API allowed for all
api_routes.post('/login', authorize.login);
+api_routes.post('/logout', authorize.logout);
// Validate all other API calls
+// TODO - Validate API calls
//api_routes.use(authorize.genCheckAuthorized('user'));
-api_routes.post('/logout', authorize.logout);
// Add API routes
function addRoutes(r) {
for (var e in r.routes) {
var route = '/' + e + (r.routes[e].params ? "/" + r.routes[e].params : "");
var log = "Adding routes for " + route + ":";
- /*
- var auth = r.routes[e].auth || r.auth;
- if (auth) {
+
+ var isAuth = r.routes[e].auth || r.auth;
+ if (isAuth) {
log += " [auth]";
api_routes.use (route, function (req, res, next) {
if (! auth(req))
@@ -145,14 +146,13 @@ function addRoutes(r) {
next ();
});
}
- */
- /*
+
var role = r.routes[e].role || r.role;
if (role) {
log += " [role:"+role+"]";
api_routes.use (route, authorize.genCheckAuthorized (role));
}
- */
+
const methods = ["get", "post", "put", "delete"];
for (var m in methods) {
if (r.routes[e][methods[m]]) {
@@ -165,12 +165,15 @@ function addRoutes(r) {
}
addRoutes(dbs);
+//addRoutes (admin);
+//addRoutes (files);
/*
* Servers
*/
http.createServer(app).listen(common.config.httpPort, function () {
- console.log("Express http server listening on port " + common.config.httpPort);
+ console.log("Express http server listening on port " +
+ common.config.httpPort);
});
/*
@@ -184,6 +187,8 @@ http.createServer(app).listen(common.config.httpPort, function () {
* openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
* rm certrequest.csr
*/
+// >>>>>>>>>>>>>>>>>>>>>>>>>>> SSL: DISABLED <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+/*
if (common.config.httpsPort) {
var options;
try {
@@ -211,6 +216,8 @@ if (common.config.httpsPort) {
console.log("Note: https server disabled by config");
}
+ common.mongoose.set('useCreateIndex', true);*/
+
/*
* Uncaught Exceptions
*/
diff --git a/server/authorization.js b/server/authorization.js
index 7717ccb..2bfe759 100644
--- a/server/authorization.js
+++ b/server/authorization.js
@@ -3,13 +3,14 @@
/*
* Authorization
*/
-var common, User;
+var common, Users;
const ldap = require ('./ldap_ohm'),
- crypto = require ("../server/crypto");
+ crypto = require ('./crypto'),
+ dbs = require ('./dbs');
// deactivated is not used yet
-const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, deactivated: true, host: true };
-const clientVisibleSession = { user: true, name: true, type: true, mail: true, roles: true };
+const serverVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true, deactivated: true, host: true };
+const clientVisibleSession = { user: true, name: true, type: true, mail: true, roles: true, gender: true };
// Fill in session object
@@ -59,7 +60,6 @@ const authorization = {
});
}
- // TODO Auth: validate session ID
// Check whether to just validate current session ID
if (user === '' && pwd === '') {
console.log ("auth revalidate: " + req.session.user);
@@ -67,9 +67,9 @@ const authorization = {
return returnError();
return returnSession ();
}
-/*
+
// check local database, then ldap
- User.findById (req.body.user) .exec (function (err, entry) {
+ 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) {
if (crypto.checkLocalAuth (entry, req.body.pwd)) {
@@ -80,7 +80,7 @@ const authorization = {
// check ldap
ldap.authorize (user.toLowerCase(), pwd, function (found) {
- console.log ("ldap authorize " + user + " returns " + JSON.stringify (found));
+ //console.log ("ldap authorize " + user + " returns " + JSON.stringify (found));
// No ldap entry either -> unauthorized
if (found == null) {
return returnError ();
@@ -100,7 +100,7 @@ const authorization = {
// Otherwise create standard user entry
return fillSession (req, found, {user:true}, returnSession);
});
- });*/
+ });
},
logout: function (req, res, next) {
fillSession (req, undefined, undefined, function (err) {
@@ -110,9 +110,8 @@ const authorization = {
init: function (_common) {
common = _common;
ldap.init (_common);
- //User = require('../database/user.model.js');;
+ Users = dbs.models.Users;
},
};
-
module.exports = authorization;
diff --git a/server/dbs.js b/server/dbs.js
index afa75e9..402f30f 100644
--- a/server/dbs.js
+++ b/server/dbs.js
@@ -131,14 +131,15 @@ const dbs = {
});
},
},
- "tag": {
+ "tag/id": {
params: ":id",
- /* GET /api/tag/[tag-id]
+ /* GET /api/tag/id/[tag-id]
* -> Tag schema
* Get a particular tag
*/
get: function(req, res) {
- model.Tags.findById(req.params.id) .exec(function(err, result) {
+ model.Tags.findById(req.params.id)
+ .exec(function(err, result) {
if (err) {
console.log (err);
res.status(404).json(err);
@@ -149,6 +150,85 @@ const dbs = {
});
},
},
+ "usr/id": {
+ params: ":id",
+ /* GET /api/usr/[usr-id]
+ * -> 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);
+ }
+ });
+ },
+ },
+ "usr": {
+ /* POST /api/usr
+ * <- User schema
+ * -> User schema
+ * Create a new user
+ */
+ post: function(req, res) {
+ model.User.create({
+ _id: req.body.id,
+ name: req.body.name,
+ type: req.body.type,
+ roles: req.body.roles,
+ hash: req.body.hash,
+ salt: req.body.salt,
+ pwd: req.body.pwd,
+ abos: req.body.abos,
+ bookmarks: req.body.bookmarks,
+ }, function(err, result) {
+ if (err) {
+ console.log (err);
+ return res.status(401).json(err.message);
+ } else {
+ res.json({message: "User created!!"});
+ }
+ if (result == null) {
+ return res.status(500).json("Can not create user.")
+ }
+ });
+ },
+ /* PUT /api/usr
+ * <- User schema
+ * -> 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) {
+ // TODO Save/Update user
+ /*
+ _id: req.body.id,
+ name: req.body.name,
+ type: req.body.type,
+ roles: req.body.roles,
+ hash: req.body.hash,
+ salt: req.body.salt,
+ pwd: req.body.pwd,
+ abos: req.body.abos,
+ bookmarks: req.body.bookmarks,
+ */
+ res.json(data);
+ });
+ });
+ },
+ },
},
/* Initialize requirements
* - DB connection
@@ -169,6 +249,8 @@ const dbs = {
console.log('Database connection error.');
process.exit();
});
+ // Default 'collection.ensureIndex' is deprecated; New is '.createIndexes'
+ common.mongoose.set('useCreateIndex', true);
/* DB Schemata
* Privat fields:
@@ -198,20 +280,19 @@ const dbs = {
model.Tags._list = [ "" ];
var userSchema = common.mongoose.Schema({
- //_id: { type: String },
+ _id: { type: String },
name: { type: String, required: true,
_comment: "" },
pwd: { type: String,
_comment: "" },
- //hash: { type: String },
- //salt: { type: String },
- //type: { type: String },
+ hash: { type: String },
+ salt: { type: String },
+ type: { type: String },
roles: { type: [String], required: true,
_comment: "" },
- tags: { type: [String],
+ abos: { type: [String],
_comment: "" },
//deactivated: { type: Boolean },
- //participating: { type: [String] },
//host: { type: Boolean },
bookmarks: { type: [String],
_comment: "" },
diff --git a/server/ldap_ohm.js b/server/ldap_ohm.js
index 5ae2f06..ced4a34 100644
--- a/server/ldap_ohm.js
+++ b/server/ldap_ohm.js
@@ -7,7 +7,7 @@ const ldap = require('ldapjs');
const ldap_escape = require('ldap-escape');
-// TODO: Where do I get the URL from?? A: Is given.
+// NOTE: Where do I get the URL from?? A: Is given.
var ldap_client = ldap.createClient({
//url: 'ldap://gso2.ads1.fh-nuernberg.de/',
url: 'ldap://sso.cs.ohm-hochschule.de:389/',
@@ -16,7 +16,7 @@ var ldap_client = ldap.createClient({
// timeouts don't work reliably
});
-// TODO: Where do I get the 'bindpath' parameters info from? A: Is given.
+// NOTE: Where do I get the 'bindpath' parameters info from? A: Is given.
const ldap_config = {
bindpath: 'cn=Users,dc=ohm-hochschule,dc=de',
timeout: 2000
@@ -89,14 +89,17 @@ const ldap_ohm = {
console.log("ldap search error after bind for user " + user);
return cb (null);
}
+ // ldap_test output
+// return_object = entry.object;
return cb (return_object);
});
res.on('error', function(err) {
console.log('ldap error: ' + err.message);
});
res.on('end', function(result) {
- // TODO: Did we forget something?
// TODO: analyze result.status?
+// console.info('ldap result: ');
+// console.info(result);
});
});
});