Commit 69ab56ca authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

Initial commit

parents
Pipeline #311 failed with stages
in 28 seconds
/node_modules
sp-account-metadata.xml
User Account Management
Re-implementation of https://transfer.hft-stuttgart.de/gitlab/sihombing/portal/tree/master/app-useracc using NodeJS and ExpressJS
\ No newline at end of file
const express = require('express');
const http = require('http');
const path = require('path');
const passport = require('passport');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const errorhandler = require('errorhandler');
const flash = require('express-flash');
var env = process.env.NODE_ENV || 'development';
const config = require('./config/config')[env];
var app = express();
app.set('port', config.app.port);
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
app.use(morgan('combined'));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(session(
{
resave: true,
saveUninitialized: true,
secret: 'thisisasecret'
}
));
app.use(flash());
app.use((req, res, next) => {
res.locals.errors = req.flash("error");
res.locals.successes = req.flash("success");
next();
});
app.use(passport.initialize());
app.use(passport.session());
// caching disabled for every route
// NOTE: Works in Firefox and Opera. Does not work in Edge
app.use(function(req, res, next) {
res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
next();
});
require('./routes/routes')(app, config, passport);
//require('./routes/dbconn')(app, config);
require('./routes/api')(app, config, passport);
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
module.exports = {
development: {
app: {
name: 'User Account Management',
port: process.env.PORT || 9989
},
passport: {
strategy: 'saml',
saml: {
path: process.env.SAML_PATH || '/saml/SSO',
entryPoint: process.env.SAML_ENTRY_POINT || 'https://transfer.hft-stuttgart.de/idp/saml2/idp/SSOService.php',
issuer: 'sp-account.m4lab.hft-stuttgart.de',
logoutUrl: 'https://transfer.hft-stuttgart.de/idp/saml2/idp/SingleLogoutService.php'
}
},
database: {
host: 'localhost', // DB host
user: 'DBManager', // DB username
password: 'Stuttgart2019', // DB password
port: 3306, // MySQL port
db: 'test_db', // User DB
dbProject: 'projectdb' // Project DB
},
mailer: {
host: 'mail.hft-stuttgart.de', // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP
authUser: 'ad\\support-transfer',
authPass: '6laumri2',
tlsCiphers: 'SSLv3',
from: 'support-transfer@hft-stuttgart.de',
}
}
}
This diff is collapsed.
{
"name": "m4lab-user-account",
"version": "0.0.1",
"description": "Example for PassportJS SAML strategy",
"author": {
"name": "Rosanny Sihombing",
"email": "rosanny.sihombing@hft-stuttgart.de",
"url": "/"
},
"keywords": [
"m4_lab",
"saml",
"sso"
],
"repository": {
"type": "git",
"url": "https://transfer.gitlab.com/tbd.git"
},
"scripts": {
"start": "nodemon app.js",
"test": ""
},
"dependencies": {
"async": "^3.1.0",
"bcryptjs": "^2.4.3",
"body-parser": "1.15.1",
"cookie-parser": "1.4.3",
"crypto": "^1.0.1",
"errorhandler": "1.4.3",
"express": "4.13.4",
"express-flash": "0.0.2",
"express-session": "1.13.0",
"fs": "0.0.1-security",
"morgan": "1.7.0",
"mysql": "^2.17.1",
"nodemailer": "^6.3.1",
"nodemon": "1.9.2",
"passport": "0.3.2",
"passport-saml": "0.15.0",
"pug": "^2.0.4"
},
"devDependencies": {},
"engines": {
"node": ">= 4.0.0"
},
"license": "MIT"
}
/*
TODO:
Show list of registered services?
*/
// Profile Initialization
$.get( "/api/v1/profile", function(data) {
var title = data.title
var firstname = data.firstname
var lastname = data.lastname
var email = data.email
var industry = data.industry
var organisation = data.organisation
var speciality = data.speciality
// asign to HTML
$("#fullname").text(firstname+' '+lastname);
//document.getElementById('inputFirstname').value = firstname; //JS
$("#inputTitle").val(title); // jQuery
$("#inputFirstname").val(firstname);
$("#inputLastname").val(lastname);
$("#inputEmail").val(email);
$("#inputIndustry").val(industry);
$("#inputOrganisation").val(organisation);
$("#inputSpeciality").val(speciality);
})
.done(function() {
console.log("done");
})
.fail(function() {
console.log( "error" );
})
/*.always(function() {
alert( "finished" );
}) */
\ No newline at end of file
// check password and password confirmation input fields
$('#inputNewPwd, #inputConfirm').on('keyup', function () {
var isBest = false;
var isMatch = false;
// password best practice
if ($('#inputNewPwd').val().length < 8) {
$('#recommendation').html('Must be at least 8 characters').css('color', 'red');
isBest = false;
} else {
$('#recommendation').html('').css('color', 'red');
isBest = true;
}
// match or not?
if ($('#inputNewPwd').val() == $('#inputConfirm').val()) {
$('#message').html('Matching').css('color', 'green');
isMatch = true;
} else {
$('#message').html('Not Matching').css('color', 'red');
isMatch = false;
}
// enable/disable update button
if (isBest && isMatch) {
$('#updateBtn').prop('disabled', false);
} else {
$('#updateBtn').prop('disabled', true);
}
});
\ No newline at end of file
extends error
block content
h2 Cannot find #{url}
\ No newline at end of file
extends error
block content
h1 Error: #{error.message}
if settings['verbose errors']
pre= error.stack
else
p An error ocurred!
\ No newline at end of file
html
head
title Error
body
h1 An error occurred!
block content
\ No newline at end of file
extends layout
block content
if user !== null
h1 Hello, #{user.firstName}
a(href="/profile") Profile
br
a(href="/logout") Logout
else
h1 Welcome
br
a(href="/login") Login
doctype html
html
head
title PassportJS SAML example
block links
link(rel='stylesheet', href='bower_components/bootstrap/dist/css/bootstrap.css')
body
div.container
block content
script(src='bower_components/jquery/dist/jquery.min.js')
script(src='bower_components/bootstrap/dist/js/bootstrap.min.js')
block scripts
<!DOCTYPE html>
<html lang="en">
<head>
<title>User Profile</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="https://transfer.hft-stuttgart.de/css/bootstrap/bootstrap.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous" />
<style>
.collapse {
display: none;
}
.collapse.in {
display: block;
}
.collapsing {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition-timing-function: ease;
-o-transition-timing-function: ease;
transition-timing-function: ease;
-webkit-transition-duration: .35s;
-o-transition-duration: .35s;
transition-duration: .35s;
-webkit-transition-property: height,visibility;
-o-transition-property: height,visibility;
transition-property: height,visibility;
}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script>
$(function(){
$("#header").load("fragment/header.html");
$("#footer").load("fragment/footer.html");
});
</script>
</head>
<body>
<!-- CONTENT -->
<div class="container-fluid">
<div class="row">
<!-- https://getbootstrap.com/docs/4.3/components/navs/ -->
<div class="col-3">
<h5>
<!-- TODO: Firstname + Lastname-->
<span>TODO: Firstname + Lastname</span>
</h5>
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link" href="#" aria-selected="true">Profile</a>
<a class="nav-link" href="#" aria-selected="false">Security</a>
<a class="nav-link" href="#" aria-selected="false">Services</a>
</div>
</div>
<div class="col-sm-9">
<form>
<p><input type="hidden" th:value="${id}"/></p>
<table class="table table-borderless">
<tr>
<th><label for="title">Title</label></th>
<td><input type="text" placeholder="Title"></td>
</tr>
<tr>
<th><label for="firstname">Vorname</label></th>
<td><input type="text" placeholder="Vorname"></td>
</tr>
<tr>
<th><label for="lastname">Nachname</label></th>
<td><input type="text" placeholder="Nachname"></td>
</tr>
<tr>
<th><label for="email">Email</label></th>
<td><input type="text" placeholder="Email"></td>
</tr>
<tr>
<th><label for="email">Unternehmen</label></th>
<td><input type="text" placeholder="Unternehmen"></td>
</tr>
<tr>
<th><label for="email">Branche</label></th>
<td><input type="text" placeholder="Branche"></td>
</tr>
<tr>
<th><label for="email">Fachgebiete</label></th>
<td><input type="text" placeholder="Fachgebiete"></td>
</tr>
</table>
<p><input type="submit" class="btn btn-primary" value="Update" disabled></p>
</form>
</div>
</div>
</div>
<!-- HEADER & FOOTER -->
<script src="https://transfer.hft-stuttgart.de/js/headfoot.js"></script>
</body>
</html>
\ No newline at end of file
include profile.html
\ No newline at end of file
// ==== USER ACOOUNT API ====
var dbconn = require('./dbconn')
module.exports = function (app) {
//console.log(dbconn);
//var con = dbconn.connection
app.get('/api/v1/profile', function (req, res) {
if (req.isAuthenticated()) {
// read data based on ID
dbconn.user.query('SELECT title, firstname, lastname, email, industry, organisation, speciality FROM user WHERE email="'+req.user.email+'"', function (err, rows, fields) {
if (err) throw err
res.send(rows[0])
})
} else {
res.redirect('/');
}
});
}
\ No newline at end of file
-----BEGIN CERTIFICATE-----
MIIFpDCCA4ygAwIBAgIJAKOpWVnPZyUUMA0GCSqGSIb3DQEBCwUAMGcxCzAJBgNV
BAYTAkRFMRIwEAYDVQQIDAlTdHV0dGdhcnQxEjAQBgNVBAcMCVN0dXR0Z2FydDEM
MAoGA1UECgwDSEZUMQ4wDAYDVQQLDAVNNExBQjESMBAGA1UEAwwJU2lob21iaW5n
MB4XDTE5MTEwODE0MzI0M1oXDTIyMDQyNjE0MzI0M1owZzELMAkGA1UEBhMCREUx
EjAQBgNVBAgMCVN0dXR0Z2FydDESMBAGA1UEBwwJU3R1dHRnYXJ0MQwwCgYDVQQK
DANIRlQxDjAMBgNVBAsMBU00TEFCMRIwEAYDVQQDDAlTaWhvbWJpbmcwggIiMA0G
CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDm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H3rSCWtcSG2gipV
6QHwORvcLJ7cZBTnf0rFT8qfk0dU6ZBwqO2bELFicHrwtUjyGEb1D+tELhuqf1jd
7IF4MweLMrx5iLK296LrVK2GYPI10BVP+n0oSLtEkjJ1iZ0GIMsdgiibIoJKw+Wr
Esv81Nzi6fxA4Fciw1156p834diOPICEGpG37qJBAoIBAArDBEdCADT740PAHGxI
K0qcJ0ufOIlwrdYXM+YpOKbmkpLipIHcHbKYkf/TViHTf0N1QlbhTZrqxok78ox3
VqphuRbshB4pyE/Lw33I9imJhKJEnM3FeZJgGOeLdmXxVZYeCMAGAA4+NrO+W+ur
VNA7iNQ8EGBzNmjtcJrXf3G8YcHijwPzCatrqD4ZYstoc33IV6M2U0wMhaQwKiGr
PiGMPANGjoYy3RoqUPhSUcfQp4zH8VyGVEBYis+i4RnR0v24IUSVjP5qtMET0g/s
vFJPIlCFbrPQbUKH/bQrB7aoy7/4x/VskuX8YF6IVLm46LkhdETmMKpq2oILl2UT
djkCggEAM4Z5Kauv5t3k8rgPQxt15Hcxv6TxaW3xLkpme2b5JQ554jXf1YQdvo9y
zSVA+oi05+mLgQ9tiCo1Yevl2Uskliq7vPuBKTe5kLT9GoMhUtV8WLFTOmecI+tI
Dox9SE2NtKwsqelkTm52ApmLglgq5zcyt5r/Gv8FMx8uCyisq5a/x0X71q95uMlF
VZ6QS37c8B6Ic5w/O+9cQpQe8DluMaOZ/swGf6ZY/Czt/xL36J+zh4RknN0WBYkR
A3GgYuQxGARFOqg7yqsRY3wuySIcJyAICk0vJH4ynyQf1nzYruJbT/4eRqTdJdOh
7lI0pJL0b06GCO5cXcrZizZJIcQf7g==
-----END PRIVATE KEY-----
const mysql = require('mysql')
var env = process.env.NODE_ENV || 'development';
const config = require('../config/config')[env]
// ==== USER ACOOUNT DB CONNECTION ====
var userConnection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.db
})
userConnection.connect(function(err) {
if (err) throw err;
})
userConnection.query('USE '+config.database.db)
// db connection test
userConnection.query('SELECT 1 + 5 AS solution', function (err, rows, fields) {
if (err) throw err
console.log('Solution = ', rows[0].solution)
})
//userConnection.end()
// ALTERNATIVE approach: close db connection manually after every query
/*
var dbconn = function dbconn(query, values, next) {
var connection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.db
})
connection.connect(function(err) {
if (err) throw err;
})
connection.query(query, values, function(err) {
connection.end(); // close the connection
if (err) {
throw err;
}
// Execute the callback
next.apply(this, arguments);
});
}
*/
// ==== PROJECT DB CONNECTION ====
var projectConnection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.dbProject
})
projectConnection.connect(function(err) {
if (err) throw err;
})
projectConnection.query('USE '+config.database.dbProject)
// projectdb connection test
projectConnection.query('SELECT 10 + 5 AS project', function (err, rows, fields) {
if (err) throw err
console.log('Project = ', rows[0].project)
})
//projectConnection.end()
var connection = {
user: userConnection,
project: projectConnection
}
module.exports = connection
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment