
    OEh                     D    d dl  d dlmZ  G d dej                        Zy)    )*)cmf_auth_two_factorc                        e Zd ZdZej
                  j                  ddgz   Zd Zd Z fdZ	d Z
d Z fd	Zd
 Z xZS )CmfAuthTwoFactorTtopt_qrcoderesetc                     dd l }dd l}dd l}dd l}d }| j                  j                         s(|j                         }|| _        | j                          n7t        j                         5  | j                  j                         }d d d        | j                  dg       d|j                  j                  | j                  d   j                  j                          d| d}|j#                  ddd	      }|j%                  |       |j'                  d
       |j)                  dd      }|j+                         5 }	|j                  |	d       |	j-                         cd d d        S # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   zpersons.loginzotpauth://totp/EvaTeam:z?secret=z&issuer=EvaTeam   
      )versionbox_sizeborderT)fitblackwhite)
fill_color
back_colorPNG)format)pyotpqrcodeiourllibtopt_secretloadrandom_base32savecmfutildisable_acldecryptload_fieldsparsequotepersonsloginvalueQRCodeadd_datamake
make_imageBytesIOgetvalue)
selfr   r   r   r   secreturlqrimgbuffers
             #./cmf/models/cmf_auth_two_factor.pytopt_qrcode_bytesz"CmfAuthTwoFactor.topt_qrcode_bytes
   sK   $$&((*F%DIIK$$& 4))1134/*+'(:(:4<<?;P;P;V;V(W'XX`ag`hhwx ]]1r!]<
C
D mmw7mC ZZ\ 	%VHHVEH*??$	% 	%4 4	% 	%s   )E(;#E4(E14E=c                 j    dd l }|j                  | j                               j                  d      }|S )Nr   zutf-8)base64	b64encoder5   decode)r.   r7   base64_images      r4   r   zCmfAuthTwoFactor.topt_qrcode'   s/    ''(>(>(@AHHQ    c                 *    t         |          g dz   S )N)phoneemailapplicationr   )supersave_preload_fields)r.   	__class__s    r4   rA   z$CmfAuthTwoFactor.save_preload_fields,   s    w*,/___r;   c                 Z   t         j                  r<t         j                  j                  s"| j                  r| j                  j                  sy t         j
                  | j                  j                         v r4dt         j                  _        t         j                  j                          y y )NT)	gsessioncheckedtwo_factor_opt
is_changedcurrent_personr%   r   r   r.   s    r4   _calc_sessionzCmfAuthTwoFactor._calc_session/   sh    yyAII--d6I6IdNaNaNlNlt||0022 $AIIIINN 3r;   c                 *    | j                  g d       y )N)phone_verifiedemail_verifiedapplication_verifiedr   rG   )r"   rJ   s    r4   _load_2fa_fieldsz!CmfAuthTwoFactor._load_2fa_fields6   s    vwr;   c                 z   | j                          | j                          | j                  j                  rd| _        | j
                  j                  rd| _        | j                  j                  s| j                  j                  rd| _	        | j                  r| j                  sd| _        t        | ,  |i |S )NFtopt)rP   rK   r=   rH   rM   r>   rN   r?   r   rO   r@   r   )r.   argskwargsrB   s      r4   r   zCmfAuthTwoFactor.save9   s    ::  "'D::  "'D&&$*:*:*E*E(-D%$$T-=-=%Dw|T,V,,r;   c                     | j                          d| _        d| _        d| _        d | _        d | _        | j                          y )NF)rP   rM   rN   rO   r   rG   r   rJ   s    r4   r   zCmfAuthTwoFactor.resetG   s?    ##$)!"		r;   )__name__
__module____qualname__	api_allowr   r   api_methodsr5   r   rA   rK   rP   r   r   __classcell__)rB   s   @r4   r   r      sN    I%66BB7F
 
K%:
`x-r;   r   N)cmf.include
cmf.fieldsr   r    r;   r4   <module>r_      s      *J*;; Jr;   