U
    Ng
                     @   s*   d dl T d dlmZ G dd dejZdS )    )*)cmf_auth_two_factorc                       sT   e Zd ZdZejjddg Zdd Z fddZdd	 Z	 fd
dZ
dd Z  ZS )CmfAuthTwoFactorTtopt_qrcoderesetc              	   C   s   dd l }dd l}dd l}dd l}dd l}d }| j sN| }|| _|   nt	
  | j }W 5 Q R X | dg d|j| jd jj d| d}|jdddd	}|| |jd
d |jddd}	| }
|	j|
dd ||
 d}|S )Nr   zpersons.loginzotpauth://totp/EvaTeam:z?secret=z&issuer=EvaTeam   
      )versionZbox_sizeZborderT)ZfitZblackZwhite)Z
fill_colorZ
back_colorZPNG)formatzutf-8)pyotpqrcodebase64iourllibtopt_secretloadZrandom_base32saveZcmfutilZdisable_aclZdecryptload_fieldsparsequotepersonsZloginvalueZQRCodeZadd_dataZmakeZ
make_imageBytesIOZ	b64encodegetvaluedecode)selfr   r   r   r   r   ZsecreturlZqrZimgbufferZbase64_image r   #./cmf/models/cmf_auth_two_factor.pyr   
   s,    


$
zCmfAuthTwoFactor.topt_qrcodec                    s   t   ddddg S )Nphoneemailapplicationr   )supersave_preload_fieldsr   	__class__r   r    r%   )   s    z$CmfAuthTwoFactor.save_preload_fieldsc                 C   sF   t jrt jjs| jr| jjs d S t j| j krBdt j_t j  d S )NT)	gZsessioncheckedtwo_factor_opt
is_changedZcurrent_personr   r   r   r&   r   r   r    _calc_session,   s
    zCmfAuthTwoFactor._calc_sessionc                    sZ   |    | jjrd| _| jjr$d| _| jjs4| jjr:d| _| jrL| jsLd| _t	 j
||S )NFZtopt)r-   r!   r,   phone_verifiedr"   email_verifiedr#   r   application_verifiedr$   r   )r   argskwargsr'   r   r    r   4   s    zCmfAuthTwoFactor.savec                 C   s>   |  dddddg d| _d| _d| _d | _d | _|   d S )Nr.   r/   r0   r   r+   F)r   r.   r/   r0   r   r+   r   r&   r   r   r    r   A   s    zCmfAuthTwoFactor.reset)__name__
__module____qualname__Z	api_allowr   r   Zapi_methodsr   r%   r-   r   r   __classcell__r   r   r'   r    r      s    r   N)Zcmf.includeZ
cmf.fieldsr   r   r   r   r   r    <module>   s   