
    f                        d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZ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 d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+  ee!d       eed       G d de                    Z,e,j[                         Z. eed       G d de             Z/e/j[                         Z0 eed       G d dee             Z1e1j[                         Z2 G d de      Z3e3j[                         Z4 eed       G d de             Z5e5j[                         Z6 eed       G d dee             Z7e7j[                         Z8y )!    )messages)login_required)HttpResponseRedirectJsonResponse)reversereverse_lazy)method_decorator)
DeleteViewFormView
UpdateView)ListView)app_settings)get_adapter)reauthentication_required)NextRedirectMixin)Login)BaseReauthenticateView)redirect_if_add_not_allowed)Authenticator)AddWebAuthnFormEditWebAuthnFormLoginWebAuthnFormReauthenticateWebAuthnForm)authflowsdispatch)namec                   Z     e Zd ZeZdej                  z   Z fdZ fdZ	d Z
 fdZ xZS )AddWebAuthnViewzmfa/webauthn/add_form.c                     t         |          }t        j                  | j                  j
                  d      }d|i|d<   |S )NFcreation_optionsjs_data)superget_context_datar   begin_registrationrequestuser)selfkwargsretr!   	__class__s       U/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/mfa/webauthn/views.pyr$   z AddWebAuthnView.get_context_data    sA    g&(224<<3D3DeL,.>?I
    c                 V    t         |          }| j                  j                  |d<   |S Nr'   r#   get_form_kwargsr&   r'   r(   r*   r+   s     r,   r1   zAddWebAuthnView.get_form_kwargs&   (    g%'ll''F
r-   c                 F    | j                   rt        d      S t        d      S )Nmfa_view_recovery_codes	mfa_index)did_generate_recovery_codesr   r(   s    r,   get_success_urlzAddWebAuthnView.get_success_url+   s"    ++455{##r-   c                     t        j                  | j                  |j                  d   |j                  d         \  }}t	        |      | _        t        |   |      S )Nr   
credential)r   r;   )r   add_authenticatorr&   cleaned_databoolr7   r#   
form_valid)r(   formr   rc_authr+   s       r,   r?   zAddWebAuthnView.form_valid0   sX    //LL""6*((6
g
 ,0=(w!$''r-   )__name__
__module____qualname__r   
form_classaccount_settingsTEMPLATE_EXTENSIONtemplate_namer$   r1   r9   r?   __classcell__r+   s   @r,   r   r      s4     !J,/?/R/RRM
$
( (r-   r   c                   4    e Zd Zdej                  z   ZdZd Zy)ListWebAuthnViewz mfa/webauthn/authenticator_list.authenticatorsc                     t         j                  j                  | j                  j                  t         j
                  j                        S N)r'   typer   objectsfilterr&   r'   TypeWEBAUTHNr8   s    r,   get_querysetzListWebAuthnView.get_querysetD   ;    $$++""););)D)D , 
 	
r-   N)rB   rC   rD   rF   rG   rH   context_object_namerV    r-   r,   rL   rL   =   s%     	+-=-P-PP  +
r-   rL   c                   R    e Zd ZU eed<   dej                  z   Z ed      Z	d Z
d Zy)RemoveWebAuthnViewobjectz*mfa/webauthn/authenticator_confirm_delete.mfa_list_webauthnc                     t         j                  j                  | j                  j                  t         j
                  j                        S rO   rQ   r8   s    r,   rV   zRemoveWebAuthnView.get_querysetV   rW   r-   c                     | j                         }t        j                  | j                  |       t	        | j                               S )N)
get_objectr   remove_authenticatorr&   r   r9   )r(   r@   authenticators      r,   r?   zRemoveWebAuthnView.form_valid[   s6    )""4<<?#D$8$8$:;;r-   N)rB   rC   rD   r   __annotations__rF   rG   rH   r   success_urlrV   r?   rY   r-   r,   r[   r[   M   s5    4

-
-	.  23K

<r-   r[   c                   "    e Zd ZeZd Zd Zd Zy)LoginWebAuthnViewc                     t               j                  |      r%t        j                  d       }d|i}t	        |      S t        t        d            S )N)r'   request_optionsaccount_login)get_account_adapteris_ajaxr   begin_authenticationr   r   r   )r(   r&   argsr)   rh   datas         r,   getzLoginWebAuthnView.getg   sH     ((1"77TBO%7D%%#GO$<==r-   c                     |j                   j                  dg       D ]6  }t               j                  | j                  t
        j                  |       8 t        t        d            S Nr;   )messageri   	errorsro   rj   add_messager&   r   ERRORr   r   r(   r@   rr   s      r,   form_invalidzLoginWebAuthnView.form_invalidn   W    {{|R8 	G!--hnng . 	 $GO$<==r-   c                     |j                   d   }d }t        |j                  |      }t        j                  | j
                  ||      S )Nr;   )r'   redirect_url)r=   r   r'   r   perform_passwordless_loginr&   )r(   r@   rb   r{   logins        r,   r?   zLoginWebAuthnView.form_validu   sB    )),7=--LI//mUSSr-   N)rB   rC   rD   r   rE   ro   rx   r?   rY   r-   r,   rf   rf   d   s    "J>>Tr-   rf   c                   Z     e Zd ZeZdej                  z   Z fdZd Z	 fdZ
 fdZ xZS )ReauthenticateWebAuthnViewzmfa/webauthn/reauthenticate.c                 V    t         |          }| j                  j                  |d<   |S r/   r0   r2   s     r,   r1   z*ReauthenticateWebAuthnView.get_form_kwargs   r3   r-   c                     |j                   j                  dg       D ]6  }t               j                  | j                  t
        j                  |       8 t        t        d            S rq   rs   rw   s      r,   rx   z'ReauthenticateWebAuthnView.form_invalid   ry   r-   c                     |j                   d   }t        j                  | j                  |       t        |   |      S )Nr;   )r=   r   reauthenticater&   r#   r?   )r(   r@   rb   r+   s      r,   r?   z%ReauthenticateWebAuthnView.form_valid   s7    )),7T\\=9w!$''r-   c                     t         |          }t        j                  | j                  j
                        }d|i|d<   |S )Nrh   r"   )r#   r$   r   rl   r&   r'   )r(   r)   r*   rh   r+   s       r,   r$   z+ReauthenticateWebAuthnView.get_context_data   s=    g&(33DLL4E4EF+_=I
r-   )rB   rC   rD   r   rE   rF   rG   rH   r1   rx   r?   r$   rI   rJ   s   @r,   r   r      s2    +J25E5X5XXM
>(
 r-   r   c                   D    e Zd ZeZdej                  z   Z ed      Z	d Z
y)EditWebAuthnViewzmfa/webauthn/edit_form.r]   c                     t         j                  j                  | j                  j                  t         j
                  j                        S rO   rQ   r8   s    r,   rV   zEditWebAuthnView.get_queryset   rW   r-   N)rB   rC   rD   r   rE   rF   rG   rH   r   rd   rV   rY   r-   r,   r   r      s(    !J-0@0S0SSM23K
r-   r   N)9django.contribr   django.contrib.auth.decoratorsr   django.httpr   r   django.urlsr   r   django.utils.decoratorsr	   django.views.generic.editr
   r   r   django.views.generic.listr   allauth.accountr   rF   allauth.account.adapterr   rj   allauth.account.decoratorsr   allauth.account.mixinsr   allauth.account.modelsr   allauth.account.viewsr   allauth.mfa.internal.flows.addr   allauth.mfa.modelsr   allauth.mfa.webauthn.formsr   r   r   r   allauth.mfa.webauthn.internalr   r   r   as_viewadd_webauthnrL   list_webauthnr[   remove_webauthnrf   login_webauthnr   reauthenticate_webauthnr   edit_webauthnrY   r-   r,   <module>r      sx   # 9 : - 4 F F . < F @ 4 ( 8 F ,  6 -J?+*=(h ( > @(< &&( .z2	
x 	
 3	
 !((* +*=<*J < ><& %,,.T T0 #**, .z2!7  38 5<<>  +*=
(* 
 >
 !((*r-   