Update 'userField' from createMsg after Login; Add API for user get, post, put; Refactor API /tag/id
This commit is contained in:
parent
633dbc90f0
commit
92220fc11c
@ -1,6 +1,6 @@
|
|||||||
// 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([
|
||||||
{
|
{
|
||||||
@ -31,5 +31,7 @@ inquirer.prompt([
|
|||||||
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -42,6 +42,7 @@ Vue.component('login-panel', {
|
|||||||
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>
|
||||||
@ -62,6 +63,10 @@ Vue.component('login-panel', {
|
|||||||
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');
|
||||||
|
@ -8,7 +8,7 @@ const CreateMsgRouter = {
|
|||||||
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>
|
||||||
@ -41,8 +41,8 @@ const CreateMsgRouter = {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class=" column is-three-quarters is-pulled-right is-hidden-touch content-desktop">
|
<div class="column is-three-quarters is-pulled-right is-hidden-touch content-desktop">
|
||||||
<div class="content card om-card">
|
<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>
|
||||||
@ -78,6 +78,8 @@ const CreateMsgRouter = {
|
|||||||
|
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
|
auth: auth,
|
||||||
|
isDisabled: false,
|
||||||
selected: [],
|
selected: [],
|
||||||
taglist: data,
|
taglist: data,
|
||||||
};
|
};
|
||||||
@ -91,7 +93,7 @@ const CreateMsgRouter = {
|
|||||||
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",
|
||||||
@ -140,6 +142,18 @@ const CreateMsgRouter = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
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();
|
||||||
@ -147,7 +161,7 @@ const CreateMsgRouter = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -93,7 +93,7 @@ Vue.component('search',{
|
|||||||
// 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);
|
||||||
|
@ -62,7 +62,7 @@ app.use(session({
|
|||||||
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
|
||||||
}));
|
}));
|
||||||
|
@ -60,7 +60,6 @@ const authorization = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
@ -131,14 +131,15 @@ const dbs = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"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);
|
||||||
@ -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
|
/* Initialize requirements
|
||||||
* - DB connection
|
* - DB connection
|
||||||
@ -210,7 +290,7 @@ const dbs = {
|
|||||||
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 },
|
||||||
|
@ -7,7 +7,7 @@ const ldap = require('ldapjs');
|
|||||||
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/',
|
||||||
@ -16,7 +16,7 @@ var ldap_client = ldap.createClient({
|
|||||||
// 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
|
||||||
@ -89,14 +89,17 @@ const ldap_ohm = {
|
|||||||
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…
x
Reference in New Issue
Block a user