
    h|              	           d dl m Z mZmZ d dlmZ d dlmZ d dlZdefdZ	dedede
fd	Zdd
edededefdZd
edefdZy)    )datetime	timedeltatimezone)Session)UserNreturnc                       y)zGenerate a random 6-digit OTP.123456 r       E/home/www/40-admission.kofcorporation.com/app/services/otp_service.pygenerate_otpr      s     r   user	user_codec                      | j                   |k(  S )zVerify the OTP code.)otp_code)r   r   s     r   
verify_otpr      s    ==I%%r   dbr   expiry_minutesc                     ||_         t        j                  t        j                        t        |      z   |_        | j                          | j                  |       y)zSet OTP expiry for a user.)minutesN)	r   r   nowr   utcr   
otp_expirycommitrefresh)r   r   r   r   s       r   set_otp_expiryr      s<    DMll8<<09^3TTDOIIKJJtr   c                 b    d|_         d|_        | j                          | j                  |       y)zClear OTP details for a user.N)r   r   r   r   )r   r   s     r   clear_otp_for_userr      s%    DMDOIIKJJtr   )
   )r   r   r   sqlalchemy.ormr   app.models.userr   secretsstrr   boolr   intr   r   r   r   r   <module>r'      sn    2 2 "   c 
&T &c &d &w d c 3 7 $ r   