Commit f471b1ae authored by arun.uday's avatar arun.uday

Merge branch '1-arun-uday-asset-manager-v1-0' into 'master'

1 arun uday asset manager v1 0

See merge request !5
parents 24d0cc0c 94e90fa8
......@@ -19,10 +19,11 @@ 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
LOG_PATH=log
LOG_LEVEL=INFO
BACKUP_COUNT=100
MAX_BYTES=5
BACKUP_COUNT=5
MAX_BYTES=10000000
......@@ -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 19:15:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-05 19:15:29 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 10:07:03 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:15:22 - ERROR - [MainThread:db_password_matching(): 76] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 11:16:06 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:16:09 - ERROR - [MainThread:db_password_matching(): 76] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 11:16:56 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:17:02 - ERROR - [MainThread:db_password_matching(): 77] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 11:17:37 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:17:39 - ERROR - [MainThread:db_password_matching(): 77] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 11:18:13 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:18:16 - ERROR - [MainThread:db_password_matching(): 77] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 11:18:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 11:18:47 - ERROR - [MainThread:db_password_matching(): 77] - Services Failed with error from process login db password matching hash could not be identified
2023-04-06 12:15:33 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 14:43:59 - ERROR - [MainThread:reset_password(): 318] - Services Failed with error from reset user password 'password'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\user_management_handler.py", line 278, in reset_password
db_user_data["password"]):
KeyError: 'password'
2023-04-06 14:58:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 15:23:00 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 15:23:06 - ERROR - [MainThread:fetch_user_details(): 257] - Services Failed with error from fetch user details unhashable type: 'dict'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\user_management_handler.py", line 237, in fetch_user_details
cursor_data = obj_mongo_user.fetch_all_user_details({"user_id": {obj_stage.not_equal(request.user_id)}},
TypeError: unhashable type: 'dict'
2023-04-06 15:23:41 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-04-06 15:53:28 - 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):
......@@ -47,7 +48,7 @@ class NormalLogin:
try:
response = {"user_id": self.db_user_data["user_id"], "name": self.db_user_data["name"],
"email": email,
"user_role": self.db_user_data["user_role"]}
"user_role": self.db_user_data["user_role"], "login_type": self.db_user_data["login_type"]}
except KeyError:
response = {"user_id": self.db_user_data["user_id"],
"email": 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,13 @@ 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"
ERROR_PASSWORD_FAILED = "Password Validation Failed"
# Data Validation
ERROR_INVALID_PASSWORD = "Invalid Password"
......@@ -28,3 +36,6 @@ 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"
ERROR_MISMATCH_CONFIRM = "New Password and Confirm Password Must Be Same"
ERROR_PASSWORD_EMPTY = "Password Cannot be Empty"
......@@ -25,7 +25,7 @@ class UserActions(BaseModel):
user_id: Optional[str] = None
name: Optional[str] = None
email: Optional[str] = None
password: Optional[str]
password: Optional[str] = None
phone_number: Optional[str] = None
login_type: Optional[str] = None
user_role: Optional[str] = None
......@@ -41,6 +41,7 @@ class ResetPassword(BaseModel):
user_id: str
old_password: Optional[str] = None
new_password: str
confirm_password: str
class UserIDValidation(BaseModel):
......
......@@ -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(),
......@@ -211,14 +226,14 @@ async def user_change_password(
content=DefaultFailureResponse(status="failed",
message=ErrorMessages.ERROR_UNAUTHORIZED_ACCESS).dict(),
status_code=status.HTTP_200_OK)
response = obj_user_handler.reset_password(reset_data)
response = obj_user_handler.reset_password(request, reset_data)
if not response:
return HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
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(),
......
......@@ -60,3 +60,6 @@ class MongoStageCreator:
def regex_stage(self, stage: dict) -> dict:
return self.add_stage("$regex", stage)
def not_equal(self, stage: dict) -> dict:
return self.add_stage("$ne", stage)
......@@ -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
......@@ -20,11 +20,7 @@ class JWT:
# decoding the payload
def decode(self, token):
try:
return jwt.decode(token, self.key, algorithms=self.alg)
except Exception as e:
logging.exception(f"Exception while encoding JWT: {str(e)}")
raise
return jwt.decode(token, self.key, algorithms=self.alg)
# validate the payload
def validate(self, token):
......@@ -39,3 +35,4 @@ class JWT:
except Exception as e:
logging.exception(f"Exception while validating JWT: {str(e)}")
raise
import base64
from typing import Optional
from Cryptodome.Cipher import AES
from passlib.context import CryptContext
from scripts.config import Secrets, Services
from scripts.errors import ErrorMessages
from scripts.logging.logger import logger
......@@ -36,14 +39,37 @@ 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
def check_password_mismatch(self, new_password, confirm_password, old_password: Optional[str] = None):
try:
# decrypting the UI password
password_decrypted = self.password_decrypt(new_password)
confirm_decrypted = self.password_decrypt(confirm_password)
if password_decrypted != confirm_decrypted:
return None, ErrorMessages.ERROR_MISMATCH_CONFIRM
# hashing the decrypted password
if confirm_decrypted is None:
return None, ErrorMessages.ERROR_PASSWORD_EMPTY
if old_password is not None:
return True, confirm_decrypted
hashed_password = self.pwd_context.hash(confirm_decrypted.split("\"")[1])
return True, hashed_password
except Exception as e:
logger.error(f'Services Failed with error from password util check password mismatch {e}')
return None, ErrorMessages.ERROR_PASSWORD_FAILED
......@@ -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