Commit 3c064dd1 authored by arun.uday's avatar arun.uday

AssetManagerV1.0-Not Reviewed

Log files Updated.
All Files return statements are updated for exceptions.
Comments are updated
parent a0a786d6
......@@ -19,6 +19,7 @@ EMAIL_PORT=465
EMAIL_PASSWORD=gpphuiweedqukchf
HTML_LINK=scripts/utils/link_email.html
RESET_ENDPOINT=http://localhost:8671/asset_manager_api/v1/login/reset?token
REDIRECT_URL_RESET=http://192.168.2.102/iLens_UI/#/l/login
CLIENT_ID=1060631831358-a21djaa3hm165a8976fnmo1lerujs5p6.apps.googleusercontent.com
......
......@@ -38,5 +38,5 @@ if __name__ == "__main__":
# starting the app
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
except Exception as e:
logger.exception(f'Services Failed with error {e}')
logger.exception(f'Services Failed with error from app {e}')
2023-04-04 20:12:33 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-05 11:00:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:08:30 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-05 10:58:48 - ERROR - [MainThread:reset_user_password(): 258] - Services Failed with error from reset user password 'ResetPassword' object has no attribute 'password'
2023-04-04 20:07:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-05 10:54:36 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-05 10:14:04 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:12:33 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:10 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:08:30 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:07:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-04 20:06:10 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
......@@ -37,4 +37,4 @@ if __name__ == "__main__":
allow_headers=ServiceConf.CORS_ALLOW_HEADERS,
)
except Exception as e:
logger.error(e)
logger.error(f'Services Failed with error from main {e}')
import pathlib
from typing import Literal
from pydantic import BaseSettings, Field
......@@ -24,6 +21,7 @@ class _Services(BaseSettings):
EMAIL_PASSWORD: str
HTML_LINK: str
RESET_ENDPOINT: str
REDIRECT_URL_RESET: str
DATE_TIME = '%Y-%m-%d %H:%M:%S'
......
......@@ -42,4 +42,5 @@ class DashboardManagement:
data=data).dict(),
status_code=status.HTTP_200_OK)
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from download header {e}')
return None
This diff is collapsed.
......@@ -31,7 +31,8 @@ class NormalLogin:
return ErrorMessages.ERROR_INVALID_PASSWORD
return None
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from process login user data validation {e}')
return None
# db validation
def db_data_validation(self, login_type, email):
......@@ -55,7 +56,8 @@ class NormalLogin:
# if the user exist
return None, response
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from process login db data validation {e}')
return True, "Exception"
# matching the password
def db_password_matching(self, login_type, user_data, password):
......@@ -71,14 +73,19 @@ class NormalLogin:
# if the password is correct
return None, message
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from process login db password matching {e}')
return True, "Exception"
@staticmethod
def update_pic(obj_mongo_user, info_data):
if not obj_mongo_user.update_user({"email": info_data["email"]},
{"name": info_data["name"], "pic_url": info_data["picture"]}):
try:
if not obj_mongo_user.update_user({"email": info_data["email"]},
{"name": info_data["name"], "pic_url": info_data["picture"]}):
return None
return True
except Exception as e:
logger.error(f'Services Failed with error from process login update pic {e}')
return None
return True
# cookie and token creation
@staticmethod
......@@ -95,4 +102,5 @@ class NormalLogin:
else:
return None
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from process login cookie tokens {e}')
return None
......@@ -58,9 +58,3 @@ class MongoUser(CollectionBaseClass):
if user := self.delete_one(query=query):
return user
return None
# for filtering
def filter_data_aggregate(self, pipeline):
if user := self.aggregate(pipelines=pipeline):
return user
return None
......@@ -6,6 +6,7 @@ class ErrorMessages:
ERROR_INVALID_LOGIN = "Your are not authorized to view this website."
ERROR_ACCOUNT_DOESNT_EXIST = "Account Does Not Exist"
ERROR_UNAUTHORIZED_USER_LOGIN = "Account is not available"
ERROR_IN_LOGIN = "Login Error"
ERROR_UNAUTHORIZED_ACCESS = "Your are not authorized to view this page"
ERROR_ACCESS_DENIED = "Access Denied!"
ERROR_USER_NOT_REGISTERED = "Account is not registered in the portal."
......@@ -18,6 +19,12 @@ class ErrorMessages:
ERROR_INVALID_REQUEST = "Invalid Request"
ERROR_USER_SESSION = "Not The Users Session"
ERROR_TOKEN_EXPIRED = "Google Token Expired"
ERROR_IN_SENDING_MAIL = "Error In Sending Mail"
ERROR_IN_RESETTING_PASSWORD = "Password Reset Failed"
ERROR_IN_REGISTERING = "User Cannot Be Added"
ERROR_IN_DELETING = "User Deletion Error"
ERROR_IN_FETCHING_HEADER = "Header Fetch Failed"
ERROR_IN_LOGOUT = "Logout Failed"
# Data Validation
ERROR_INVALID_PASSWORD = "Invalid Password"
......@@ -28,3 +35,4 @@ class ErrorMessages:
ERROR_USER_ID_DOESNT_EXIST = "User Id doesn't exist"
ERROR_USER_ID = "User Id Not Required"
ERROR_INVALID_TOKEN = "Invalid Token"
ERROR_IN_VALIDATION = "Validation Failed"
......@@ -43,7 +43,7 @@ async def login_default_api(
detail=ErrorMessages.ERROR_INVALID_REQUEST)
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from login_default_api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -58,9 +58,14 @@ async def forgot_password(
try:
# forgot password
response = obj_login_handler.forgot_password_handler(validation_data.email)
if not response:
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.ERROR_IN_SENDING_MAIL).dict(),
status_code=status.HTTP_200_OK)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from forgot password api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -75,9 +80,14 @@ async def reset_password(
try:
# Get the JWT token from the query parameters
response = obj_login_handler.validate_jwt(request)
if not response:
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.ERROR_IN_RESETTING_PASSWORD).dict(),
status_code=status.HTTP_200_OK)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from get reset password api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -92,9 +102,14 @@ async def reset_password(
try:
# Get the JWT token from the query parameters
response = obj_login_handler.reset_user_password(reset_data)
if not response:
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.ERROR_IN_RESETTING_PASSWORD).dict(),
status_code=status.HTTP_200_OK)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from post reset password api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -135,7 +150,7 @@ async def user_management(
status_code=status.HTTP_403_FORBIDDEN,
detail=ErrorMessages.ERROR_INVALID_REQUEST)
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from user management api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -163,7 +178,7 @@ async def user_view_header(
detail=ErrorMessages.ERROR_IN_FETCHING)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from view users header api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -190,7 +205,7 @@ async def user_view_data(
detail=ErrorMessages.ERROR_IN_FETCHING)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from view users data api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -218,7 +233,7 @@ async def user_change_password(
detail=ErrorMessages.ERROR_IN_FETCHING)
return response
except Exception as e:
logger.exception(f"From user change password - {e}")
logger.exception(f'Services Failed with error from change password api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -245,7 +260,7 @@ async def dashboard_download_files(
detail=ErrorMessages.ERROR_IN_FETCHING)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from download button api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......@@ -268,7 +283,7 @@ async def user_logout(
detail=ErrorMessages.ERROR_IN_FETCHING)
return response
except Exception as e:
logger.exception(e)
logger.exception(f'Services Failed with error from logout api {e}')
return JSONResponse(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.OP_FAILED).dict(),
......
......@@ -11,7 +11,8 @@ class RegexValidation:
regex = re.fullmatch(r'^([A-Za-z]+)*$', str(name))
return regex
except Exception as e:
logger.error(f'An Error While listing the home plans {str(e)}')
logger.error(f'Error in name regex {str(e)}')
return None
@staticmethod
def phone_number_validation(phone_number):
......@@ -19,7 +20,8 @@ class RegexValidation:
regex = re.fullmatch('([0-9]{1,20})', str(phone_number))
return regex
except Exception as e:
logger.error(f'An Error While listing the home plans {str(e)}')
logger.error(f'An Error in phone number regex {str(e)}')
return None
@staticmethod
def password_validation(password):
......@@ -29,4 +31,5 @@ class RegexValidation:
return False
except Exception as e:
logger.error(f'An Error While listing the home plans {str(e)}')
logger.error(f'Error in password regex {str(e)}')
return None
from typing import Optional
from scripts.database.mongo.mongo_db import MongoUser
from scripts.logging.logger import logger
from scripts.schemas.project_schema import ResetPassword
obj_mongo_user = MongoUser()
......@@ -18,13 +19,20 @@ class AuthorizeAccess:
return True
except TypeError:
return False
except Exception as e:
logger.error(f'Services Failed with error from authorize access {e}')
return False
@staticmethod
def login_authorize(request, reset_data: Optional[ResetPassword] = None):
if reset_data is not None:
if reset_data.user_id != request.user_id:
return False
return True
if request.user_id:
return True
return False
try:
if reset_data is not None:
if reset_data.user_id != request.user_id:
return False
return True
if request.user_id:
return True
return False
except Exception as e:
logger.error(f'Services Failed with error from login authorize {e}')
return False
......@@ -39,3 +39,4 @@ class JWT:
except Exception as e:
logging.exception(f"Exception while validating JWT: {str(e)}")
raise
......@@ -36,14 +36,19 @@ class EncryptDecryptPassword:
data = self.un_pad(data)
return data.decode(Services.ENCODING_TYPE)
except Exception as e:
logger.exception(e)
logger.error(f'Services Failed with error from password util password decrypt {e}')
return None
# encrypting the password
def password_encrypt(self, password):
# decrypting the UI password
decrypted_password = self.password_decrypt(password)
# hashing the decrypted password
if decrypted_password is None:
try:
# decrypting the UI password
decrypted_password = self.password_decrypt(password)
# hashing the decrypted password
if decrypted_password is None:
return None
hashed_password = self.pwd_context.hash(decrypted_password.split("\"")[1])
return hashed_password
except Exception as e:
logger.error(f'Services Failed with error from password util password encrypt {e}')
return None
hashed_password = self.pwd_context.hash(decrypted_password.split("\"")[1])
return hashed_password
......@@ -12,36 +12,33 @@ class UserDataValidations:
def register_data_validation(user_data, method, feature):
try:
if user_data.name == "":
return False, {"message": ErrorMessages.ERROR_INVALID_NAME,
"data": user_data.phone_number}
return False, ErrorMessages.ERROR_INVALID_NAME
# checking for valid username
if user_data.email == "" or validate_email(
user_data.email) is not True:
return False, {"message": ErrorMessages.ERROR_INVALID_EMAIL, "data": user_data.email}
return False, ErrorMessages.ERROR_INVALID_EMAIL
# checking for valid password
if method == 'general':
if user_data.password == "" or user_data.password == "string":
return False, {"message": ErrorMessages.ERROR_INVALID_PASSWORD, "data": user_data.password}
return False, ErrorMessages.ERROR_INVALID_PASSWORD
# Validate phone number
if user_data.phone_number == "":
return False, {"message": ErrorMessages.ERROR_INVALID_PHONE_NUMBER,
"data": user_data.phone_number}
return False, ErrorMessages.ERROR_INVALID_PHONE_NUMBER
if user_data.user_role == "" and method == 'general' and feature == 'register':
return False, {"message": ErrorMessages.ERROR_INVALID_USER_ROLE,
"data": user_data.phone_number}
return False, ErrorMessages.ERROR_INVALID_USER_ROLE
return True, None
except Exception as e:
logger.exception(e)
logger.error(f'Register data validation error {e}')
return False, ErrorMessages.ERROR_IN_VALIDATION
@staticmethod
def update_data_validation(user_data):
try:
if user_data.name == "":
return False, {"message": ErrorMessages.ERROR_INVALID_NAME,
"data": user_data.phone_number}
return False, ErrorMessages.ERROR_INVALID_NAME
if user_data.user_role == "":
return False, {"message": ErrorMessages.ERROR_INVALID_USER_ROLE,
"data": user_data.phone_number}
return False, ErrorMessages.ERROR_INVALID_USER_ROLE
return True, None
except Exception as e:
logger.exception(e)
logger.error(f'Update data validation error {e}')
return False, ErrorMessages.ERROR_IN_VALIDATION
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment