-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
44 lines (32 loc) · 1.24 KB
/
main.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
import mysql.connector as my
from flask import Flask, jsonify
import itertools
app = Flask(__name__)
connection = my.connect(user='root',password='blc332',host='localhost', database='user_info')
cursor = connection.cursor()
table_com = f'CREATE TABLE IF NOT EXISTS data(username varchar(255) PRIMARY KEY, password varchar(200), description varchar(255))'
cursor.execute(table_com)
@app.route('/app/user/<string:u>/<string:p>')
def create_user(u, p):
username = u
passw = p
try:
insert_com = 'INSERT INTO data values(%s,%s,%s)'
data_ = [u,p, 'NULL']
cursor.execute(insert_com, data_)
connection.commit()
return 'Registered Successfully!'
except my.errors.IntegrityError:
return 'Username Already Exists'
@app.route('/app/user/auth/<string:au>/<string:ap>')
def auth(au,ap):
fetch = 'SELECT * FROM data'
cursor.execute(fetch)
data_tuple = cursor.fetchall()
data_list = list(itertools.chain(*data_tuple))
for i in range(0,int(len(data_list)/3)):
if au == data_list[i*3] and ap == data_list[(i*3)+1]:
return 'Login Successfull!'
return 'unsucess'
if __name__ == '__main__':
app.run(debug=True)