This is validate.py
import cgi
import yate
import sqlite3
connection = sqlite3.connect('users.sqlite')
cursor = connection.cursor()
print(yate.start_response('text/plain'))
form=cgi.FieldStorage()
for each_form_item in form.keys():
if (each_form_item=='username'):
username=form[each_form_item].value
if (each_form_item=='password'):
password=form[each_form_item].value
result=cursor.execute('SELECT USERNAME from validate')
usernames=[row[0] for row in result.fetchall()]
for each_username in usernames:
if (username==each_username):
pass_result=cursor.execute('SELECT PASSWORD from validate where username=?',(each_username,))
password1=[row[0] for row in pass_result.fetchall()]
for each_password in password1:
if (each_password==password):
print('Login Success')
#Here want to run another python program eg welcome.py
else:
print('Login Failure')
The web server is running in the background. I want to webpage to redirect to another python program if the condition in the above code is true. How do I do that?
EDIT:
Index.html
<html>
<head>
<title>Login Page</title>
<link type="text/css" rel="stylesheet" href="coach.css" />
</head>
<body>
<img src="images/logo-cel-transparent_0.png" width="74" height="64"> <strong><img src="images/logo-cel-transparent_0.png" alt="Cel logo" width="74" height="64" align="right">
</strong>
<h1 align="center"><strong>Central Electronics Limited</strong></h1>
<p> </p>
<h2 align="center">Storage Management System</h2>
<p> </p>
<p align="center">Login to System</p>
<p align="center"> </p>
<form action="/cgi-bin/validate.py" method="post">
<div align="center">User name :
<input type="text" name="username" value=""> <br>
Password : <input type="text" name="password" value=""> <br>
<input name="Submit" type="submit" value="Submit">
</div>
</form>
</body>
</html>
When i click on the submit button validate.py runs. Now if the username and password match, I want the web browser to automatically redirect the browser to another py file or html page, without the user needing to do anything.
EDIT2:
I am using a python server whose code is:
from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port))
httpd.serve_forever()
This is run using command prompt. The index page i then open in web browser using "localhost:8080".