-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
105 lines (84 loc) · 3.59 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from datetime import datetime
import models
from flask_cors import CORS
from flask import Flask, request, jsonify
from flask_mail import Mail
app = Flask(__name__)
CORS(app, resources={r"*": {"origins": "*"}}, supports_credentials=True)
app.config['CORS_HEADERS'] = 'Content-Type'
url_prefix = "/api/v1/usermng/"
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'createyourown'
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_DEBUG'] = True
app.config['MAIL_DEFAULT_SENDER'] = '[email protected]'
mail = Mail(app)
def _corsify_actual_response(response):
# response.headers.add("Access-Control-Allow-Origin", "*")
response.status_code = 200
return response
@app.route(f'{url_prefix}/signup', methods=["POST", "OPTIONS"])
def index():
try:
data = request.json
if request.method == "OPTIONS":
return _corsify_actual_response(jsonify({"status": None}))
elif data == None:
return _corsify_actual_response(jsonify({"status": False, "message": "No data provided"}))
email = data['email']
password = data['password']
username = data["username"]
mobile_no = data["mobile_no"]
status, message, data = models.insert_user(
username, email, password, mobile_no)
return jsonify({"Data": data, "Status": status, "Message": message})
except Exception as e:
return jsonify({"Status": False, "Message": str(e)})
@app.route(f'{url_prefix}/signin', methods=["POST", "OPTIONS"])
def login():
try:
data = request.json
if request.method == "OPTIONS":
return _corsify_actual_response(jsonify({"status": None}))
elif data == None:
return _corsify_actual_response(jsonify({"status": False, "message": "No data provided"}))
email = data['email']
password = data['password']
status, message, data = models.login(email, password)
return jsonify({"Data": data, "Status": status, "Message": message})
except Exception as e:
return jsonify({"Status": False, "Message": str(e)})
@app.route(f'{url_prefix}/forgetPassword', methods=["OPTIONS", "POST"])
def forgetPassword():
try:
data = request.json
if request.method == "OPTIONS":
return _corsify_actual_response(jsonify({"status": None}))
elif data == None:
return _corsify_actual_response(jsonify({"status": False, "message": "No data provided"}))
email = data['email']
username = data['username']
status, message = models.forget_password(email, username)
return jsonify({"Status": status, "Message": message})
except Exception as e:
return jsonify({"Status": False, "Message": str(e)})
@app.route(f'{url_prefix}/resetPassword', methods=["OPTIONS", "POST"])
def resetPassword():
try:
data = request.json
if request.method == "OPTIONS":
return _corsify_actual_response(jsonify({"status": None}))
elif data == None:
return _corsify_actual_response(jsonify({"status": False, "message": "No data provided"}))
email = data['email']
password = data['password']
new_password = data['new_password']
status, message = models.reset_password(email, password, new_password)
return jsonify({"Status": status, "Message": message})
except Exception as e:
return jsonify({"Status": False, "Message": str(e)})
if __name__ == '__main__':
app.run(debug=True)