
    l'h	                     Z    d dl  d dlmZ  G d dej                  j
                  e      Zy)    )*)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y)	TwoFactorViewz/two-factorc                 Z   t               }t        j                  t        j                  k(  rt	        d      S t        j                  j                  g d       t        j                  j                  j                  st        j                  j                  j                  st        j                  j                  j                  st        j                  j                  }t        j                  j                  }|d k7  r%|dk(  xs |dk(  }|dk(  xs |dk(  }|dk(  xs |dk(  }nht        j                  j                  dg       t        j                  j                  j                  }|dk(  xs |dk(  }|dk(  xs |dk(  }|dk(  xs |dk(  }| j                  d      S | j                  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   sy   "$	q}},C= 	$$ &N 	O   ++::##..==##..CC''22J**99JT!'1U':'RjF>R$(2e(;(TzW?T%&0E&9&PZ5=P#  ,,.I-JK--88GG
'1U':'RjF>R$(2e(;(TzW?T%&0E&9&PZ5=P#;;9::{{,--    c                     t         j                  j                          t         j                  r | j	                  dt         j                        S | j                  dt         j                        S )Nfailok)r   sessiontfa_send_codealert_error_okauthr   s    r"   	send_codezTwoFactorView.send_code%   sC    			!77;;vqww//xxaff%%r$   c                    	 t         j                  j                  t        j                  d   t        j                  j                  d            r | j                  dt         j                        S | j                  dt         j                        S # t        $ r=}t                | j                  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    	,yy''V(<gll>N>Nx>XYxxaff--xx// 	, "88CFAFF++	,s$   A-B 0B 	C2CCCc                    t         j                  j                  g d       t         j                  j                  j                  sHt         j                  j                  j
                  s$t         j                  j                  j                  r| j                  dd      S t        j                  j                  d      r<t        j                  j                  d      t         j                  j                  _        t        j                  j                  d      r<t        j                  j                  d      t         j                  j                  _        t        j                  j                  d      r<t        j                  j                  d      t         j                  j                  _        t         j                  j                  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   sK   	$$ &N 	O &&559I9I9T9T9c9cghgwgw  hC  hC  hX  hX;;v'tuu<<G$070@0@0IA''-<<G$070@0@0IA''-<<M*6=ll6F6F}6UA''3	##((*xxaff%%r$   c                 2   t         j                  j                  j                  r| j	                  dd      S t         j                  j                  j                         }t        |      }|j                  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));;= %^[9*.'r$   c                     t         j                  j                  j                  r| j	                  dd      S t         j                  j                  j                         S )Nr&   rA   )r   r   r   r   r+   topt_qrcoder.   s    r"   
qrcode_2fazTwoFactorView.qrcode_2faQ   sD    &&;;;;v'YZZ**6688r$   N)__name__
__module____qualname____url__cmfviewsactionr#   r/   r:   r?   rJ   rM    r$   r"   r   r      s    GYY. .8 	YY& & 	YY, , 	YY& & 	YY  	YY9 9r$   r   N)cmf.includemodules.auth.views.responser   rR   rS   BaseViewr   rU   r$   r"   <module>rY      s%     5P9CII&& P9r$   