-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
64 lines (58 loc) · 2.4 KB
/
views.py
File metadata and controls
64 lines (58 loc) · 2.4 KB
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
from init import app, mysql
from flask import jsonify, request, render_template, flash, redirect, logging, url_for
import hashlib,time
from input import *
import pandas as pd
from authentication import authenticate_user
# test_data = []
@app.route('/')
def index():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/register', methods=['GET', 'POST'])
def register_user():
if request.method == "POST":
username = request.form['username']
password = hashlib.md5(request.form['password'].encode()).hexdigest()
if username and password:
cursor = mysql.connection.cursor()
cursor.execute("INSERT INTO users(username, passcode) VALUES (%s, %s)", (username, password))
mysql.connection.commit()
cursor.close()
flash('You are now registered and can log in', 'success')
return redirect(url_for('login'))
return render_template('register.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
# global test_data
if request.method == "POST":
username = request.form['username']
password = hashlib.md5(request.form['password'].encode()).hexdigest()
captcha = request.form['captcha']
if username and password and captcha == '.tie5Roanl':
cursor = mysql.connection.cursor()
result = cursor.execute("SELECT * FROM users WHERE username = %s", [username])
if result > 0:
data = cursor.fetchone()
if password == data[2]:
time.sleep(1)
data = pd.read_csv('test_data.csv',header=None)
# print('mihir',data.head(5))
predicted_user = authenticate_user(data.head(1))
if predicted_user[0].lower() == username.lower():
flash('You are now logged in', 'success')
else:
flash('Hacker', 'danger')
else:
flash('Your username and password does not match', 'danger')
return render_template('login.html')
@app.route('/start_background_script', methods=['GET','POST'])
def background_script():
start_listener()
return ""
@app.route('/stop_background_script', methods=['GET','POST'])
def stop_background_script():
stop_listener()
return ""