Ë
    >È'j‘  ã                  óv   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZ dd„Zd	d
œdd„Zdd„Zy	)z=Shared password-reset OTP flow for admin and member accounts.é    )Úannotations)Úfunc)ÚSession)Úrelease_db_connection)ÚUserÚUserRole)Úcreate_password_reset_flowÚsend_password_reset_emailc                ó>   — | j                  «       j                  «       S ©N)ÚstripÚlower)Úemails    úH/var/www/html/kelly/kelly-backend/app/services/password_reset_service.pyÚnormalize_emailr      s   € Ø�;‰;‹=×ÑÓ Ð ó    N)Úrolec               ó  — t        |«      }| j                  t        «      j                  t	        j
                  t        j                  «      |k(  «      }|�"|j                  t        j                  |k(  «      }|j                  «       S r   )	r   Úqueryr   Úfilterr   r   r   r   Úfirst)Údbr   r   Ú
normalizedÚqs        r   Úfind_user_by_emailr      s_   € Ü  Ó'€JØ
�‰”‹×ÑœdŸj™j¬¯©Ó4¸
ÑBÓC€AØÐØ�H‰H”T—Y‘Y $Ñ&Ó'ˆØ�7‰7‹9Ðr   c              ƒ  óš   K  — t        | |«      }|j                  }t        | «       t        ||«      ƒ d{  –—† }|st	        d«      ‚|S 7 Œ­w)z;Create OTP row and email it. Raises if SMTP delivery fails.NzGCould not send password reset email. Check SMTP settings on the server.)r	   r   r   r
   ÚRuntimeError)r   ÚuserÚotpÚ	recipientÚsents        r   Úsend_password_reset_otpr"      sQ   è ø€ ä
$ R¨Ó
.€CØ—
‘
€IÜ˜"ÔÜ*¨9°cÓ:×:€DÙÜØUó
ð 	
ð €Jð ;ús   ‚3AµA	¶A)r   ÚstrÚreturnr#   )r   r   r   r#   r   zUserRole | Noner$   zUser | None)r   r   r   r   r$   r#   )Ú__doc__Ú
__future__r   Ú
sqlalchemyr   Úsqlalchemy.ormr   Úapp.databaser   Ú
app.modelsr   r   Úapp.services.email_otpr	   r
   r   r   r"   © r   r   Ú<module>r-      s0   ðÙ Cå "å Ý "å .ß %ß Xó!ð LPõ ô
r   