
    E.iC                         S SK JrJr  S SKJr  S SKJr  S SKJr  S SK	J	r	J
r
Jr  S SKJr  S SKrS SKJr  S SKrS SKr " S	 S
5      rg)    )	UserModelCustomerModel)HTTPException)pwd_context)	UserClass)datetime	timedeltadate)UnionN)jwtc                   R    \ rS rSrS rS rS rSS\S\\	S4   4S jjr
S	 rS
 rSrg)AuthenticationClass   c                     Xl         g Ndb)selfr   s     ZC:\Users\jesus\Desktop\proyecto_pie360\backend\app\backend\classes\authentication_class.py__init__AuthenticationClass.__init__   s        c                    [        U R                  5      R                  SU5      nU(       a  US:X  d  UR                  S5      (       a  [	        SSSS0S9e[
        R                  " U5      nU R                  X$S	   S
   5      (       d  [	        SSSS0S9eUS	   R                  S5      nUS	   R                  S5      nU(       a  US:w  a  U R                  R                  [        5      R                  [        R                  U:H  5      R                  5       nU(       a>  UR                  (       a-  UR                  [        R                  " 5       :  a
  [	        SSS9eU$ )Nemailz3No se encontraron datos para el campo especificado.zError:i  zCould not validate credentialszWWW-AuthenticateBearer)status_codedetailheaders	user_datahashed_passwordrol_idcustomer_id   i  z'La licencia ha expirado. Debe renovarla)r   r   )r   r   get
startswithr   jsonloadsverify_passwordqueryr   filteridfirstlicense_timer
   today)r   r   passworduserresponse_datar!   r"   customers           r   authenticate_user%AuthenticationClass.authenticate_user   s?   !%%gu5tTTX\XgXghpXqXqC8Xcuw  cA  B  B

4(##HK.HIZ.[\\C8Xcuw  cA  B  B {+//9#K044]C6Q;ww}}]3::=;K;K{;Z[aacHH11((4::<7'C@ijjr   c                 .    [         R                  " X5      $ r   )r   verify)r   plain_passwordr    s      r   r(   #AuthenticationClass.verify_password&   s    !!.BBr   Ndatatime_expirec                 2   UR                  5       nUc   [        R                  " 5       [        SS9-   nO[        R                  " 5       U-   nUR	                  SU05        [
        R                  " U[        R                  S   [        R                  S   S9nU$ )Ni@B )minutesexp
SECRET_KEY	ALGORITHM)	algorithm)	copyr   utcnowr	   updater   encodeosenviron)r   r9   r:   	data_copyexpirestokens         r   create_token AuthenticationClass.create_token)   sw    IIK	oo')G*DDGoo'+5G%)*

9bjj&>"**U`Jabr   c                    U R                   R                  [        5      R                  [        R                  UR                  :H  5      R                  5       nU(       d  gUR                  SS9nUR                  5        H:  u  pEUS:X  a  U R                  U5      n[        X$5      (       d  M.  [        X$U5        M<     U R                   R                  5         g)NzNo data foundT)exclude_unsetr    r#   )r   r)   r   r*   
visual_rutone_or_nonedictitemsgenerate_bcrypt_hashhasattrsetattrcommit)r   user_inputsexisting_userexisting_user_datakeyvalues         r   update_password#AuthenticationClass.update_password5   s    i077	8L8LP[PfPf8fgssu"(--D-A,224JC''11%8}**E2	 5 	r   c                 ~    UR                  S5      n[        R                  " 5       n[        R                  " X#5      nU$ )Nzutf-8)rD   bcryptgensalthashpw)r   input_stringencoded_stringsalthashed_strings        r   rR   (AuthenticationClass.generate_bcrypt_hashF   s2    %,,W5~~n;r   r   r   )__name__
__module____qualname____firstlineno__r   r3   r(   rP   r   r   rJ   r[   rR   __static_attributes__ r   r   r   r      s8    ,C
 
E(D.4I 
"r   r   )app.backend.db.modelsr   r   fastapir   app.backend.auth.auth_userr   app.backend.classes.user_classr   r   r	   r
   typingr   rE   joser   r&   r^   r   rk   r   r   <module>rr      s2    : ! 2 4 . .  	   A Ar   