1
1
import flask
2
- from flask import request , jsonify
2
+ from flask import request , jsonify , abort
3
+ from argon2 import PasswordHasher
4
+ from database import *
5
+ import timeit
3
6
4
7
app = flask .Flask (__name__ )
5
8
app .config ["DEBUG" ] = True
@@ -45,4 +48,33 @@ def api_id():
45
48
return jsonify (results )
46
49
47
50
51
+ @app .route ("/api/v1/auth/register" , methods = ["POST" ])
52
+ def api_register ():
53
+ # Calls on the DB method to register a user
54
+ if "username" in request .args and "password" in request .args :
55
+ username = request .args ["username" ]
56
+ password = request .args ["password" ]
57
+ else :
58
+ abort (400 , description = "Error: either username or password not provided" )
59
+
60
+ if does_user_exist (username ):
61
+ abort (400 , description = "Error: User already exists" )
62
+ else :
63
+ password_hash = PasswordHasher (hash_len = 32 ).hash (password )
64
+ print ("Password Hash computed in User Registration: {0}" .format (password_hash ))
65
+ registration_success = register_user (username , password_hash )
66
+ if not registration_success :
67
+ abort (500 )
68
+ else :
69
+ return "User Registered!"
70
+
71
+
72
+ @app .route ("/api/v1/upload" , methods = ["POST" ])
73
+ def upload_file ():
74
+ uploaded_file = request .files ["file" ]
75
+ if uploaded_file .filename != "" :
76
+ uploaded_file .save (uploaded_file .filename )
77
+ return "File Saved"
78
+
79
+
48
80
app .run ()
0 commit comments