U
    9d                     @   s   d dl Z d dlmZ d dlmZ d dlmZ ddlmZm	Z	 dd Z
d	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    N)settings)EmailMessage)render_to_string   )EmailHistoryPasswordHistoryc                 C   sF   d}t d| |j| dd}t||| jgtjd}d|_|  dS )z# Send activation email to the user z UseVoice. | Account Confirmationzaccounts/email_activation.htmlemail_verificationuserdomaintokento
from_emailhtmlN	r   r   r   r   emailr   EMAIL_HOST_USERcontent_subtypesend)Znew_usercurrent_sitesubjectmessagemail r   7/var/www/html/UseVoiceDocker/src/apps/accounts/utils.pysend_activation_email
   s    r   c                 C   sF   d}t d| |j| dd}t||| jgtjd}d|_|  dS )z' Send password reset email to the user zUseVoice. | Password Resetz"accounts/email_password_reset.htmlpassword_resetr	   r   r   Nr   )r
   r   r   r   r   r   r   r   send_password_reset_email   s    r   c                 C   s.   dddddg}|  dd  dd	 }||kS )
NZgmailZyahooZoutlookZhotmailZicloud@.r   )split)	new_emailZallowed_providersZemail_providerr   r   r   check_email_provider_allowed/   s    r$   c                    s2   dddddg}|  dd  t fdd	|D S )
Nz.eduz.govz.comz.maz.frr   r    c                 3   s   | ]}  |V  qd S )N)endswith).0dr   r   r   	<genexpr>7   s     z-check_email_domain_allowed.<locals>.<genexpr>)r"   any)r#   allowed_domainsr   r(   r   check_email_domain_allowed4   s    r,   c                 C   s   dS )NFr   )r
   r   r   r   email_change_limit_reached9   s    r-   c                 C   sB   d}d}t j  t j|d }tjj| |d}| |kr>dS dS )N      daysr
   Ztimestamp__gteTF)datetimenow	timedeltar   objectsfiltercountr
   limitZtime_periodZtime_thresholdZemail_changesr   r   r   r-   @   s    c                 C   sB   d}d}t j  t j|d }tjj| |d}| |kr>dS dS )Nr.      r0   r2   TF)r3   r4   r5   r   r6   r7   r8   r9   r   r   r   password_change_limit_reachedI   s    r<   c                 C   s   d}d S )NzConfirm your email changer   )r#   r   r   r   r   send_confirmation_emailR   s    r=   c                 C   s.   |}t ||d| d dg| d}|  d S )Nz
from r!   zbrahim.boughanem@usevoice.io)r   bodyr   r   )r   r   )r   Zsender_namer   r   r   r   r   r   contact_us_send_messageY   s    r?   )r3   django.confr   django.core.mail.messager   django.template.loaderr   modelsr   r   r   r   r$   r,   r-   r<   r=   r?   r   r   r   r   <module>   s   		