Started a basic Electron app project; adding simple LDAP binding functionality
This commit is contained in:
3
js/index.js
Normal file
3
js/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
window.onload = function(){
|
||||
document.getElementById('ldapHost').textContent = localStorage.getItem('ldap_hostname');
|
||||
};
|
33
js/login.js
Normal file
33
js/login.js
Normal file
@ -0,0 +1,33 @@
|
||||
const ldap = require('ldapjs');
|
||||
|
||||
window.onload = function(){
|
||||
document.getElementById('loginForm').addEventListener('submit', loginForm);
|
||||
};
|
||||
|
||||
|
||||
// do stuff when login form is submitted
|
||||
function loginForm(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var bindHost = document.forms.loginForm.ldap_host.value;
|
||||
var bindDn = document.forms.loginForm.bind_dn.value;
|
||||
var bindPw = document.forms.loginForm.bind_pw.value;
|
||||
|
||||
const client = ldap.createClient({
|
||||
url: 'ldap://' + bindHost + '/'
|
||||
});
|
||||
|
||||
client.bind(bindDn, bindPw, (err) => {
|
||||
if (err) {
|
||||
document.querySelector("h1").textContent = 'error';
|
||||
} else {
|
||||
document.querySelector("h1").textContent = 'Logged in!';
|
||||
|
||||
localStorage.setItem('ldap_hostname', document.forms.loginForm.ldap_host.value);
|
||||
localStorage.setItem('ldap_bind_dn', document.forms.loginForm.bind_dn.value);
|
||||
localStorage.setItem('ldap_bind_pw', document.forms.loginForm.bind_pw.value);
|
||||
|
||||
window.location.href = 'index.html';
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user