o
    &zh                     @   s  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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+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1 ee$ddeeddG dd deZ2e23 Z4eeddG dd deZ5e53 Z6eeddG dd deeZ7e73 Z8G dd deeZ9e93 Z:eeddG dd de"Z;e;3 Z<eeddG d d! d!eeZ=e=3 Z>eee1j?d"d#ddG d$d% d%eZ@e@3 ZAd&S )'    )messages)login_required)HttpResponseRedirectJsonResponse)reversereverse_lazy)method_decorator)
DeleteViewFormView
UpdateView)ListView)app_settings)get_adapter)reauthentication_required)login_stage_required)NextRedirectMixinRedirectAuthenticatedUserMixin)Login)BaseReauthenticateView)redirect_if_add_not_allowed)Authenticator)AddWebAuthnFormEditWebAuthnFormLoginWebAuthnFormReauthenticateWebAuthnFormSignupWebAuthnForm)authflows)PasskeySignupStagedispatch)namec                       sJ   e Zd ZeZdej Z fddZ fddZ	dd Z
 fdd	Z  ZS )
AddWebAuthnViewzmfa/webauthn/add_form.c                    s*   t   }t| jjd}d|i|d< |S )NFcreation_optionsjs_data)superget_context_datar   begin_registrationrequestuserselfkwargsretr"   	__class__ U/var/www/html/kangema/venv/lib/python3.10/site-packages/allauth/mfa/webauthn/views.pyr%   #   s   
z AddWebAuthnView.get_context_datac                       t   }| jj|d< |S Nr(   r$   get_form_kwargsr'   r(   r*   r,   r-   r/   r0   r4   )      
zAddWebAuthnView.get_form_kwargsc                 C   s   | j rtdS tdS )Nmfa_view_recovery_codes	mfa_index)did_generate_recovery_codesr   r*   r/   r/   r0   get_success_url.   s   zAddWebAuthnView.get_success_urlc                    s8   t j| j|jd |jd d\}}t|| _t |S )Nr    
credential)r    r<   )r   add_authenticatorr'   cleaned_databoolr9   r$   
form_valid)r*   formr   rc_authr-   r/   r0   r@   3   s   

zAddWebAuthnView.form_valid)__name__
__module____qualname__r   
form_classaccount_settingsTEMPLATE_EXTENSIONtemplate_namer%   r4   r;   r@   __classcell__r/   r/   r-   r0   r!      s    
r!   c                   @   s"   e Zd Zdej ZdZdd ZdS )ListWebAuthnViewz mfa/webauthn/authenticator_list.authenticatorsc                 C      t jj| jjt jjdS N)r(   typer   objectsfilterr'   r(   TypeWEBAUTHNr:   r/   r/   r0   get_querysetG      zListWebAuthnView.get_querysetN)rC   rD   rE   rG   rH   rI   context_object_namerU   r/   r/   r/   r0   rK   @   s
    rK   c                   @   s8   e Zd ZU eed< dej ZedZ	dd Z
dd ZdS )	RemoveWebAuthnViewobjectz*mfa/webauthn/authenticator_confirm_delete.mfa_list_webauthnc                 C   rM   rN   rP   r:   r/   r/   r0   rU   Y   rV   zRemoveWebAuthnView.get_querysetc                 C   s"   |   }t| j| t|  S )N)
get_objectr   remove_authenticatorr'   r   r;   r*   rA   authenticatorr/   r/   r0   r@   ^   s   zRemoveWebAuthnView.form_validN)rC   rD   rE   r   __annotations__rG   rH   rI   r   success_urlrU   r@   r/   r/   r/   r0   rX   P   s   
 rX   c                   @   s(   e Zd ZeZdd Zdd Zdd ZdS )LoginWebAuthnViewc                 O   s4   t  |rtjd 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+   rb   datar/   r/   r0   getj   s
   zLoginWebAuthnView.getc                 C   6   |j dg D ]}t j| jtj|d qttdS Nr<   )messagerc   	errorsri   rd   add_messager'   r   ERRORr   r   r*   rA   rl   r/   r/   r0   form_invalidq   
   
zLoginWebAuthnView.form_invalidc                 C   s,   |j d }d }t|j|d}t| j||S )Nr<   )r(   redirect_url)r>   r   r(   r   perform_passwordless_loginr'   )r*   rA   r^   rt   loginr/   r/   r0   r@   x   s   
zLoginWebAuthnView.form_validN)rC   rD   rE   r   rF   ri   rr   r@   r/   r/   r/   r0   ra   g   s
    ra   c                       sJ   e Zd ZeZdej Z fddZdd Z	 fddZ
 fdd	Z  ZS )
ReauthenticateWebAuthnViewzmfa/webauthn/reauthenticate.c                    r1   r2   r3   r5   r-   r/   r0   r4      r6   z*ReauthenticateWebAuthnView.get_form_kwargsc                 C   rj   rk   rm   rq   r/   r/   r0   rr      rs   z'ReauthenticateWebAuthnView.form_invalidc                    s$   |j d }t| j| t |S )Nr<   )r>   r   reauthenticater'   r$   r@   r]   r-   r/   r0   r@      s   
z%ReauthenticateWebAuthnView.form_validc                    s(   t   }t| jj}d|i|d< |S )Nrb   r#   )r$   r%   r   rf   r'   r(   )r*   r+   r,   rb   r-   r/   r0   r%      s   
z+ReauthenticateWebAuthnView.get_context_data)rC   rD   rE   r   rF   rG   rH   rI   r4   rr   r@   r%   rJ   r/   r/   r-   r0   rw      s    
rw   c                   @   s*   e Zd ZeZdej ZedZ	dd Z
dS )EditWebAuthnViewzmfa/webauthn/edit_form.rZ   c                 C   rM   rN   rP   r:   r/   r/   r0   rU      rV   zEditWebAuthnView.get_querysetN)rC   rD   rE   r   rF   rG   rH   rI   r   r`   rU   r/   r/   r/   r0   ry      s
    
ry   account_signup)stageredirect_urlnamec                       s>   e Zd ZeZdej Z fddZ fddZ	dd Z
  ZS )SignupWebAuthnViewzmfa/webauthn/signup_form.c                    s.   t   }t| jjjjd}d|i|d< |S )NTr"   r#   )r$   r%   r   r&   r'   _login_stagerv   r(   r)   r-   r/   r0   r%      s   
z#SignupWebAuthnView.get_context_datac                    s   t   }| jjjj|d< |S r2   )r$   r4   r'   r~   rv   r(   r5   r-   r/   r0   r4      s   
z"SignupWebAuthnView.get_form_kwargsc                 C   s4   t j| j| jjjj|jd |jd d | jj S )Nr    r<   )r(   r    r<   )r   signup_authenticatorr'   r~   rv   r(   r>   exit)r*   rA   r/   r/   r0   r@      s   
zSignupWebAuthnView.form_valid)rC   rD   rE   r   rF   rG   rH   rI   r%   r4   r@   rJ   r/   r/   r-   r0   r}      s    
r}   N)B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   rG   allauth.account.adapterr   rd   allauth.account.decoratorsr   #allauth.account.internal.decoratorsr   allauth.account.mixinsr   r   allauth.account.modelsr   allauth.account.viewsr   allauth.mfa.internal.flows.addr   allauth.mfa.modelsr   allauth.mfa.webauthn.formsr   r   r   r   r   allauth.mfa.webauthn.internalr   r   allauth.mfa.webauthn.stagesr   r!   as_viewadd_webauthnrK   list_webauthnrX   remove_webauthnra   login_webauthnrw   reauthenticate_webauthnry   edit_webauthnkeyr}   signup_webauthnr/   r/   r/   r0   <module>   sZ    





