rset [pass
This commit is contained in:
@@ -47,6 +47,15 @@ def serve_paths(filename):
|
||||
swagger_dir = os.path.join("swagger")
|
||||
return send_from_directory(swagger_dir, filename)
|
||||
|
||||
|
||||
@api.route("/panel/auth/reset", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_reset():
|
||||
data = request.get_json()
|
||||
response = LoginService.process_reset(data)
|
||||
return response
|
||||
|
||||
|
||||
@api.route("/panel/Login", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_login():
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from marshmallow import Schema, fields
|
||||
|
||||
class ResetPassStart(Schema):
|
||||
username = fields.Str(required=True)
|
||||
@@ -4,11 +4,78 @@ from flask import jsonify
|
||||
from marshmallow import ValidationError
|
||||
import logging
|
||||
from app.api.integrations import KafkaIntegration
|
||||
|
||||
from app.config import Config
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from flask_mail import Mail, Message
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
|
||||
class BaseService:
|
||||
TRANSACTION_TYPE = None
|
||||
JWT_SECRET_KEY = Config.JWT_SECRET_KEY
|
||||
|
||||
SEND_EMAIL_FROM = Config.SEND_EMAIL_FROM
|
||||
SEND_EMAIL_PASS = Config.SEND_EMAIL_PASS
|
||||
|
||||
|
||||
@staticmethod
|
||||
def send_resetpass_mail(signup_email, pending_uid, pending_id, firstname, lastname):
|
||||
|
||||
pending_member = {
|
||||
"email": signup_email,
|
||||
"pending_uid": pending_uid,
|
||||
"first_name": firstname,
|
||||
"last_name": lastname,
|
||||
"pending_id": pending_id,
|
||||
}
|
||||
jwt_part = jwt.encode(
|
||||
{"user": pending_member, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=3330)},
|
||||
BaseService.JWT_SECRET_KEY, algorithm='HS256'
|
||||
)
|
||||
panel_url = "https://qa-panel.mermsemr.com"
|
||||
link_url = str(panel_url) + '/accreset/' + jwt_part
|
||||
|
||||
msg_body = f"""
|
||||
Hello {firstname},
|
||||
|
||||
You received this message for account reset password
|
||||
|
||||
Follow the link:{link_url}
|
||||
|
||||
For any Support
|
||||
Reach Out
|
||||
support@mermsemr.com
|
||||
"""
|
||||
|
||||
sender_email = BaseService.SEND_EMAIL_FROM
|
||||
sender_password = BaseService.SEND_EMAIL_PASS
|
||||
receiver_email = signup_email
|
||||
subject = "Reset Password Email"
|
||||
body = msg_body
|
||||
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = sender_email
|
||||
msg['To'] = receiver_email
|
||||
msg.attach(MIMEText(body, 'plain')) # or 'html' for HTML content
|
||||
|
||||
try:
|
||||
# For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL)
|
||||
# For other providers, consult their documentation for SMTP server and port
|
||||
server = smtplib.SMTP('smtp.gmail.com', 587)
|
||||
# server.starttls() # Enable TLS encryption
|
||||
server.login(sender_email, sender_password)
|
||||
server.sendmail(sender_email, receiver_email, msg.as_string())
|
||||
print("Email sent successfully!")
|
||||
except Exception as e:
|
||||
print(f"Error sending email: {e}")
|
||||
logger.error(f"Error sending email: {e}")
|
||||
finally:
|
||||
server.quit() # Close the connection
|
||||
|
||||
|
||||
@classmethod
|
||||
def validate_data(cls, data, schema):
|
||||
|
||||
+73
-31
@@ -1,17 +1,18 @@
|
||||
from flask import session, jsonify
|
||||
from app.models.loan import Loan
|
||||
#from app.models.loan import Loan
|
||||
from app.utils.logger import logger
|
||||
from app.api.services.base_service import BaseService
|
||||
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
# from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums import TransactionType
|
||||
from app.api.integrations import SimbrellaIntegration
|
||||
# from app.api.enums import TransactionType
|
||||
# from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Offer, RACCheck, Members
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.models import PasswordReset, Members
|
||||
#from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from app.api.schemas.login import LoginSchema
|
||||
from app.api.schemas.reset_pass_start import ResetPassStart
|
||||
import datetime
|
||||
import jwt
|
||||
import random
|
||||
@@ -19,6 +20,47 @@ from app.config import Config
|
||||
|
||||
|
||||
class LoginService(BaseService):
|
||||
@staticmethod
|
||||
def process_reset(data):
|
||||
try:
|
||||
with db.session.begin():
|
||||
|
||||
validated_data = LoginService.validate_data(data, ResetPassStart())
|
||||
username = validated_data.get('username')
|
||||
member = Members.get_member_by_username(username)
|
||||
if not member:
|
||||
invalid_data = {
|
||||
"error_message": "invalid username or password",
|
||||
"message_key": "invalid_username_or_password",
|
||||
}
|
||||
return ResponseHelper.success(data=invalid_data)
|
||||
PasswordReset.create_reset(username=username)
|
||||
BaseService.send_resetpass_mail(member.email, member.uid, member.id, "FF","LL") #pending_uid, pending_id, firstname, lastname
|
||||
|
||||
response_data = {
|
||||
"error_message": "invalid username or password 000",
|
||||
"message_key": "invalid_username_or_password",
|
||||
}
|
||||
|
||||
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):
|
||||
@@ -150,28 +192,28 @@ class LoginService(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