-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
96 lines (72 loc) · 2.99 KB
/
application.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
import os
from flask.ext.uuid import FlaskUUID
import config
import requests
from flask import Flask, render_template, redirect, request, url_for
from requests import ConnectionError
from wtforms import Form, BooleanField, TextField, PasswordField, validators
import logging
import json
from hello import ApiClient
from flask_sslify import SSLify
application = Flask(__name__)
FlaskUUID(application)
sslify = SSLify(application)
application.config.from_object(os.environ['APP_SETTINGS'])
logger = logging.getLogger(__name__)
apiClient = ApiClient(application.config['API_URL'], application.config['OAUTH_TOKEN'])
@application.after_request
def sanitizing(response):
response.headers["X-Frame-Options"] = "SAMEORIGIN"
return response
@application.route('/', methods=['GET'])
def home():
return redirect(url_for('register'))
@application.route('/reset', methods=['GET', 'POST'])
def register():
form = ResetForm(request.form)
error_message = ''
if request.method == 'POST' and form.validate():
resp = apiClient.send_email(form.email.data)
if resp:
return render_template('reset_success.html', user_email=form.email.data.lower())
error_message = 'Please try again, make sure email is correct'
return render_template('reset.html', form=form, error_message=error_message)
@application.route('/export/<uuid:ext_id>', methods=['GET'])
def export_view(ext_id):
return render_template('export.html', ext_id=ext_id)
@application.route('/export/<uuid:ext_id>', methods=['POST'])
def export_submit(ext_id):
resp = apiClient.export(ext_id)
if resp:
return render_template('thankyou.html')
return render_template('export.html', ext_id=ext_id, error=True)
@application.route('/success', methods=['GET'])
def success():
return render_template('update_success.html')
@application.route('/error', methods=['GET'])
def error():
return render_template('update_error.html'), 500
@application.route('/password_update/<uuid:id>/<state>', methods=['GET', 'POST'])
def updatePassword(id, state):
link_is_valid = apiClient.validate_link(id, state)
if not link_is_valid:
return render_template('expired.html')
form = UpdatePasswordForm(request.form)
if request.method == 'POST' and form.validate():
if apiClient.update(id, state, form.password.data):
return redirect(url_for('success'))
else:
return redirect(url_for('error'))
return render_template('update.html', id=id, state=state, form=form)
class ResetForm(Form):
email = TextField('Email address', [validators.Email(message="Email address is not valid.")])
class UpdatePasswordForm(Form):
password = PasswordField('New Password', [
validators.Required(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
if __name__ == '__main__':
#port = int(os.environ['PORT'])
application.run(host='0.0.0.0',debug=application.config['DEBUG'])