29 lines
972 B
Python
29 lines
972 B
Python
from flask import request, jsonify, make_response
|
|
from database.crud import insert_data, verify_otp, verify_login
|
|
from app.twilio import send_otp
|
|
from app import app
|
|
|
|
|
|
@app.route("/register", methods=["POST"])
|
|
def create_user():
|
|
data = request.get_json()
|
|
insert_data(schema="Users", data=data)
|
|
send_otp(receiver=data["mobile"])
|
|
return make_response(jsonify("User created, pending OTP verification"))
|
|
|
|
|
|
@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"])
|
|
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"))
|