
    g                        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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 eejD                  d      d       G d de	             Z#e#jI                         Z% eed       G d de             Z&e&jI                         Z' eed       G d de	             Z(e(jI                         Z)y)    )login_required)HttpResponseRedirect)reverse)method_decorator)TemplateView)app_settings)login_stage_required)BaseReauthenticateView)AuthenticateFormReauthenticateForm)Authenticator)AuthenticateStage)is_mfa_enabled)AuthenticateWebAuthnForm)auth)get_form_classaccount_login)stageredirect_urlnamedispatch)namec                   v     e Zd ZeZeZdej                  z   Z	 fdZ
d Zd Zd Zd Zd Z fdZ fd	Z xZS )
AuthenticateViewzmfa/authenticate.c                 V   |j                   | _        t        | j                  j                  j                  t
        j                  j                  t
        j                  j                  g      st        t        d            S | j                         | _        t        | 8  |g|i |S )Nr   )_login_stager   r   loginuserr   TypeTOTPWEBAUTHNr   r   _build_formsformsuperr   )selfrequestargskwargs	__class__s       S/var/www/django_project/virt/lib/python3.12/site-packages/allauth/mfa/base/views.pyr   zAuthenticateView.dispatch   s    ))
JJ!!$$m&8&8&A&AB
 ((@AA%%'	w9$9&99    c                     | j                   j                         r| j                  | j                         S | j                  | j                         S N)r"   is_valid
form_validform_invalid)r$   r%   r&   r'   s       r)   postzAuthenticateView.post'   s:    99??499--$$TYY//r*   c                 4   d }| j                         }| j                         }| j                  j                  j                  }dt
        j                  v }| j                  j                  dk(  rd| j                  j                  v r9 ||| j                  j                        x}| _
        |r	 ||      nd | _        |S |r	 ||      nd | _
         ||| j                  j                        x}| _        |S  ||      | _
        |r	 ||      nd | _        |S )NwebauthnPOSTcode)r   datar   )r   get_webauthn_form_classr   r   r   r   SUPPORTED_TYPESr%   methodr3   	auth_formwebauthn_form)r$   posted_formAuthenticateFormClassAuthenticateWebAuthnFormClassr   support_webauthns         r)   r!   zAuthenticateView._build_forms-   s$    $ 3 3 5(,(D(D(F%zz$$%)E)EE<<&(***/DDLL$5$50 dn
 ( 2t< ""  9I)t4d  4QDLL$5$54 d0 	 3=DN<L-48RV  r*   c                 L    t        t        j                  d| j                        S )Nauthenticater   r   FORMS
form_classr$   s    r)   r   zAuthenticateView.get_form_classK   s    l00.$//RRr*   c                 L    t        t        j                  d| j                        S )Nauthenticate_webauthn)r   r   rC   webauthn_form_classrE   s    r)   r7   z(AuthenticateView.get_webauthn_form_classN   s#     79Q9Q
 	
r*   c                 V    |j                          | j                  j                         S r,   )saver   exit)r$   r"   s     r)   r.   zAuthenticateView.form_validS   s    		zz  r*   c                 6    t         |   | j                        S r,   )r#   getr%   r$   r"   r(   s     r)   r/   zAuthenticateView.form_invalidW   s    w{4<<((r*   c                 :   t         |          }|j                  | j                  t        j
                  d       | j                  rSt        j                  | j                  j                  j                        }|j                  | j                  d|id       |S )N)r"   MFA_SUPPORTED_TYPESrequest_options)r;   js_data)r#   get_context_dataupdater:   r   r8   r;   webauthn_authbegin_authenticationr   r   r   )r$   r'   retrQ   r(   s       r)   rS   z!AuthenticateView.get_context_dataZ   s    g&(

'3'C'C	
 +@@AQAQAVAVWOJJ%)%7%7 1?C 
r*   )__name__
__module____qualname__r   rD   r   rH   account_settingsTEMPLATE_EXTENSIONtemplate_namer   r0   r!   r   r7   r.   r/   rS   __classcell__r(   s   @r)   r   r      sO    
 "J2'*:*M*MMM:0<S

!) r*   r   c                   P     e Zd ZeZdej                  z   Z fdZd Z	 fdZ
 xZS )ReauthenticateViewzmfa/reauthenticate.c                 V    t         |          }| j                  j                  |d<   |S )Nr   )r#   get_form_kwargsr%   r   )r$   rW   r(   s     r)   rc   z"ReauthenticateView.get_form_kwargsu   s(    g%'ll''F
r*   c                 L    t        t        j                  d| j                        S )NreauthenticaterB   rE   s    r)   r   z!ReauthenticateView.get_form_classz   s    l002BDOOTTr*   c                 B    |j                          t        | 	  |      S r,   )rJ   r#   r.   rN   s     r)   r.   zReauthenticateView.form_valid}   s    		w!$''r*   )rX   rY   rZ   r   rD   r[   r\   r]   rc   r   r.   r^   r_   s   @r)   ra   ra   p   s.    #J),<,O,OOM
U( (r*   ra   c                   <     e Zd Zdej                  z   Z fdZ xZS )	IndexViewz
mfa/index.c                    t        |   di |}i }t        j                  j	                  | j
                  j                        D ]  }|j                  t        j                  j                  k(  r<|j                  |j                  g       }|j                  |j                                f|j                         ||j                  <    ||d<   t        j                  |d<   t        | j
                  j                        |d<   |S )Nr6   authenticatorsrP   r    )r#   rS   r   objectsfilterr%   r   typer   r    
setdefaultappendwrapr   r8   r   )r$   r'   rW   rj   r   authsr(   s         r)   rS   zIndexView.get_context_data   s    g&00!))00dll6G6G0H 	8DyyM..777&11$))R@TYY[),0IIKtyy)	8 !/%1%A%A!" .t||/@/@ A
r*   )rX   rY   rZ   r[   r\   r]   rS   r^   r_   s   @r)   rh   rh      s     #3#F#FFM r*   rh   N)*django.contrib.auth.decoratorsr   django.httpr   django.urlsr   django.utils.decoratorsr   django.views.genericr   allauth.accountr   r[   #allauth.account.internal.decoratorsr	   allauth.account.viewsr
   allauth.mfaallauth.mfa.base.formsr   r   allauth.mfa.modelsr   allauth.mfa.stagesr   allauth.mfa.utilsr   allauth.mfa.webauthn.formsr   #allauth.mfa.webauthn.internal.flowsr   rU   allauth.utilsr   keyr   as_viewrA   ra   re   rh   indexrk   r*   r)   <module>r      s    9 ,  4 - < D 8 $ G , 0 , ? E ( 044W	R| R	Rj  '') .z2(/ ( 3(" $++- .z2  3$ 	r*   