-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
98 lines (79 loc) · 3.17 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']= 'sqlite:///test.db'
db= SQLAlchemy(app)
# adding a schema for the alchemy databse
class Info(db.Model):
id= db.Column(db.Integer, primary_key=True)
email= db.Column(db.String(20), nullable=False)
datecreated= db.Column(db.DateTime, default=datetime.utcnow)
def __repr__self():
return '<Task %r>' % self.id
# Define a route for the homepage
@app.route('/')
def index():
return render_template('index.html')
# Define a route to handle the form submission
@app.route('/submit', methods=['GET' ,'POST'])
def submit():
# Get the data from the submitted form
code = request.form.get('code')
# Process the code, perform necessary computations, etc.
result = process_code(code)
# Pass the result back to the HTML template
return render_template('result.html', result=result, code=code)
# route for login page
@app.route('/login')
def login():
return render_template('login.html')
#gives new route of welcome after validation.
@app.route('/welcome' , methods=['GET', 'POST'])
def changed():
email = str(request.form.get('email'))
passw = str(request.form.get('password'))
if (validatePass(passw) and validateEmail(email) and email=="[email protected]" and passw=="Admin123"):
return render_template('welcome.html', email = email , passw = passw)
#this requires moroe testing and debugging for the smae the same type of code
# elif (validateEmail(email)==False):
# return render_template('index.html', email = "Please write correct email address!")
# elif (validatePass(passw)==False):
# return render_template('index.html', passw = "Password should greater than 8 character and not guessable!")
elif (validatePass(passw) == True and validateEmail(email) == True):
return render_template('login.html', email = email, passw = passw)
elif (validatePass(passw) == False and validateEmail(email) == True):
return render_template('login.html', email = email, passw = "Wrong")
else:
return render_template('login.html', email = "", passw = "")
# Function to process the code
def process_code(code):
try:
# Try to compile the code
compiled_code = compile(code, '<string>', 'exec')
return 'Code is valid and makes sense'
except SyntaxError as e:
return f'Code has syntax errors: {str(e)}' + ' Failed Processed Result'
except Exception as e:
return f'An error occurred: {str(e)}' + 'Failed Processed Result'
# validates login email for the page
def validateEmail(email):
count=0
if (email[-4:]==".com" and len(email)>7):
for i in email:
print(i)
if (i=="@"):
count+=1
if count==1:
return True
else:
return False
#validates login password for the page
def validatePass(password):
if (len(password)>=8 and password != "Password123"):
return True
else:
return False
# Run the Flask app
if __name__ == '__main__':
app.run(debug=True)