-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathviews.py
147 lines (103 loc) · 3.87 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from django.shortcuts import render
import pyrebase
from django.contrib import auth
import json
import requests as msgRequest
import time
from django import urls as urlresolvers
try:
from django.urls.exceptions import NoReverseMatch
except ImportError:
from django.core.urlresolvers import NoReverseMatch
config={
'apiKey': "AIzaSyCUchbdcHU75ahgwcyOnqqLupMauIbR32I",
'authDomain': "friendlychat-ssss.firebaseapp.com",
'databaseURL': "https://friendlychat-ssss.firebaseio.com",
'projectId': "friendlychat-ssss",
'storageBucket': "friendlychat-ssss.appspot.com",
'messagingSenderId': "338120484312",
'appId': "1:338120484312:web:a6432d15c2b2bdf0563ead",
'measurementId': "G-R0WLSHM6D0"
}
# // Initialize Firebase
firebase=pyrebase.initialize_app(config)
auths=firebase.auth()
database=firebase.database()
def intro(requests):
return render(requests, "homePage.html")
def signIn(requests):
return render(requests, "login.html")
def postsign(requests):
email=requests.POST.get('email')
passw=requests.POST.get('pass')
try:
user=auths.sign_in_with_email_and_password(email,passw)
session_id=user['idToken']
requests.session['uid']=str(session_id)
except:
message="invalid credentials"
return render(requests,"login.html",{"messg":message})
print(user['idToken'])
return render(requests,'mainPage.html',{"e":email})
def quiz(requests):
if requests.session['uid']==str(session_id):
return render(requests,'index.html')
return render(requests,"login.html")
def you(requests):
if requests.session['uid']==str(session_id):
return render(requests,'you.html')
return render(requests,"login.html")
def waterReminder(requests):
t=time.time()+ 30*60
print(t)
message="Time to drink Water"
while(True):
if(time.time==t):
return render(requests, 'mainPage.html', {'msg':message})
return render(requests,'mainPage.html')
def logout(requests):
auth.logout(requests)
del requests.session['uid']
msg="sucessfully logged out"
return render(requests,"homePage.html",{"messg":msg})
def signUp(requests):
return render(requests,"signup.html")
def postsignUp(requests):
email=requests.POST.get('email')
passw=requests.POST.get('pass')
name=requests.POST.get('Fname')
friend1no=requests.POST.get('friend1no')
friend2no=requests.POST.get('friend2no')
user=auths.create_user_with_email_and_password(email,passw)
uid=user['localId']
data= {"name":name, "status":"1", "friend1no":friend1no,"friend2no":friend2no}
database.child(uid).child("details").set(data)
msg="Account created sucessfully, please login now"
return render(requests,"login.html",{"messg":msg})
def sendsms(requests):
url='https://www.fast2sms.com/dev/bulk'
idtoken=requests.session['uid']
a=auths.get_account_info(idtoken)
a =a['users']
print(a)
a =a[0]
a =a['localId']
print(a)
name=database.child(a).child('details').child('name').get().val()
firstFriendNumber=database.child(a).child('details').child('friend1no').get().val()
print(firstFriendNumber)
print(name)
para={
'authorization':'XYmpiL3FWBhEcz50HxVuQDteI1RlUgojsSqCO2rGdwyMTvb9PkfaP6NUeFHvVAzjwTnXydOrkEKmo1Gt',
'sender_id':"FSTSMS",
'message':"your friend needs your help, plz contact him",
'language':'english',
"route":"p",
'numbers':firstFriendNumber
}
response=msgRequest.get(url, params=para)
print(response.json())
msg="message sent successfully"
return render(requests,"mainPage.html",{"messg":msg})
def DocsNear(requests):
return render(requests, 'mapsFinal.html')