-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSignup.py
40 lines (30 loc) · 1.17 KB
/
Signup.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
from flask_restful import reqparse, Resource
from flask import jsonify, make_response
from flasgger import swag_from
import validators
from src.DbHandler import DbHandler
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument('username', type=str, required=True)
parser.add_argument('password', type=str, required=True)
class Signup(Resource):
@swag_from('../../yml/signup.yml')
def post(self):
args = parser.parse_args()
username = args["username"]
password = args["password"]
# Validate if username is Email or not
if not validators.email(username):
return make_response(
jsonify(msg="Username should be an valid Email."), 400
)
validate_sign_up = DbHandler.add_new_user(username, password)
return_message = ""
if validate_sign_up == "OK":
return_message = make_response(
jsonify(username=username, msg="User created"), 200
)
elif validate_sign_up == "USER_EXISTS":
return_message = make_response(
jsonify({"msg": "Username exists"}), 403
)
return return_message