
     qhu                         d dl Z d dlmZmZmZmZmZmZmZ ddl	m
Z
 ddlmZmZ d dlmZmZ d dlmZ ddlmZ  ed	e      Ze j.                  j1                   e j2                         d
      Z e j6                  ed       ej9                  dddg      d        Zej9                  d      d        Zej9                  dddg      d        Zej9                  dddg      d        Z ej9                  d      d        Z!ej9                  d      d        Z"ej9                  dddg      d        Z#ej9                  d      d        Z$ej9                  d       d!        Z%ejM                  e'      d"        Z(y)#    N)	Blueprintrender_templaterequestredirecturl_forflash	send_file   )db)Client	Provision)generate_password_hashcheck_password_hash)secure_filename)process_allocai_csvclientuploadsT)exist_okz/client/loginGETPOST)methodsc                     t         j                  dk(  rt         j                  j                  d      j	                         j                         } t        j                  j                  |       j                         }t        j                  j                  |       j                         }|rt        t        d|             }|S |rt        t        d|             }|S t        dd       t        d      S t        d      S )	Nr   emailr   zclient.password_loginzclient.setup_accountzEmail not found in systemdangerzclient_login1.html)r   methodformgetstriplowerr   query	filter_byfirstr   r   r   r   r   )r   r   	provisionresps       ./var/www/html/allocaisaas/app/routes_client.pyclient_loginr'      s    ~~  )//1779''e'4::<OO--E-:@@B	G$;5IJDKG$:%HIDK
 -x8"#788/00    z/client/logoutc                      t        t        d            } | j                  ddd       | j                  ddd       | j                  ddd       | j                  ddd       t        d	d
       | S )Nclient.client_loginclient_email r   )expiresclient_firstnameclient_lastnameclient_featuresz&You have been logged out successfully.success)r   r   
set_cookier   )r%   s    r&   client_logoutr3   '   sm    G123DOONBO2OO&AO6OO%r1O5OO%r1O5	
2I>Kr(   z/client/setupc                  R   t         j                  j                  d      } t         j                  dk(  rht         j                  j                  d      }t         j                  j                  d      }||k7  rt        dd       t        d|       S t        |d	
      }t        j                  j                  |       j                         }|j                  }|j                  }d}|j                  }t        | ||||      }	t         j"                  j%                  |	       t         j"                  j'                          t)        t+        d            }
|
j-                  d|        |
j-                  d|       |
j-                  d|       |
j-                  d|       |
S t        d|       S )Nr   r   passwordconfirmPasswordzPasswords do not matchr   zclient_login_setup_page.htmlr   zpbkdf2:sha256)r   T)r   r5   
first_name	last_nameprovisionedclient.copilotwelcomer+   r.   r/   r0   )r   argsr   r   r   r   r   r   r   r!   r"   r#   r7   r8   featuresr   r   sessionaddcommitr   r   r2   )r   r5   confirm	hashed_pwr$   r7   r8   r9   r<   
new_clientr%   s              r&   setup_accountrC   2   sW   LLW%E~~<<##J/,,""#45w*H5"#AOO*8OL	OO--E-:@@B	))
''	%%%)
^g  vA  B



z"


 789.*J7)95)849GGr(   z/client/password-loginc                     t         j                  j                  d      } t         j                  dk(  rt         j                  j                  d      }t
        j                  j                  |       j                         }t        j                  j                  |       j                         }|rt        |j                  |      r|t        t        d            }|j                  d|        |j                  d|j                         |j                  d|j                          |j                  d	|j"                         |S t%        d
       t'        d|       S )Nr   r   ClientPasswordr   r:   r+   r.   r/   r0   zInvalid email or passwordzclient_login2.html)r   r;   r   r   r   r   r!   r"   r#   r   r   r5   r   r   r2   r7   r8   r<   r   r   )r   r5   r   r$   r%   s        r&   password_loginrF   Q   s   LLW%E~~<<##$45''e'4::<OO--E-:@@B	)&//8DG$;<=DOONE2OO.0A0ABOO-v/?/?@OO-y/A/ABK-./u==r(   z/client/copilotc                  z   t         j                  j                  d      } t         j                  j                  d      }t         j                  j                  d      }t         j                  j                  d      }| st        t	        d            S |rd|v st        t	        d            S t        d| |||	      S )
Nr+   r.   r/   r0   r*   copilotr:   zclient_welcome_copilot.htmlr+   r.   r/   r0   r   cookiesr   r   r   r   rI   s       r&   rH   rH   d   s    ??&&~6L**+=>oo))*;<Ooo))*;<O 5677	_ <!89:	:%!)'' r(   z/client/copilot_standalonec                  z   t         j                  j                  d      } t         j                  j                  d      }t         j                  j                  d      }t         j                  j                  d      }| st        t	        d            S |rd|v st        t	        d            S t        d| |||	      S )
Nr+   r.   r/   r0   r*   rH   r:   zclient_welcome_copilot2.htmlrI   rJ   rI   s       r&   copilot_standalonerM   v   s    ??&&~6L**+=>oo))*;<Ooo))*;<O 5677	_ <!89:	:&!)'' r(   z/client/attributionc                     t         j                  j                  d      } t         j                  j                  d      }t         j                  j                  d      }t         j                  j                  d      }| st        t	        d            S |rd|v st        t	        d            S t         j
                  dk(  rt         j                  j                  d	      }|r|j                  d
k(  r t        dd       t        t	        d            S t        |j                        }t        j                  j                  t        |      }|j                  |       t         j                  j                  dd      }| d| }t        j                  j                  t        |      }	t!        ||	|       dt	        d|      iS t%        d| |||      S )Nr+   r.   r/   r0   r*   attributionr:   r   z
csv-uploadr,   zPlease upload a CSV filer   zclient.attributionmodelFT_AttributionOutput_)rP   download_urlz client.download_attribution_file)filenamezclient_welcome_attribution.htmlrI   )r   rK   r   r   r   r   filesrT   r   r   ospathjoinUPLOAD_FOLDERsaver   r   r	   r   )
r+   r.   r/   r0   filerT   
input_pathrP   output_filenameoutput_paths
             r&   rO   rO      sv   ??&&~6L**+=>oo))*;<Ooo))*;<O 5677 @!89:	:~~}}  .t}}*,h7G$89::"4==1WW\\-:
		*  $/"G#6xjAggll=/BJ%@(JUd eff )!)'' r(   z/client/copilotwelcomec                  F   t         j                  j                  d      } t         j                  j                  d      }t         j                  j                  d      }t         j                  j                  d      }| st        t	        d            S t        d| |||      S )Nr+   r.   r/   r0   r*   z!client_welcome_copilot_page1.htmlrI   rJ   rI   s       r&   copilotwelcomer`      s    ??&&~6L**+=>oo))*;<Ooo))*;<O 5677+!)'' r(   z'/client/attribution/download/<filename>c                 d    t         j                  j                  t        |       }t	        |d      S )NT)as_attachment)rV   rW   rX   rY   r	   )rT   r^   s     r&   download_attribution_filerc      s#    '',,}h7K[55r(   c                     t        d|         t        dt        |        d       t        t        j
                  xs t        d            S )Nu   ❌ Client route error: u   ❌ Something went wrong: r   r*   )printr   strr   r   referrerr   )es    r&   handle_client_errorsri      sF    	$QC
()	&s1vh
/: G$$F0E(FGGr(   ))rV   flaskr   r   r   r   r   r   r	   r,   r   modelsr   r   werkzeug.securityr   r   werkzeug.utilsr   allocair   __name__	client_bprW   rX   getcwdrY   makedirsrouter'   r3   rC   rF   rH   rM   rO   r`   rc   errorhandler	Exceptionri    r(   r&   <module>rw      s   	 Z Z Z  % I * (h)	YRYY[)4 MD )
5&/:1 ;12 !" # 5&/:H ;H< )E6?C> D>$ "# $" -. /  &@" A"F )* + :;6 <6 	"H #Hr(   