-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
83 lines (73 loc) · 2.48 KB
/
app.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
from __future__ import print_function
from datetime import datetime
from get_twilio_info import read,vig
from twilio.rest import Client
from flask import Flask, request, redirect
from twilio.twiml.voice_response import VoiceResponse, Gather, Say, Hangup
import logging
from logging.handlers import RotatingFileHandler
curr_p = ''
k_dic = {"":""}
app = Flask(__name__)
inf = read("hacksnw123")
t_client = Client(inf[0],inf[1])
def setPhone(phn):
global curr_p
curr_p = phn
def setDic(key,item):
global k_dic
k_dic[key] = item
@app.route('/encrypt/<pin>', methods=['GET'])
def encryptPin(pin):
return vig(str(pin),'hacksnw123','e')
@app.route('/getPin/<phone>', methods=['GET'])
def getPin(phone):
global k_dic
print(k_dic)
return str(k_dic[phone])
@app.route("/", methods=['GET', 'POST'])
@app.route("/app", methods=['GET', 'POST'])
@app.route("/app/voice", methods=['GET', 'POST'])
def voice(_num_digits=6,_timeout=10):
"""Respond to incoming phone calls with a menu of options"""
# Start our TwiML response
resp = VoiceResponse()
app.logger.error("")
# Start our <Gather> verb
# num_digits is how many digits in authentication
gather = Gather(num_digits=_num_digits,timeout=_timeout,action='/app/gather')
gather.say('Please enter your 6 digit passcode.')
resp.append(gather)
return str(resp)
@app.route('/app/gather', methods=['GET', 'POST'])
def gather():
"""Processes results from the <Gather> prompt in /voice"""
# Start our TwiML response
resp = VoiceResponse()
# If Twilio's request to our app included already gathered digits,
# process phone,them
if 'Digits' in request.values:
dig = request.values['Digits']
resp.say("Your code is "+str(dig))
#print(str(dig))
global curr_p
global k_dic
print(curr_p,k_dic)
#k_dic[curr_p] = str(vig(str(dig),'hacksnw123','e'))
setDic(curr_p,str(vig(str(dig),'hacksnw123','e')))
#print('curr_p',curr_p)
#print('dig',str(vig(str(dig),'hacksnw123','e')))
print('dic',k_dic)
return str(resp)
else:
resp.say("Please try again")
resp.redirect('/app/voice')
return str(resp)
@app.route('/app/verify/<phone>', methods=['GET'])
def verify(phone):
resp = VoiceResponse()
setPhone(phone)
call = t_client.api.account.calls.create(to=curr_p, from_="+16046708545",url="https://polar-bastion-19391.herokuapp.com/")
return redirect('/')
def inp():
app.run(debug=True)