2020-04-19 21:30:41 +02:00
|
|
|
from flask import request, jsonify, make_response
|
2020-05-28 00:53:23 +02:00
|
|
|
from database.crud import insert_data, verify_otp, verify_login
|
2020-04-28 20:49:13 +02:00
|
|
|
from app.twilio import send_otp
|
2020-03-23 21:17:16 +01:00
|
|
|
from app import app
|
|
|
|
|
|
|
|
|
2020-04-15 00:29:59 +02:00
|
|
|
@app.route("/register", methods=["POST"])
|
2020-04-02 19:33:04 +02:00
|
|
|
def create_user():
|
2020-03-23 21:17:16 +01:00
|
|
|
data = request.get_json()
|
2020-04-15 00:29:59 +02:00
|
|
|
insert_data(schema="Users", data=data)
|
2020-05-28 00:53:23 +02:00
|
|
|
send_otp(receiver=data["mobile"])
|
2020-04-19 21:30:41 +02:00
|
|
|
return make_response(jsonify("User created, pending OTP verification"))
|
|
|
|
|
|
|
|
|
2020-05-28 00:53:23 +02:00
|
|
|
@app.route("/login", methods=["POST"])
|
|
|
|
def log_in():
|
|
|
|
data = request.get_json
|
|
|
|
if verify_login(data=data):
|
|
|
|
return make_response(jsonify("Successful login"))
|
|
|
|
return make_response(jsonify("The email/password combination is not correct"))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/otpVerification", methods=["POST"])
|
2020-04-19 21:30:41 +02:00
|
|
|
def validate_otp():
|
|
|
|
data = request.get_json()
|
|
|
|
if verify_otp(mobile=data["mobile"], otp=data["otp"]):
|
|
|
|
return make_response(jsonify("The OTP has been verified successfully"))
|
|
|
|
return make_response(jsonify("The OTP is not correct"))
|