
    ƥh	                     L    d dl T d dlmZ  G d dej        j        e          ZdS )    )*)ResponseMixinc                      e Zd ZdZej        j        d             Zej        j        d             Zej        j        d             Z	ej        j        d             Z
ej        j        d             Zej        j        d             ZdS )	TwoFactorViewz/two-factorc                    t                      }t          j        t          j        k    rt	          d          S t          j                            g d           t          j        j        j        st          j        j        j        st          j        j        j	        st          j        j        }t          j
        j        }|d k    r%|dk    p|dk    }|dk    p|dk    }|dk    p|dk    }nZt          j                            dg           t          j        j        j        }|dk    p|dk    }|dk    p|dk    }|dk    p|dk    }|                     d          S |                     d	          S )
N/ztwo_factor.phone_verifiedztwo_factor.email_verifiedztwo_factor.application_verifiedztwo_factor.applicationztwo_factor.phoneztwo_factor.emailanytotpemailsmsztwo_factor.two_factor_optztwo_factor_settings.htmlztwo_factor.html)auth_base_hrefgcurrent_personsystem_userredirectload_fields
two_factorphone_verifiedemail_verifiedapplication_verifiedglobal_settingstwo_factor_optrender)self	base_hrefr   
global_tfais_totp_auth_allowedis_email_auth_allowedis_sms_auth_allowed
person_tfas           "./modules/auth/views/two_factor.pygetzTwoFactorView.get   s   "$$	q},,C== 	$$ &N &N &N 	O 	O 	O  +: 	;#.=	;#.C	; '2J*9JT!!'1U':'RjF>R$(2e(;(TzW?T%&0E&9&PZ5=P## ,,.I-JKKK-8G
'1U':'RjF>R$(2e(;(TzW?T%&0E&9&PZ5=P#;;9:::{{,---    c                     t           j                                         t           j        r |                     dt           j                  S |                     dt           j                  S )Nfailok)r   sessiontfa_send_codealert_error_okauthr   s    r"   	send_codezTwoFactorView.send_code%   sL    		!!!7 	0;;vqw///xxaf%%%r$   c                    	 t           j                            t          j        d         t          j                            d                    r |                     dt           j                  S |                     dt           j                  S # t          $ rE}t                       |                     t          |          t           j                  cY d }~S d }~ww xY w)Ncodemethodr'   r&   )r   r(   tfa_check_coderequestjsonr#   r,   r-   	Exceptionrollback_purge_eventstr)r   es     r"   
check_codezTwoFactorView.check_code,   s    	,y''V(<gl>N>Nx>X>XYY 0xxaf---xx/// 	, 	, 	, """88CFFAF++++++++	,s$   A,B /B 
C:CCCc                 f   t           j                            g d           t           j        j        j        s,t           j        j        j        st           j        j        j        r|                     dd          S t          j	        
                    d          r3t          j	        
                    d          t           j        j        _        t          j	        
                    d          r3t          j	        
                    d          t           j        j        _        t          j	        
                    d          r3t          j	        
                    d          t           j        j        _        t           j        j                                         |                     dt           j                  S )Nr	   r&   uK   Двухфакторная авторизация уже настроенаphoner   applicationr'   )r   r   r   r   r   r   r   r+   r4   r5   r#   r<   r   r=   saver,   r-   r.   s    r"   
update_2fazTwoFactorView.update_2fa7   sY   	$$ &N &N &N 	O 	O 	O &5 	v9I9T9c 	vghgw  hC  hX 	v;;v'tuuu<G$$ 	J070@0@0I0IA'-<G$$ 	J070@0@0I0IA'-<M** 	V6=l6F6F}6U6UA'3	#((***xxaf%%%r$   c                    t           j        j        j        r|                     dd          S t           j        j                                        }t          |          }|j                            dd           d|j	        _
        |S )Nr&   0   Приложение уже подключеноzContent-Typez	image/pngT)r   r   r   r   r+   topt_qrcode_bytesmake_responseheaderssetcache_controlno_cache)r   pngresponses      r"   qrcode_2fa_pngzTwoFactorView.qrcode_2fa_pngG   sv    &; 	[;;v'YZZZ);;== %%^[999*.'r$   c                     t           j        j        j        r|                     dd          S t           j        j                                        S )Nr&   rA   )r   r   r   r   r+   topt_qrcoder.   s    r"   
qrcode_2fazTwoFactorView.qrcode_2faQ   sA    &; 	[;;v'YZZZ*66888r$   N)__name__
__module____qualname____url__cmfviewsactionr#   r/   r:   r?   rJ   rM    r$   r"   r   r      s        GY. . .8 	Y& & & 	Y, , , 	Y& & & 	Y   	Y9 9 9 9 9r$   r   N)cmf.includemodules.auth.views.responser   rR   rS   BaseViewr   rU   r$   r"   <module>rY      sh        5 5 5 5 5 5P9 P9 P9 P9 P9CI& P9 P9 P9 P9 P9r$   