
    pip                        S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  SSK	J
r
  \ R                  " S5      r\" \ R                  " SS	5      5      r\ R                  " S
5      r\ R                  " S5      r\ R                  " S5      r\ R                  " SS5      R%                  5       S:H  r\" \
5      rS\S\4S jrSS\S\S-  4S jjrS\S\S\4S jrg)    N)MIMEText)MIMEMultipart)URLSafeTimedSerializer   )
SECRET_KEYSMTP_SERVER	SMTP_PORTi  SMTP_USERNAMESMTP_PASSWORDSMTP_FROM_EMAILSMTP_USE_TLSTruetrueemailreturnc                 *    [         R                  U SS9$ )z,Generates a safe token containing the email.password-recovery-salt)salt)
serializerdumps)r   s    ;/home/mario/Escritorio/thel4footbal/app/auth/email_utils.pygenerate_password_reset_tokenr      s    E(@AA    tokenc                 R     [         R                  U SUS9nU$ ! [         a     gf = f)zBVerifies the token and returns the email if valid and not expired.r   )r   max_ageN)r   loads	Exception)r   
expirationr   s      r   verify_password_reset_tokenr       s6      -Ez Z s    
&&to_emailrequest_url_basec                    U SU 3nSnSU SU S3n[        5       n[        US'   XS'   XFS'   UR                  [        US	5      5         [        R
                  " 5       n[        R                  " [        [        US
9 nUR                  [        [        5        UR                  [        XR                  5       5        SSS5        [        SU  35        g! , (       d  f       N= f! [          a  n	[        SU	 35         Sn	A	gSn	A	ff = f)z/Sends a password reset email securely via SMTP.z/reset-password?token=u.   Recuperación de contraseña - Living4Footballu[  
    <html>
      <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
        <div style="max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #eee; border-radius: 10px;">
          <h2 style="color: #6366f1;">Restablecer Contraseña</h2>
          <p>Hola,</p>
          <p>Hemos recibido una solicitud para restablecer la contraseña de tu cuenta en <strong>Living4Football</strong>.</p>
          <p>Si has sido tú, pulsa el siguiente botón para crear una nueva contraseña:</p>
          <p style="text-align: center; margin: 30px 0;">
            <a href="u8  " style="background-color: #6366f1; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px; font-weight: bold;">Restablecer Contraseña</a>
          </p>
          <p>O copia y pega este enlace en tu navegador:</p>
          <p style="word-break: break-all; color: #666; font-size: 0.9em;">u"  </p>
          <hr style="border: none; border-top: 1px solid #eee; margin: 20px 0;">
          <p style="font-size: 0.8em; color: #888;">Si no has solicitado este cambio, puedes ignorar este correo. Tu contraseña seguirá siendo la misma.</p>
        </div>
      </body>
    </html>
    FromToSubjecthtml)contextNzEmail sent to TzFailed to send email: F)r   r   attachr   sslcreate_default_contextsmtplibSMTP_SSLr   r	   loginr
   r   sendmail	as_stringprintr   )
r!   r   r"   
reset_linksubjecthtml_contentmsgr(   serveres
             r   send_password_reset_emailr8       s   $%%;E7CJ>G	 !\ "L MW< XL( /C!CKI	NJJxf-.	,,.k9gF&LL6OOOX}}G G 	xj)*	 GF
  &qc*+s0   
3C$ =?C<C$ 
C!C$ $
D.DD)i  )osr,   r*   email.mime.textr   email.mime.multipartr   itsdangerousr   databaser   getenvr   intr	   r
   r   r   lowerr   r   strr   r    r8    r   r   <module>rC      s    	  
 $ . / ! ii&		+s+,			/*		/*))-.yy0668FB $J/
B B Bs d
 ) )C )3 )r   