verify link core
This commit is contained in:
@@ -61,11 +61,12 @@ def merms_register():
|
||||
response = RegisterService.process_request(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/RegisterVerify", methods=["POST"])
|
||||
#/panel/Register/verify
|
||||
@api.route("/panel/Register/verify", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_register_verify():
|
||||
data = request.get_json()
|
||||
response = RegisterService.process_request(data)
|
||||
response = RegisterService.process_verify(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/RegisterComplete", methods=["POST"])
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from marshmallow import Schema, fields
|
||||
|
||||
class RegisterVerifySchema(Schema):
|
||||
verify_link = fields.Str(required=True)
|
||||
@@ -12,6 +12,8 @@ from app.models import Offer, MembersPending, Members
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from app.api.schemas.register import RegisterSchema
|
||||
from app.api.schemas.register_verify import RegisterVerifySchema
|
||||
|
||||
from flask_mail import Mail, Message
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
@@ -27,17 +29,58 @@ from app.config import Config
|
||||
class RegisterService(BaseService):
|
||||
JWT_SECRET_KEY = Config.JWT_SECRET_KEY
|
||||
|
||||
@staticmethod
|
||||
def process_verify(data):
|
||||
#"verify_link": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiMThmYzg0YTQtYjQzMC00ZWFkLWE4ZjEtMTk2MTJmNzA5ZDE0IiwiZXhwIjoxNzUyMjc2NjQzfQ.UEsSpCkMq8xNTLiqzyCB572tK-9WkeYaSBF4gfvX7vk"
|
||||
try:
|
||||
with db.session.begin():
|
||||
|
||||
validated_data = RegisterService.validate_data(data, RegisterVerifySchema())
|
||||
# Simulate processing
|
||||
verify_link = validated_data.get('verify_link')
|
||||
|
||||
if not verify_link:
|
||||
return jsonify({'message': 'Error - missing verify link'}), 403
|
||||
try:
|
||||
data = jwt.decode(verify_link, RegisterService.JWT_SECRET_KEY, algorithms=["HS256"])
|
||||
except:
|
||||
return jsonify({'status': 'INVALID', 'message': 'Link is invalid'}), 403
|
||||
|
||||
country = {
|
||||
"last_update": datetime.datetime.utcnow(),
|
||||
"list": [
|
||||
{"code": "US", "description": "United States"},
|
||||
{"code": "NG", "description": "Nigeria"},
|
||||
]
|
||||
}
|
||||
|
||||
response_data = {
|
||||
"member_id": 0,
|
||||
"uid": 0,
|
||||
"country": country,
|
||||
}
|
||||
|
||||
return ResponseHelper.success(data=response_data)
|
||||
|
||||
except ValidationError as err:
|
||||
|
||||
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
|
||||
|
||||
except ValueError as err:
|
||||
logger.error(f"{getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.error(result_description=str(err))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the Login request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
with db.session.begin():
|
||||
|
||||
@@ -79,31 +122,31 @@ class RegisterService(BaseService):
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
@staticmethod
|
||||
def check_loan_limits(customer_id):
|
||||
"""
|
||||
Checks if a customer has exceeded the loan limits for given offer.
|
||||
"""
|
||||
loan = Loan.get_customer_last_loan(customer_id)
|
||||
|
||||
if not loan:
|
||||
return True
|
||||
|
||||
offer_id = loan.offer_id[:5]
|
||||
|
||||
offer = Offer.get_offer_by_id(offer_id)
|
||||
if not offer:
|
||||
logger.error(f"Offer not found for offer_id: {offer_id} (customer_id: {customer_id})")
|
||||
return False
|
||||
|
||||
daily_count = Loan.get_daily_loan_count(customer_id, offer.product_id)
|
||||
|
||||
logger.info(f"daily_count: {daily_count}, Max: {offer.max_daily_loans}")
|
||||
|
||||
if offer.max_daily_loans is not None and daily_count >= offer.max_daily_loans:
|
||||
return False
|
||||
|
||||
return True
|
||||
# @staticmethod
|
||||
# def check_loan_limits(customer_id):
|
||||
# """
|
||||
# Checks if a customer has exceeded the loan limits for given offer.
|
||||
# """
|
||||
# loan = Loan.get_customer_last_loan(customer_id)
|
||||
#
|
||||
# if not loan:
|
||||
# return True
|
||||
#
|
||||
# offer_id = loan.offer_id[:5]
|
||||
#
|
||||
# offer = Offer.get_offer_by_id(offer_id)
|
||||
# if not offer:
|
||||
# logger.error(f"Offer not found for offer_id: {offer_id} (customer_id: {customer_id})")
|
||||
# return False
|
||||
#
|
||||
# daily_count = Loan.get_daily_loan_count(customer_id, offer.product_id)
|
||||
#
|
||||
# logger.info(f"daily_count: {daily_count}, Max: {offer.max_daily_loans}")
|
||||
#
|
||||
# if offer.max_daily_loans is not None and daily_count >= offer.max_daily_loans:
|
||||
# return False
|
||||
#
|
||||
# return True
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user