o
    Ke                     @   s   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
mZ d dlZd dlZd dlZd dlZdadd Zee d	d
 Zdd ZdS )    )HttpResponse)settings)ensure_csrf_cookie)login_required)credentialsdbauthNc                  C   s   zNt jstdtjtjt} t jr.t	dt
jd tt j}t|dddid}nt	dt
jd tt j}t|d	ddid}|rK|W S td
    )Nz|(Notice only): The client asked the server to instantiate Firebase, but Firebase has been turned off in the Django settings.z USING DEVEL Firebase Credentials)filez#https://ideatreetest.firebaseio.comuidideatreeServer)databaseURLdatabaseAuthVariableOverridez%USING PRODUCTION Firebase Credentialszhttps://ideatree.firebaseio.comz(Notice only): The cloud component that does real-time updates to others sharing this map is not reachable.  Try reloading the page to re-establish a connection.)r   USE_FIREBASEWarningospathdirnamerealpath__file__USE_DEVEL_FIREBASE_SITEprintsysstderrr   Certificate,FIREBASE_DEVELOPMENT_SERVER_CREDENTIALS_PATHfirebase_admininitialize_app+FIREBASE_PRODUCTION_SERVER_CREDENTIALS_PATH)currentDir_pathcredfirebaseAdmin r!   +/var/www/ideatree/ideatree/itreeFirebase.pygetFirebaseInstance)   s    r#   c              
   C   s~   z"t jstdtd u rt at jrdnd}i }t||}t|W S  t	y> } ztdt
| ddW  Y d }~S d }~ww )Nzy(Notice only): The client asked the server for a Firebase token, but Firebase has been turned off in the Django settings.ideatreetestideatreeUserzSystem error:i  )status)r   r   r   
__firebaser#   r   r   create_custom_tokenr   	Exceptionstr)requestr
   additional_claimstokenerrr!   r!   r"   firebaseClientTokenK   s   
 r/   c                 C   sD   zt d u rt a t| }||}||}W d S  ty!    w )N)r'   r#   r   	referencechildpushr)   )rootAddr	childAddrdataref	posts_refnew_post_refr!   r!   r"   
push_valued   s   

r9   )django.httpr   django.confr   django.views.decorators.csrfr   django.contrib.auth.decoratorsr   r   r   r   r   r   r   pdbr'   r#   r/   r9   r!   r!   r!   r"   <module>   s   "