Browse Source

Update 'userField' from createMsg after Login; Add API for user get, post, put; Refactor API /tag/id

master
Erik Römmelt 5 years ago
parent
commit
92220fc11c
8 changed files with 120 additions and 17 deletions
  1. 4
    2
      ldap_test.js
  2. 5
    0
      public/routes/auth.js
  3. 19
    5
      public/routes/createMessage.js
  4. 1
    1
      public/search.js
  5. 1
    1
      server.js
  6. 0
    1
      server/authorization.js
  7. 84
    4
      server/dbs.js
  8. 6
    3
      server/ldap_ohm.js

server/ldap_test.js → ldap_test.js View File

// Terminal call: node server/ldap_test.js - needs VPN or eduroam // Terminal call: node server/ldap_test.js - needs VPN or eduroam
const inquirer = require('inquirer'), const inquirer = require('inquirer'),
ldap = require('./ldap_ohm.js');
ldap = require('./server/ldap_ohm.js');


inquirer.prompt([ inquirer.prompt([
{ {
.then(answers => { .then(answers => {
ldap.init(null); ldap.init(null);
ldap.authorize(answers.username,answers.password,function(user) { ldap.authorize(answers.username,answers.password,function(user) {
console.log(JSON.stringify(user));
console.log(JSON.stringify(user));
process.exit();
}); });
}); });


+ 5
- 0
public/routes/auth.js View File

type="password" type="password"
placeholder="Password" placeholder="Password"
:value="pwd" :value="pwd"
@change="pwd_changed"
@keyup.enter.native="login" @keyup.enter.native="login"
required> required>
</b-input> </b-input>
error: false, error: false,
}; };
}, },
// TODO: Check if enough for session cookie re-login; checkbox
// mounted: function() {
// this.checkData();
// },
methods: { methods: {
closeLoginPanel: function() { closeLoginPanel: function() {
this.$emit('close-login-panel'); this.$emit('close-login-panel');

+ 19
- 5
public/routes/createMessage.js View File

template: ` template: `
<div class="content"> <div class="content">
<div class="is-hidden-desktop"> <div class="is-hidden-desktop">
<div class="content card om-card">
<div id="mobile" class="content card om-card">
<h4>Neue Nachricht erstellen</h4> <h4>Neue Nachricht erstellen</h4>
<b-field> <b-field>
<b-input placeholder="User" id="user"></b-input> <b-input placeholder="User" id="user"></b-input>
</div> </div>
</div> </div>


<div class=" column is-three-quarters is-pulled-right is-hidden-touch content-desktop">
<div class="content card om-card">
<div class="column is-three-quarters is-pulled-right is-hidden-touch content-desktop">
<div id="desktop" class="content card om-card">
<h4>Neue Nachricht erstellen</h4> <h4>Neue Nachricht erstellen</h4>
<b-field> <b-field>
<b-input placeholder="User" id="user"></b-input> <b-input placeholder="User" id="user"></b-input>


data: function () { data: function () {
return { return {
auth: auth,
isDisabled: false,
selected: [], selected: [],
taglist: data, taglist: data,
}; };
var _subject = $("#subject").val(); var _subject = $("#subject").val();
var _message = $("#message").val(); var _message = $("#message").val();
var _tag = tagArray; var _tag = tagArray;
var _user = $("#user").val();
var _user = auth.name ? auth.name : $("#user").val();
//console.log("Message Created: " + _tag + " " + _message + " " + _user); //console.log("Message Created: " + _tag + " " + _message + " " + _user);
$.ajax({ $.ajax({
url: "api/msg", url: "api/msg",
} }
}, },
mounted: function () { 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(); this.list_tags();
if ($(this).bootstrapMaterialDesign) if ($(this).bootstrapMaterialDesign)
$(this).bootstrapMaterialDesign(); $(this).bootstrapMaterialDesign();
}; };


function get_insert_tag(id){ function get_insert_tag(id){
$.ajax({ url: "api/tag/"+id, method: "GET" }).done(function (tag) {
$.ajax({ url: "api/tag/id/"+id, method: "GET" }).done(function (tag) {
data.push("#" + tag.name); data.push("#" + tag.name);
console.log("Array:"+this.data); console.log("Array:"+this.data);
}).fail(function (e, f, g) { }).fail(function (e, f, g) {

+ 1
- 1
public/search.js View File

// Global Functions !!! // Global Functions !!!
function get_insert_tag(id) { function get_insert_tag(id) {
$.ajax({ $.ajax({
url: "api/tag/" + id,
url: "api/tag/id/" + id,
method: "GET" method: "GET"
}).done(function(tag) { }).done(function(tag) {
dat.push("#" + tag.name); dat.push("#" + tag.name);

+ 1
- 1
server.js View File

name: 'om.sid', name: 'om.sid',
store: new MongoStore({ store: new MongoStore({
mongooseConnection: mong.connection, mongooseConnection: mong.connection,
ttl: 30 * 24 * 3600
ttl: 30 * 24 * 3600,
}), // mongoose + connect-mongo }), // mongoose + connect-mongo
//store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore //store: new MemoryStore ({checkPeriod: 24*3600*1000}), // memorystore
})); }));

+ 0
- 1
server/authorization.js View File

}); });
} }


// TODO Auth: validate session ID
// Check whether to just validate current session ID // Check whether to just validate current session ID
if (user === '' && pwd === '') { if (user === '' && pwd === '') {
console.log ("auth revalidate: " + req.session.user); console.log ("auth revalidate: " + req.session.user);

+ 84
- 4
server/dbs.js View File

}); });
}, },
}, },
"tag": {
"tag/id": {
params: ":id", params: ":id",
/* GET /api/tag/[tag-id]
/* GET /api/tag/id/[tag-id]
* -> Tag schema * -> Tag schema
* Get a particular tag * Get a particular tag
*/ */
get: function(req, res) { 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) { if (err) {
console.log (err); console.log (err);
res.status(404).json(err); res.status(404).json(err);
}); });
}, },
}, },
"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 /* Initialize requirements
* - DB connection * - DB connection
type: { type: String }, type: { type: String },
roles: { type: [String], required: true, roles: { type: [String], required: true,
_comment: "" }, _comment: "" },
tags: { type: [String],
abos: { type: [String],
_comment: "" }, _comment: "" },
//deactivated: { type: Boolean }, //deactivated: { type: Boolean },
//host: { type: Boolean }, //host: { type: Boolean },

+ 6
- 3
server/ldap_ohm.js View File

const ldap_escape = require('ldap-escape'); 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({ var ldap_client = ldap.createClient({
//url: 'ldap://gso2.ads1.fh-nuernberg.de/', //url: 'ldap://gso2.ads1.fh-nuernberg.de/',
url: 'ldap://sso.cs.ohm-hochschule.de:389/', url: 'ldap://sso.cs.ohm-hochschule.de:389/',
// timeouts don't work reliably // 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 = { const ldap_config = {
bindpath: 'cn=Users,dc=ohm-hochschule,dc=de', bindpath: 'cn=Users,dc=ohm-hochschule,dc=de',
timeout: 2000 timeout: 2000
console.log("ldap search error after bind for user " + user); console.log("ldap search error after bind for user " + user);
return cb (null); return cb (null);
} }
// ldap_test output
// return_object = entry.object;
return cb (return_object); return cb (return_object);
}); });
res.on('error', function(err) { res.on('error', function(err) {
console.log('ldap error: ' + err.message); console.log('ldap error: ' + err.message);
}); });
res.on('end', function(result) { res.on('end', function(result) {
// TODO: Did we forget something?
// TODO: analyze result.status? // TODO: analyze result.status?
// console.info('ldap result: ');
// console.info(result);
}); });
}); });
}); });

Loading…
Cancel
Save