-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
510 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#flAuth | ||
|
||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# Logs # | ||
######## | ||
*.log | ||
logfile.txt | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
Icon? | ||
ehthumbs.db | ||
Thumbs.db | ||
*~ | ||
node_modules | ||
|
||
# Local settings # | ||
################## | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
'use strict'; | ||
var mysql = require('mysql'); | ||
var connection = mysql.createConnection({ | ||
host: '192.168.14.21', | ||
user: 'flauth', | ||
password: 'FabLab', | ||
database: 'flauth' | ||
}); | ||
|
||
connection.connect(function(error) { | ||
if(!!error){ | ||
console.log(error); | ||
} else { | ||
console.log('Connected'); | ||
} | ||
}); | ||
|
||
|
||
// MACHINES | ||
exports.list_all_machines = function(req, res) { | ||
connection.query('SELECT * FROM machines', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.list_all_machine_tags = function(req, res) { | ||
connection.query('SELECT t.*, r.start, r.end FROM tags t LEFT JOIN rights r ON t.tid=r.tid WHERE r.end>=now() AND r.mid=' + req.params.mid, function(error, rows, fields) { | ||
//connection.query('SELECT t.*, r.end FROM tags t LEFT JOIN rights r ON r.tid=t.tid WHERE tid IN (SELECT tid FROM rights WHERE start<=now() AND end>=now() AND mid=' + req.params.mid + ')', function(error, rows, fields) { | ||
//connection.query('SELECT * FROM machines', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.list_all_machine_logs = function(req, res) { | ||
connection.query('SELECT * FROM logs WHERE mid=' + req.params.mid, function(error, rows, fields) { | ||
// connection.query('SELECT * FROM machines', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.create_a_machine = function(req, res) { | ||
res.json(req.body); | ||
}; | ||
|
||
exports.read_a_machine = function(req, res) { | ||
connection.query('SELECT * FROM machines WHERE mid=' + req.params.mid, function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.update_a_machine = function(req, res) { | ||
}; | ||
|
||
exports.delete_a_machine = function(req, res) { | ||
}; | ||
|
||
|
||
// TAGS | ||
exports.list_all_tags = function(req, res) { | ||
connection.query('SELECT * FROM tags', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.create_a_tag = function(req, res) { | ||
res.json(req.body); | ||
}; | ||
|
||
exports.read_a_tag = function(req, res) { | ||
connection.query('SELECT * FROM tags WHERE tid=' + req.params.tid, function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.update_a_tag = function(req, res) { | ||
}; | ||
|
||
exports.delete_a_tag = function(req, res) { | ||
}; | ||
|
||
|
||
// RIGHTS | ||
exports.list_all_rights = function(req, res) { | ||
connection.query('SELECT * FROM rights', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.create_a_right = function(req, res) { | ||
res.json(req.body); | ||
}; | ||
|
||
exports.read_a_right = function(req, res) { | ||
connection.query('SELECT * FROM rights WHERE rid=' + req.params.rid, function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.update_a_right = function(req, res) { | ||
}; | ||
|
||
exports.delete_a_right = function(req, res) { | ||
}; | ||
|
||
|
||
// LOGS | ||
exports.list_all_logs = function(req, res) { | ||
connection.query('SELECT * FROM logs', function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.create_a_log = function(req, res) { | ||
res.json(req.body); | ||
}; | ||
|
||
exports.read_a_log = function(req, res) { | ||
connection.query('SELECT * FROM logs WHERE lid=' + req.params.lid, function(error, rows, fields) { | ||
if (error) { | ||
res.send(error); | ||
} else { | ||
res.json(rows); | ||
} | ||
}); | ||
}; | ||
|
||
exports.update_a_log = function(req, res) { | ||
}; | ||
|
||
exports.delete_a_log = function(req, res) { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
var mysql = require('mysql'); | ||
var Schema = mysql.Schema; | ||
|
||
|
||
var TaskSchema = new Schema({ | ||
name: { | ||
type: String, | ||
Required: 'Kindly enter the name of the task' | ||
}, | ||
Created_date: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
status: { | ||
type: [{ | ||
type: String, | ||
enum: ['pending', 'ongoing', 'completed'] | ||
}], | ||
default: ['pending'] | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model('Tasks', TaskSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
module.exports = function(app) { | ||
var aas = require('../controllers/aasController'); | ||
|
||
// machine Routes | ||
app.route('/machines') | ||
.get(aas.list_all_machines) | ||
.post(aas.create_a_machine); | ||
|
||
app.route('/machines/:mid') | ||
.get(aas.read_a_machine) | ||
.put(aas.update_a_machine) | ||
.delete(aas.delete_a_machine); | ||
|
||
app.route('/machines/:mid/tags') | ||
.get(aas.list_all_machine_tags); | ||
|
||
app.route('/machines/:mid/logs') | ||
.get(aas.list_all_machine_logs); | ||
|
||
|
||
// tags Routes | ||
app.route('/tags') | ||
.get(aas.list_all_tags) | ||
.post(aas.create_a_tag); | ||
|
||
app.route('/tags/:tid') | ||
.get(aas.read_a_tag) | ||
.put(aas.update_a_tag) | ||
.delete(aas.delete_a_tag); | ||
|
||
|
||
// rights Routes | ||
app.route('/rights') | ||
.get(aas.list_all_rights) | ||
.post(aas.create_a_right); | ||
|
||
app.route('/rights/:rid') | ||
.get(aas.read_a_right) | ||
.put(aas.update_a_right) | ||
.delete(aas.delete_a_right); | ||
|
||
|
||
// logs Routes | ||
app.route('/logs') | ||
.get(aas.list_all_logs) | ||
.post(aas.create_a_log); | ||
|
||
app.route('/logs/:tid') | ||
.get(aas.read_a_log) | ||
.put(aas.update_a_log) | ||
.delete(aas.delete_a_log); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "Access Authentication Server", | ||
"version": "1.0.0", | ||
"description": "FabLab Access Authentication Server with REST API", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/fablabwinti/access_auth_server.git" | ||
}, | ||
"author": "Claudio Prezzi", | ||
"license": "LGPL-3.0", | ||
"bugs": { | ||
"url": "https://github.com/fablabwinti/access_auth_server/issues" | ||
}, | ||
"homepage": "https://github.com/fablabwinti/access_auth_server#readme", | ||
"devDependencies": { | ||
"nodemon": "^1.11.0" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.17.2", | ||
"express": "^4.15.3", | ||
"mysql": "^2.13.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var express = require('express'); | ||
var app = express(); | ||
var port = process.env.PORT || 3000; | ||
var mysql = require('mysql'); | ||
//var model = require('./api/models/aasModel'); | ||
var bodyParser = require('body-parser'); | ||
|
||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
|
||
var routes = require('./api/routes/aasRoutes'); | ||
routes(app); | ||
|
||
|
||
app.listen(port); | ||
|
||
|
||
console.log('AAS RESTful API server started on: ' + port); |
Oops, something went wrong.