I made a script that allows a user to login I used python flask microframework jquery but the problem that if I filled the fields user and password it will not have a passage to another page which I have already specified in the method if the data are loginuser correctent. And the second problem is the appraition data in the url.
login1.html
<!DOCTYPE html>
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>login</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 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" type="submit" value="Login">
</div>
</form><!-- form -->
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}
{% endif %}
</section><!-- content -->
</div><!-- container -->
</body>
</html>
$(function(){
$('submit').click(function(){
var user = $('#txtUsername').val();
var pass = $('#txtPassword').val();
$.ajax({
url: '/loginuser',
data: $('form').serialize(),
type: 'POST',
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
});
});
});
this script.js. and app.py
@APP.route('/login')
def login1():
return render_template('login1.html')
# route for handling the login page logic
@APP.route('/loginuser', methods=['POST'])
def login():
error = None
con = mdb.connect('localhost','testuser', 'test623', 'secure')
#con= mdb.connect(host="x.x.x.x", port=3306, passwd="root", db="se")
cur = con.cursor()
cur.execute("SELECT * FROM ADMIN")
rows = cur.fetchall()
login=False
########recuperer la liste des admin de la BD ADMIN
for row in rows:
if request.form['username'] == row[0] and request.form['password'] == row[1]:
login=True
con.close
if login ==False:
error = 'Invalid Credentials. Please try again.'
return render_template('login1.html', error=error)
else:
return render_template('mon.html', error=error)