a
    AWed                  	   @   s  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ eeZdejd< dejd< eje  ddddddiZeedddedddZeeZe	eZeeZeeZee eje e!dddZ"ej#dd Z$e%d d!d" Z&e'd#d$d% Z(e'd&d'd( Z)e'd)d*d+ Z*e'd,d-d. Z+e'd/d0d1 Z,d2S )3    )Flask)Api)CORS)Mail)MongoEngine)
JWTManager)Config)auth_namespace)TokenService)AuthServiceTZTEMPLATES_AUTO_RELOADZ	templatesZTEMPLATES_FOLDERzBearer TokenZapiKeyZheaderZAuthorizationzWType in the *'Value'* input box below: **'Bearer &lt;JWT&gt;'**, where JWT is the token)typeZinnamedescriptionzAuthentication Service APIz1.0ar  <p>The Authentication Service API is dedicated to user authentication and access control.</p><p>It provides secure and robust authentication mechanisms for user login, registration, and management.</p><p>This service ensures the protection of user data and identity, making it an ideal solution for building a secure user authentication system for your applications.</p>z/swaggerz/api)titleversionr   authorizationsZdocprefix)jwt_payloadreturnc                 C   s$   |d }| d}tt||S )NjtiZsub)getr
   Zis_blacklistedr   Zget_user_by_email)
jwt_headerr   r   Zcurrent_user_id r   /app/app/__init__.pycheck_if_token_revoked?   s    
r   c                 C   s   ddidfS )Nmsgz(Token blacklisted. Please log in again..  r   )r   r   r   r   r   revoked_token_callbackK   s    r   /c                   C   s   dS )Nz`<h1>Welcome to the Authentication Service API</h1><p>Go to <a href='/swagger'>Swagger UI</a></p>r   r   r   r   r   homeR   s    r     c                 C   s   ddddfS )NzInternal Server Errorz@An internal server error occurred while processing your request.errorr   r    r   er   r   r   internal_server_errorX   s
    r%     c                 C   s   ddddfS )NzBad RequestzMThe request you made was invalid. Please check your input data and try again.r!   r&   r   r#   r   r   r   bad_request_error_   s
    r'   r   c                 C   s   ddddfS )NZUnauthorizedz\You are not authorized to access this resource. Please log in and provide valid credentials.r!   r   r   r#   r   r   r   unauthorized_errorf   s
    r(     c                 C   s   ddddfS )NZ	Forbiddenz3You do not have permission to access this resource.r!   r)   r   r#   r   r   r   forbidden_errorm   s
    r*     c                 C   s   ddddfS )Nz	Not Foundz.The requested URL was not found on the server.r!   r+   r   r#   r   r   r   page_not_foundt   s
    r,   N)-Zflaskr   Zflask_restxr   Z
flask_corsr   Z
flask_mailr   Zflask_mongoenginer   Zflask_jwt_extendedr   Zapp.config.settingsr   Zapp.resources.v1.authr	   Zapp.services.tokenr
   Zapp.services.authr   __name__appZconfigZfrom_objectr   ZapiZcorsZdbZjwtZmailZadd_namespaceZtoken_in_blocklist_loaderdictboolr   Zrevoked_token_loaderr   Zrouter   Zerrorhandlerr%   r'   r(   r*   r,   r   r   r   r   <module>   sd   









