I try to make a web service that is to the login of a user. I want the web pages are dynamic, so I work with javascript jquery html and the problem if I filled username and password in the correct values then passing to another
127.0.0.1 - - [12/Apr/2015 08:54:42] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [12/Apr/2015 08:54:51] "POST /login HTTP/1.1" 405 -
this /loginuser
@APP.route('/loginuser', methods=['POST'])
def login():
error = None
con = mdb.connect('localhost','testuser', 'test623', 'test')
cur = con.cursor()
cur.execute("SELECT * FROM ADMIN")
rows = cur.fetchall()
login=False
for row in rows:
if request.form['username'] == row[0] and request.form['password'] == row[1]:
login=True
print request.form['username']
print request.form['password']
if login ==False:
error = 'Invalid Credentials. Please try again.'
response.result == error
else:
response.result == "success"
con.close
and this /login
@APP.route('/login')
def login1():
return render_template('login1.html')
script.js
function loginAndRedirect (){
var user = $('#txtUsername').val();
var pass = $('#txtPassword').val();
$.ajax({
url: '/loginuser',
data: $('form').serialize(),
type: 'POST',
dataType: 'json',
success: function(response){
if (response.result == "success") {
alert("You have been logged in!");
window.location.href="hello.html";
} else {
alert(result.details);
}
},
error: function(error){
console.log(error);
}
});
}
and login:
<!DOCTYPE html>
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>MONOTORING_LAN</title>
<link href="static/css/style.css" rel="stylesheet">
<script src="static/js/jquery-1.9.0.js"></script>
<script src="static/js/script.js"></script>
</head>
<body>
<div class="container">
<section id="content">
<form method="POST" class="form-signin" role="form">
<h1>Login Form</h1>
<div>
<input type="text" id="txtUsername" placeholder="Username" name="username" required autofocus>
<input type="password" id="txtPassword" placeholder="Password" name="password" required autofocus>
<input class="btn btn-default" id = "submitButton" type="submit" value="Login">
</div>
</form><!-- form -->
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}
{% endif %}
</section><!-- content -->
</div><!-- container -->
</body>
<script src="static/js/script.js>
$(".form-signin").on("submit", function(e) {
e.preventDefault();
loginAndRedirect();});
</script>
</html>
/loginuserand/loginhandlers and how you are invoking them that results in the exception?