
    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	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mZmZmZ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( d dl)m&Z*m!Z+ d Z, G d de
      Z- G d de	      Z. G d de	      Z/ G d de	      Z0 G d de	      Z1 G d de	      Z2 G d de	      Z3 G d de
      Z4 G d d e      Z5y!)"    )ValidationError)Login)APIResponseAuthenticationResponse)APIViewAuthenticatedAPIViewAuthenticationStageAPIView)ErrorResponse)response)	ActivateTOTPInputAddWebAuthnInputAuthenticateInputAuthenticateWebAuthnInputDeleteWebAuthnInputGenerateRecoveryCodesInputLoginWebAuthnInputReauthenticateWebAuthnInputUpdateWebAuthnInput)DefaultMFAAdapterget_adapter)add)Authenticator)flows)AuthenticateStage)authr   c                     	 t        j                  | j                         y # t        $ r}t	        | d|      cY d }~S d }~ww xY w)Ni  )status	exception)r   validate_can_add_authenticatoruserr   r
   )requestes     U/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/headless/mfa/views.py_validate_can_add_authenticatorr$   #   s8    ?**7<<8 ?WSA>>?s   " 	A>AAc                        e Zd ZeZeZd Zd Zy)AuthenticateViewc                 V    | j                   j                          | j                         S Ninputsaverespond_next_stageselfr!   argskwargss       r#   postzAuthenticateView.post.       

&&((    c                 F    d| j                   j                  j                  iS Nr    stageloginr    r.   s    r#   get_input_kwargsz!AuthenticateView.get_input_kwargs2       

((--..r3   N)	__name__
__module____qualname__r   input_classr   stage_classr1   r:    r3   r#   r&   r&   *   s    #K#K)/r3   r&   c                       e Zd ZeZd Zd Zy)ReauthenticateViewc                 `    | j                   j                          t        | j                        S r(   )r*   r+   r   r!   r-   s       r#   r1   zReauthenticateView.post9   s    

%dll33r3   c                 2    d| j                   j                  iS r5   r!   r    r9   s    r#   r:   z#ReauthenticateView.get_input_kwargs=       ))**r3   N)r<   r=   r>   r   r?   r1   r:   rA   r3   r#   rC   rC   6   s    #K4+r3   rC   c                       e Zd Zd Zy)AuthenticatorsViewc                     t         j                  j                  |j                        }t	        j
                  ||      S )N)r    )r   objectsfilterr    r   AuthenticatorsResponser.   r!   r/   r0   authenticatorss        r#   getzAuthenticatorsView.getB   s2    &..557<<5H..wGGr3   N)r<   r=   r>   rP   rA   r3   r#   rI   rI   A   s    Hr3   rI   c                   8    e Zd ZdeiZdefdZd Zd Zd Z	d Z
y)	ManageTOTPViewPOSTreturnc                    | j                         }|sbt        |      }|r|S t               }t        j                  d      }|j                  |j                  |      }t        j                  |||      S t        j                  ||      S )NT)
regenerate)
_get_authenticatorr$   r   	totp_authget_totp_secretbuild_totp_urlr    r   TOTPNotFoundResponseTOTPResponse)	r.   r!   r/   r0   authenticatorerradaptersecrettotp_urls	            r#   rP   zManageTOTPView.getJ   sz    //11':C
)4G..$?F#227<<HH00&(KK$$Wm<<r3   c                     t         j                  j                  t         j                  j                  | j
                  j                        j                         S )N)typer    )r   rK   rL   TypeTOTPr!   r    firstr9   s    r#   rW   z!ManageTOTPView._get_authenticatorV   sB    $$++##((t||/@/@ , 

%'	r3   c                 2    d| j                   j                  iS r5   rF   r9   s    r#   r:   zManageTOTPView.get_input_kwargs[   rG   r3   c                 t    t        j                  || j                        d   }t        j                  ||      S )Nr   )
totp_flowsactivate_totpr*   r   r\   r.   r!   r/   r0   r]   s        r#   r1   zManageTOTPView.post^   s0    "00$**EaH$$Wm<<r3   c                 |    | j                         }|rt        j                  ||      }t        j                  |      S r(   )rW   ri   deactivate_totpr   AuthenticatorDeletedResponserk   s        r#   deletezManageTOTPView.deleteb   s6    //1&66wNM44W==r3   N)r<   r=   r>   r   r?   r   rP   rW   r:   r1   ro   rA   r3   r#   rR   rR   G   s-    ,-K
={ 
=
+=>r3   rR   c                   "    e Zd ZeZd Zd Zd Zy)ManageRecoveryCodesViewc                     t        j                  |      }|st        j                  |      S t        j                  ||      S r(   )recovery_codes_flowsview_recovery_codesr   RecoveryCodesNotFoundResponseRecoveryCodesResponserk   s        r#   rP   zManageRecoveryCodesView.getl   s9    ,@@I99'BB--g}EEr3   c                 X    t        j                  |      }t        j                  ||      S r(   )rs   generate_recovery_codesr   rv   rk   s        r#   r1   zManageRecoveryCodesView.postr   s%    ,DDWM--g}EEr3   c                 2    d| j                   j                  iS r5   rF   r9   s    r#   r:   z(ManageRecoveryCodesView.get_input_kwargsv   rG   r3   N)r<   r=   r>   r   r?   rP   r1   r:   rA   r3   r#   rq   rq   i   s    ,KFF+r3   rq   c                   H     e Zd ZeeedZ fdZd Zd Z	d Z
d Zd Z xZS )ManageWebAuthnView)rS   PUTDELETEc                 d    |j                   dv rt        |      }|r|S t        |   |g|i |S )N)GETrS   )methodr$   superhandle)r.   r!   r/   r0   r^   	__class__s        r#   r   zManageWebAuthnView.handle   s:    >>_,1':C
w~g7777r3   c                     d|j                   v }t        j                  ||j                  |      }t	        j
                  ||      S )Npasswordless)r   webauthn_flowsbegin_registrationr    r   AddWebAuthnResponse)r.   r!   r/   r0   r   creation_optionss         r#   rP   zManageWebAuthnView.get   sB    %4)<<W\\<
 ++G5EFFr3   c                 2    d| j                   j                  iS r5   rF   r9   s    r#   r:   z#ManageWebAuthnView.get_input_kwargs   rG   r3   c                     t        j                  || j                  j                  d   | j                  j                  d         \  }}t	        |      }t        j                  ||d|i      S )Nname
credential)r   r   recovery_codes_generated)meta)r   add_authenticatorr*   cleaned_databoolr   AuthenticatorResponse)r.   r!   r/   r0   r   rc_authdid_generate_recovery_codess          r#   r1   zManageWebAuthnView.post   sk    &88((0zz..|<
g
 '+7m#--,.IJ
 	
r3   c                     | j                   j                  d   }t        j                  ||| j                   j                  d          t	        j
                  ||      S )Nidr   )r*   r   r   rename_authenticatorr   r   rk   s        r#   putzManageWebAuthnView.put   sO    

//5++]DJJ$;$;F$C	
 --g}EEr3   c                     | j                   j                  d   }t        j                  ||       t	        j
                  |      S )NrO   )r*   r   r   remove_authenticatorsr   AuthenticatorsDeletedResponserN   s        r#   ro   zManageWebAuthnView.delete   s8    001AB,,WnE55g>>r3   )r<   r=   r>   r   r   r   r?   r   rP   r:   r1   r   ro   __classcell__)r   s   @r#   r{   r{   z   s3     "%K8G+
F?r3   r{   c                   &    e Zd ZdeiZd Zd Zd Zy)ReauthenticateWebAuthnViewrS   c                 l    t        j                  |j                        }t        j                  ||      S r(   )webauthn_authbegin_authenticationr    r   WebAuthnRequestOptionsResponser.   r!   r/   r0   request_optionss        r#   rP   zReauthenticateWebAuthnView.get   s)    '<<W\\J66wPPr3   c                 2    d| j                   j                  iS r5   rF   r9   s    r#   r:   z+ReauthenticateWebAuthnView.get_input_kwargs   rG   r3   c                     | j                   j                  d   }t        j                  ||       t	        | j
                        S )Nr   )r*   r   r   reauthenticater   r!   rk   s        r#   r1   zReauthenticateWebAuthnView.post   s5    

//=%%g}=%dll33r3   N)r<   r=   r>   r   r?   rP   r:   r1   rA   r3   r#   r   r      s    +KQ+4r3   r   c                   *    e Zd ZdeiZeZd Zd Zd Z	y)AuthenticateWebAuthnViewrS   c                     t        j                  | j                  j                  j                        }t        j                  ||      S r(   )r   r   r7   r8   r    r   r   r   s        r#   rP   zAuthenticateWebAuthnView.get   s5    '<<TZZ=M=M=R=RS66wPPr3   c                 F    d| j                   j                  j                  iS r5   r6   r9   s    r#   r:   z)AuthenticateWebAuthnView.get_input_kwargs   r;   r3   c                 V    | j                   j                          | j                         S r(   r)   r-   s       r#   r1   zAuthenticateWebAuthnView.post   r2   r3   N)
r<   r=   r>   r   r?   r   r@   rP   r:   r1   rA   r3   r#   r   r      s&    )K $KQ/)r3   r   c                        e Zd ZdeiZd Zd Zy)LoginWebAuthnViewrS   c                 V    t        j                         }t        j                  ||      S r(   )r   r   r   r   r   s        r#   rP   zLoginWebAuthnView.get   s#    '<<>66wPPr3   c                     | j                   j                  d   }d }t        |j                  |      }t	        j
                  |||       t        |      S )Nr   )r    redirect_url)r*   r   r   r    r   perform_passwordless_loginr   )r.   r!   r/   r0   r]   r   r8   s          r#   r1   zLoginWebAuthnView.post   sJ    

//==--LI11'=%P%g..r3   N)r<   r=   r>   r   r?   rP   r1   rA   r3   r#   r   r      s    "KQ/r3   r   N)6django.core.exceptionsr   allauth.account.modelsr   allauth.headless.base.responser   r   allauth.headless.base.viewsr   r   r	   *allauth.headless.internal.restkit.responser
   allauth.headless.mfar   allauth.headless.mfa.inputsr   r   r   r   r   r   r   r   r   allauth.mfa.adapterr   r   allauth.mfa.internal.flowsr   allauth.mfa.modelsr   #allauth.mfa.recovery_codes.internalr   rs   allauth.mfa.stagesr   allauth.mfa.totp.internalr   rX   ri   allauth.mfa.webauthn.internalr   r   r$   r&   rC   rI   rR   rq   r{   r   r   r   rA   r3   r#   <module>r      s    2 ( N 
 E )
 
 
 ? * , M 0 L?	/1 	/+- +H- H>) >D+2 +"/?- /?d4!5 4$)9 )$/ /r3   