U
    >i                     @   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d
dddZdddZd
S )    wraps)messages)AbstractBaseUser)ValidationError)HttpResponseRedirect)reverse)get_adapter)EmailAddress)app_settingsN)userreturnc                 C   s6   t jr
dS tjj| jdd  }|s2t ddS )z
    If we would allow users to enable 2FA with unverified email address,
    that would allow for an attacker to signup, not verify and prevent the real
    owner of the account from ever regaining access.
    NF)Zuser_idZverifiedZunverified_email)	r   ZALLOW_UNVERIFIED_EMAILr
   Zobjectsfilterpkexistsr	   Zvalidation_error)r   Zemail_verified r   B/tmp/pip-unpacked-wheel-upujnpc2/allauth/mfa/internal/flows/add.pyvalidate_can_add_authenticator   s     r   c                 C   s   dd }| r|| S |S )Nc                    s   t   fdd}|S )Nc              
      s~   | j jrnzt| j  W nV tk
rl } z8|jD ]}t }|j| tj|d q.tt	d W Y S d }~X Y nX  | f||S )N)messageZ	mfa_index)
r   is_authenticatedr   r   r   get_account_adapterZadd_messageERRORr   r   )requestargskwargser   adapter	view_funcr   r   _wrapper_view    s    
"zEredirect_if_add_not_allowed.<locals>.decorator.<locals>._wrapper_viewr   )r   r   r   r   r   	decorator   s    z.redirect_if_add_not_allowed.<locals>.decoratorr   )functionr    r   r   r   redirect_if_add_not_allowed   s    r"   )N)	functoolsr   Zdjango.contribr   Zdjango.contrib.auth.base_userr   Zdjango.core.exceptionsr   Zdjango.httpr   Zdjango.urlsr   Zallauth.account.adapterr	   r   Zallauth.account.modelsr
   Zallauth.mfar   Zallauth.mfa.adapterr   r"   r   r   r   r   <module>   s   