Add user registration test
This commit is contained in:
@@ -3,10 +3,13 @@ from app import db
|
||||
from app.models import *
|
||||
from app.schema import *
|
||||
from marshmallow import ValidationError
|
||||
from pydoc import locate
|
||||
|
||||
|
||||
def insert_data(schema, data):
|
||||
instance = validate_data(schema=schema, data=data)
|
||||
validate_data(schema=schema, data=data)
|
||||
model = locate("app.models." + schema)
|
||||
instance = model(**data)
|
||||
db.session.add(instance)
|
||||
db.session.commit()
|
||||
|
||||
@@ -22,11 +25,11 @@ def save_otp(mobile, otp):
|
||||
|
||||
|
||||
def validate_data(schema, data):
|
||||
validation_schema = schema + "Schema()"
|
||||
instance = validation_schema
|
||||
schema_name = schema + "Schema"
|
||||
validation_schema = locate("app.schema." + schema_name)
|
||||
instance = validation_schema()
|
||||
try:
|
||||
output = instance.load(data).data
|
||||
return output
|
||||
instance.load(data)
|
||||
except ValidationError as err:
|
||||
print(err.messages)
|
||||
|
||||
@@ -37,16 +40,17 @@ def fetch_stored_otp(mobile):
|
||||
return otp
|
||||
|
||||
|
||||
def validate_otp(mobile):
|
||||
def validate_account(mobile):
|
||||
timestamp = datetime.now()
|
||||
db.session.query(table="Users").filter_by(mobile=mobile).update(
|
||||
dict(otp_valid_time=timestamp)
|
||||
)
|
||||
db.session.query(table="Users").filter_by(mobile=mobile).update(dict(status=1))
|
||||
|
||||
|
||||
def verify_otp(mobile, otp):
|
||||
stored_otp = fetch_stored_otp(mobile=mobile)
|
||||
if stored_otp == otp:
|
||||
validate_otp(mobile=mobile)
|
||||
validate_account(mobile=mobile)
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user