jeudi 16 avril 2015

javascript + nodejs login not working

I'm trying to make a login page that takes the username and password entered and uses them in windows command line. When I test it in its current state, I get "Uncaught ReferenceError: login is not defined" in console.


Here is the code that I am using





<script>
// create the object that will hold the input values
var formValues = {};
function inputObj(formNR, defaultValues) {
var inputs = formNR.getElementsByTagName('input');
for ( var i = 0; i < inputs.length; i++) {
formValues[inputs[i].name] = defaultValues[i];
if(inputs[i].type === 'text' || inputs[i].type === 'password') {
inputs[i].value = defaultValues[i];
document.getElementById(inputs[i].name).innerHTML = defaultValues[i];
}
inputs[i].addEventListener('keyup', function() {
formValues[this.name] = this.value;
document.getElementById(this.name).innerHTML = this.value;
}, false);
}
}
// build a little array with the defaultValues for each input
var defValues =['',''];
// this will push all inputs from the given form in the formValues object.
inputObj(document.forms[0], defValues);
//now lets test the input against cli
function login()
{
var adminname = "-adminname" + " " + formValues.user; //the username
var password = "-password" + " " + formValues.pass; //the password
var testlogin = "-c" + " " + "testlogin"; //the action/command to be performed (see below)
var exec = require('child_process').exec, child;

child = exec('adminname + password + testlogin',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
child();
}
}
</script>



<div class="single-widget-container">
<section class="widget login-widget">
<header class="text-align-center">
<h4>Login to your account</h4>
</header>
<div class="body">
<form class="no-margin"
action="" onsubmit="login()" method="get">
<fieldset>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<input name="user" type="text" class="form-control input-lg"
placeholder="Username">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-lg">
<span class="input-group-addon">
<i class="fa fa-lock"></i>
</span>
<input name="pass" type="password" class="form-control input-lg"
placeholder="Password">
</div>
</div>
</fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-block btn-lg btn-danger">
<span class="small-circle"><i class="fa fa-caret-right"></i></span>
<small>Sign In</small>
</button>
<a class="forgot" href="#">Forgot Username or Password?</a>
</div>
</form>
</div>
<footer>
<div class="facebook-login">
<a href="#"><span><i class="fa fa-copyright"></i> 2015</span></a>
</div>
</footer>
</section>
</div>
<h3>Results</h3>

formValues.user = <span id="user"></span><br>

formValues.pass = <span id="pass"></span><br>



Not totally sure what I'm doing wrong here. Any help is appreciated.


Aucun commentaire:

Enregistrer un commentaire