Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement- Forgot password #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Repository for backend service of Data upload and Validation tool

Code pushes to be done in the `main` branch only.

## Limitations
The character limit on the os.path is 260 characters and the path can not be beyond the limit. Please Keep the file names short.

## Requirements
1. Python dependencies
Expand Down
57 changes: 56 additions & 1 deletion apiServices/src/main/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import hashlib
import jwt
import re
from flask_cors import CORS
import numpy as np
import pymongo
Expand Down Expand Up @@ -231,11 +232,65 @@ def signup():
return {"status" : 200,"code" : "Authenticated","errorFlag" : False,"error" : [],"response" : "User created Successfully."}
else:
# return user already exists
return {"status" : 404,"code" : "Error","errorFlag" : True,"error" : ["UserName already exisiting."],"response" : {"accessToken" : "" }}
return {"status" : 404,"code" : "Error","errorFlag" : True,"error" : ["Please provide a new email, this email is already registered."],"response" : {"accessToken" : "" }}
except Exception as e:
# return error
return {"status" : 500,"code" : str(e) ,"errorFlag" : True,"error" : ["Error in reaching server"],"response" : {"accessToken" : "" }}

def validate_password(password: str) -> bool:
# Check for length (at least 8 characters)
if len(password) < 8:
return False
# Check for at least one uppercase letter
if not re.search(r'[A-Z]', password):
return False
# Check for at least one lowercase letter
if not re.search(r'[a-z]', password):
return False
# Check for at least one digit
if not re.search(r'[0-9]', password):
return False
# Check for at least one special character
if not re.search(r'[@#$%^&+=]', password):
return False
return True

@app.route("/template/api/v1/forgot-password", methods=['POST'])
def forgot_password():
req_body = request.get_json()
try:
userName = req_body['request']['email']
new_password = req_body['request']['new_password']
confirm_password = req_body['request']['confirm_password']

if not userName or not new_password or not confirm_password:
return {"status": 400, "code": "Bad Request", "errorFlag": True, "error": ["All fields are required."]}

if new_password != confirm_password:
return {"status": 400, "code": "Bad Request", "errorFlag": True, "error": ["Passwords do not match."]}

hashed_password = hashlib.md5(new_password.encode('utf-8'))
usersCollection = connectDb(os.environ.get('mongoURL'), os.environ.get('db'), 'userCollection')
user = usersCollection.find_one({'userName': userName})
if not user:
return {"status": 404, "code": "Error", "errorFlag": True, "error": ["The email address provided is not registered."]}

# Validate password complexity
if not validate_password(new_password):
return {"status": 400, "code": "Bad Request", "errorFlag": True, "error": [
"Password must be at least 8 characters long, contain uppercase and lowercase letters, a number, and a special character."
]}

now = datetime.now()
usersCollection.update_one(
{'userName': userName},
{'$set': {"password": str(hashed_password.hexdigest()), "updatedAt": str(now)}}
)
return {"status": 200, "code": "Password Updated", "errorFlag": False, "error": [], "response": "Password updated successfully."}

except Exception as e:
return {"status": 500, "code": str(e), "errorFlag": True, "error": ["Error in reaching server"], "response": "" }

# sample template downloader api
@app.route("/template/api/v1/download/sampleTemplate", methods = ['GET'])
def sample():
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/modules/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def fetch_solution_id(self, access_token, resourceType):
if solution_id in all_parent_solution_ids:
continue
solution_data = {
'Link' : item.get('link', 'None'),
'SOLUTION_NAME': item.get('name', 'N/A'),
'SOLUTION_CREATED_DATE': item.get('createdAt') if item.get('createdAt') != 'None' else None,
'START_DATE': item.get('startDate') if item.get('startDate') != 'None' else None,
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Jinja2==3.1.4
lml==0.1.0
MarkupSafe==2.1.5
mkl==2024.2.1
mkl-fft==1.3.8
mkl-random==1.2.4
mkl-service==2.4.1
mkl-fft==1.3.11
mkl-random==1.2.8
mkl-service==2.4.2
numexpr==2.10.1
numpy==1.26.4
openpyxl==3.1.0
Expand Down