diff --git a/.gitignore b/.gitignore index 190e07b..eb1187d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ build dist techdocs.egg-info -test.py \ No newline at end of file +test.py +temp.py diff --git a/TechdocsAPI/backend/__init__.py b/TechdocsAPI/backend/__init__.py index 0ece937..60c08b2 100644 --- a/TechdocsAPI/backend/__init__.py +++ b/TechdocsAPI/backend/__init__.py @@ -10,9 +10,8 @@ from langchain.llms import Clarifai from langchain.chains import LLMChain -from langchain.prompts import PromptTemplate +from langchain.prompts import PromptTemplate -from fastapi_mail import ConnectionConfig, FastMail app = FastAPI(title="Techdocs", version="V0.0.1", @@ -46,23 +45,6 @@ app.state.llmchain = llmchain - conf = ConnectionConfig( - MAIL_USERNAME=config.MAIL_USERNAME, - MAIL_PASSWORD=config.MAIL_PASSWORD, - MAIL_FROM=config.MAIL_FROM, - MAIL_PORT=587, - MAIL_SERVER="smtp.gmail.com", - MAIL_STARTTLS=True, - MAIL_SSL_TLS=False, - TEMPLATE_FOLDER="backend/templates", - USE_CREDENTIALS = True, - VALIDATE_CERTS = True - - # MAIL_TLS=True, - # MAIL_SSL=False - ) - - app.state.mail_client = FastMail(conf) app.state.templates = Jinja2Templates(directory="./backend/templates") diff --git a/TechdocsAPI/backend/core/ConfigEnv.py b/TechdocsAPI/backend/core/ConfigEnv.py index bc8fb89..61b393b 100644 --- a/TechdocsAPI/backend/core/ConfigEnv.py +++ b/TechdocsAPI/backend/core/ConfigEnv.py @@ -21,6 +21,8 @@ class Settings(BaseSettings): CLARIFAI_PAT:str MODEL_VERSION_ID:str + MAIL_SERVER_URL:str + MAIL_USERNAME:str MAIL_PASSWORD:str MAIL_FROM:str diff --git a/TechdocsAPI/backend/core/ExceptionHandlers.py b/TechdocsAPI/backend/core/ExceptionHandlers.py index c3be974..b95fc93 100644 --- a/TechdocsAPI/backend/core/ExceptionHandlers.py +++ b/TechdocsAPI/backend/core/ExceptionHandlers.py @@ -19,6 +19,12 @@ async def email_not_verified(request: Request, exec: EmailNotVerifiedException): content=repr(exec) ) +@app.exception_handler(EmailNotSentException) +async def email_not_sent(request: Request, exec: EmailNotSentException): + return JSONResponse(status_code=status.HTTP_403_FORBIDDEN, + content=repr(exec) + ) + @app.exception_handler(InvalidCredentialsException) async def handle_login_failed(request: Request, exec: InvalidCredentialsException): return JSONResponse(status_code=status.HTTP_403_FORBIDDEN, diff --git a/TechdocsAPI/backend/core/Exceptions.py b/TechdocsAPI/backend/core/Exceptions.py index f314604..0ba6d8d 100644 --- a/TechdocsAPI/backend/core/Exceptions.py +++ b/TechdocsAPI/backend/core/Exceptions.py @@ -43,7 +43,6 @@ def set_statuses(self): def __repr__(self): return "exception.InfoNotFoundException()" - class EmailNotVerifiedException(Exception): def __init__(self): @@ -55,3 +54,15 @@ def set_statuses(self): def __repr__(self): return "exception.EmailNotVerifiedException()" + + +class EmailNotSentException(Exception): + def __init__(self): + self.set_statuses() + super(EmailNotSentException, self).__init__() + + def set_statuses(self): + self.status = 'EmailNotSentException' + + def __repr__(self): + return "exception.EmailNotSentException()" diff --git a/TechdocsAPI/backend/router.py b/TechdocsAPI/backend/router.py index 6f204a6..156159f 100644 --- a/TechdocsAPI/backend/router.py +++ b/TechdocsAPI/backend/router.py @@ -67,7 +67,6 @@ async def inference(generate: Generate, access_token:str=Depends(JWTBearer())): return ops_inference(generate.code_block,generate.api_key,user_sub) - @app.get("/auth/verify/{token}", summary="Verify Email", response_model=GeneralResponse, tags=["Auth Server"]) async def verify_email(request: Request, token:str): response_result = GeneralResponse.get_instance(data={}, diff --git a/TechdocsAPI/backend/services/auth/__init__.py b/TechdocsAPI/backend/services/auth/__init__.py index 78f0b1a..94f3e18 100644 --- a/TechdocsAPI/backend/services/auth/__init__.py +++ b/TechdocsAPI/backend/services/auth/__init__.py @@ -1,2 +1,3 @@ from .ops import * -from .utils.JWTBearer import * \ No newline at end of file +from .utils.JWTBearer import * +from .utils.functools import * \ No newline at end of file diff --git a/TechdocsAPI/backend/services/auth/ops.py b/TechdocsAPI/backend/services/auth/ops.py index add08f6..ade83bb 100644 --- a/TechdocsAPI/backend/services/auth/ops.py +++ b/TechdocsAPI/backend/services/auth/ops.py @@ -1,4 +1,5 @@ from .utils.auth_funcs import * +from .utils.functools import * from .utils.JWTBearer import * from backend.models import * from backend.services.db.utils.DBQueries import DBQueries @@ -11,11 +12,6 @@ from pydantic import ValidationError from jose import jwt -from fastapi_mail import MessageSchema, MessageType - -# import openai -# from transformers import RobertaTokenizer, T5ForConditionalGeneration - async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth): """Wrapper method to handle signup process. @@ -34,22 +30,25 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, # user with the entered credentials already exists raise ExistingUserException(response_result) verifiction_token = Auth.create_access_token(f"{data.username} {data.email}", secret_name='VERIFICATION') - verification_link = f"http://localhost:8000/auth/verify/{verifiction_token}" + verification_link = f"https://caffeinecrew-techdocs.hf.space/auth/verify/{verifiction_token}" email_body_params = { "username": data.username, "verify_link": verification_link } - message = MessageSchema( - subject="Welcome to Techdocs:[Account Verification]", - recipients=[data.email], # List of recipients, as many as you can pass - template_body=email_body_params, - subtype=MessageType.html - ) + details = { + "recipients": [data.email], + "subject": "Welcome to Techdocs:[Account Verification]", + "template_name": "email_verification.html", + "template_kwargs": email_body_params + } + + status = post_request(url=config.MAIL_SERVER_URL, data=details, headers=None) + if status != 200: + raise EmailNotSentException() + - bgtasks.add_task(app.state.mail_client.send_message, message=message, template_name="email_verification.html") - # await app.state.mail_client.send_message(message=message, template_name="email_verification.html") DBQueries.insert_to_database('auth', (data.username, Auth.get_password_hash(data.password), "", 0), ['username', 'password', 'email', 'is_verified']) @@ -143,6 +142,7 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s payload = jwt.decode( token, config.JWT_VERIFICATION_SECRET_KEY, algorithms=[config.ALGORITHM] ) + token_data = TokenPayload(**payload) if datetime.fromtimestamp(token_data.exp)< datetime.now(): return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request}) @@ -155,7 +155,6 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s print(registered_email[0][0]) if registered_email[0][0]: return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request}) - DBQueries.update_data_in_database('auth','is_verified',f"username='{username}'", (True,)) DBQueries.update_data_in_database('auth','email',f"username='{username}'", email) diff --git a/TechdocsAPI/backend/services/auth/utils/functools.py b/TechdocsAPI/backend/services/auth/utils/functools.py new file mode 100644 index 0000000..6393c9f --- /dev/null +++ b/TechdocsAPI/backend/services/auth/utils/functools.py @@ -0,0 +1,9 @@ +import requests +from typing import Any, Dict +import json + +def post_request(url: str, data: Dict[str, Any], headers: Dict[str, str]=None): + json_data = json.dumps(data) + headers = {'Content-type': 'application/json', 'Accept': 'application/json'} + response = requests.post(url, data=json_data, headers=headers) + return response.status_code \ No newline at end of file diff --git a/TechdocsAPI/requirements.txt b/TechdocsAPI/requirements.txt index 048c6e9..970ddc5 100644 --- a/TechdocsAPI/requirements.txt +++ b/TechdocsAPI/requirements.txt @@ -9,4 +9,4 @@ pydantic[email] langchain clarifai Pillow -fastapi_mail==1.3.1 +jinja2 diff --git a/techdocs/pyproject.toml b/techdocs/pyproject.toml index acce1cb..a2e6fc2 100644 --- a/techdocs/pyproject.toml +++ b/techdocs/pyproject.toml @@ -8,12 +8,20 @@ build-backend = "setuptools.build_meta" [project] name = "techdocs" +<<<<<<< HEAD +version = "0.2.0" +======= version = "0.2.1" +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 description = "Code documentation generation CLI App" readme = "README.md" requires-python = ">=3.10" authors = [ +<<<<<<< HEAD + {"name" = "test", "email" = "alfatrion123@gmail.com"}, +======= {"name" = "Caffiene Crew", "email" = "caffienecrewhacks@gmail.com"}, +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 ] dependencies = [ "requests", diff --git a/techdocs/setup.cfg b/techdocs/setup.cfg index aad5b4b..ecec742 100644 --- a/techdocs/setup.cfg +++ b/techdocs/setup.cfg @@ -1,6 +1,10 @@ [metadata] name = techdocs +<<<<<<< HEAD:techdocs/setup.cfg +version = 0.2.0 +======= version = 0.2.1 +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6:setup.cfg [options] packages = techdocs diff --git a/techdocs/setup.py b/techdocs/setup.py index 219c543..ccdebe2 100644 --- a/techdocs/setup.py +++ b/techdocs/setup.py @@ -4,7 +4,11 @@ setup( name='techdocs', +<<<<<<< HEAD:techdocs/setup.py + version='0.2.0', +======= version='0.2.1', +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6:setup.py # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow # pip to create the appropriate form of executable for the target platform. diff --git a/techdocs/techdocs/__init__.py b/techdocs/techdocs/__init__.py index 77648b6..f55fc87 100644 --- a/techdocs/techdocs/__init__.py +++ b/techdocs/techdocs/__init__.py @@ -1 +1,5 @@ -__version__ = "0.2.1" \ No newline at end of file +<<<<<<< HEAD +__version__ = "0.2.0" +======= +__version__ = "0.2.1" +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 diff --git a/techdocs/techdocs/utils/functools.py b/techdocs/techdocs/utils/functools.py index ddaf9f1..76a189f 100644 --- a/techdocs/techdocs/utils/functools.py +++ b/techdocs/techdocs/utils/functools.py @@ -5,6 +5,10 @@ # BASE_URL = "http://127.0.0.1:8000" +<<<<<<< HEAD + +======= +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 def get_access_token(data, return_refresh_token=False): try: url = BASE_URL + "/auth/login" @@ -19,6 +23,14 @@ def get_access_token(data, return_refresh_token=False): return access_token, refresh_token return access_token except Exception as e: +<<<<<<< HEAD + print("Invlaid Credentials") + return None + + + + +======= if response.json() == "exception.InvalidCredentialsException()": print("Please check your credentials") else: @@ -26,6 +38,7 @@ def get_access_token(data, return_refresh_token=False): return None +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 def request_inference(config, code_block, max_retries=1): if max_retries == 0: @@ -53,6 +66,10 @@ def update_file(file_path, docstr_code): file.write(docstr_code) +<<<<<<< HEAD + +======= +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 def issue_api_key(config): try: headers={"accept":"application/json", "Authorization": f"Bearer {config['access_token']}"} @@ -75,7 +92,11 @@ def signup(config): elif (response.status_code!=200): raise Exception("Something went wrong, please try again later") +<<<<<<< HEAD + print("Signed up successfully, please issue a new `API_KEY` to continue") +======= print(response.json()["message"][0].replace('\\n','\n'), "Then issue a new `API_KEY` to continue") +>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6 except Exception as e: print(e)