o
    i                     @   s   d dl mZmZ d dlmZ d dlZd dlZd dlmZmZ d dl	m
Z
 e
e jZe Zdd Zdd	 Zd
d Zdd ZdS )    )MailMessage)render_templateN)datetime	timedelta)Pathc                   C   s   t tddS )Ni'  i )strrandomrandint r   r   L/Users/harjaapdhillon/Desktop/newidea/medvista_backend/Services/SendEmail.pygenerate_otp   s   r   c                   C   s   t t S )N)r   uuiduuid4r   r   r   r   generate_token   s   r   c              
   C   sH   zt d| gd}td|d|_t| W d S  ty# } z d }~ww )NzReset Password)
recipientszotp_email_template.html)otp)r   r   htmlmailsend	Exception)Z
user_emailr   msger   r   r   send_otp_email   s   r   c              
   C   sP   zt  tdd }|d| |||f |  W d S  ty' } z d }~ww )N   )minutesz{
            INSERT INTO password_reset_tokens (email, otp, otp_expiry, token)
            VALUES (%s, %s, %s, %s)
        )r   nowr   executecommitr   )emailr   tokencursor
connectionZexpiry_timer   r   r   r   save_otp_to_db)   s   
r#   )
flask_mailr   r   flaskr   r	   r   r   r   pathlibr   __file__resolveparentBASE_DIRr   r   r   r   r#   r   r   r   r   <module>   s    