forked from Om-Thorat/Sih23
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (55 loc) · 1.58 KB
/
app.py
File metadata and controls
64 lines (55 loc) · 1.58 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 flask import Flask, send_from_directory, request
import pymongo
import bcrypt as bc
import os
from datetime import datetime
app = Flask(__name__)
client = pymongo.MongoClient((os.environ['MONGODB_URI']))
db = client['Track01']
# To expose the main page
@app.route('/')
def root():
return send_from_directory('./client/dist', 'index.html')
# To expose all the assets
@app.route('/<path:path>')
def assets(path):
return send_from_directory('./client/dist',path)
# Backend functions to fetch
@app.route('/time')
def gettime():
return str(datetime.now().strftime("%H:%M:%S"))
@app.route("/upload")
def upload():
img=request.args.get("image");
users = db.users
uploadimage={"image":img}
users.insert_one(uploadimage)
return ["image uploaded"]
@app.route("/login")
def login():
user = request.args.get("user");
pas = request.args.get("pass");
job = request.args.get("job");
bytes = pas.encode('utf-8');
salt = bc.gensalt();
hpas = bc.hashpw(bytes, salt);
print(type(hpas))
users = db.users
entryform = {
"user": user,
"pass": hpas,
"job": job
}
entry = users.find_one({"user":user})
if not entry:
users.insert_one(entryform)
return ["yep",job ,"registered"]
else:
if entry['job'] != job:
return ["nope","Wrong job"]
if (bc.checkpw(pas.encode('utf-8'),entry['pass'])):
return ["yep",str(entry['job'])]
else:
return ["nope","You mistyped it maybe? Try again"]
# if __name__ == "__main__":
# app.run(debug=True)