-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.py
114 lines (96 loc) · 3.39 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
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
"""
Copyright MiranDaniel <[email protected]>
The Software is provided to you by the Licensor under
the License, as defined below, subject to the following
condition.
Without limiting other conditions in the
License, the grant of rights under the License will not
include, and the License does not grant to you, the
right to Sell the Software.
For purposes of the
foregoing, “Sell” means practicing any or all of the
rights granted to you under the License to provide to
third parties, for a fee or other consideration
(including without limitation fees for hosting or
consulting/ support services related to the Software), a
product or service whose value derives, entirely or
substantially, from the functionality of the Software.
Any license notice or attribution required by the
License must also include this Commons Cause License
Condition notice.
THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from flask import Flask, render_template, request, redirect
import yaml
import requests
import exceptions
from utils import verifyRecaptcha, generateInvite, verifyConfig
with open("config.yaml", "r") as f:
try:
config = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)
quit(1)
else:
verifyConfig(config)
app = Flask(__name__)
theme = "text-dark border-dark" if config["dark_theme"] else "text-light border-light"
border = "border-dark" if config["dark_theme"] else ""
catpcha_theme = "dark" if config["dark_theme"] else "light"
@app.route("/")
def index():
key = request.args.get("key")
if key: # User has submitted a captcha
r = verifyRecaptcha(key, request, config)
if r.get("success"): # Captcha is OK
print(f"Recaptcha {key[:30]} verified!")
inviteCode = generateInvite(config)
return redirect(f"https://discord.gg/{inviteCode}")
else: # Captcha failed
print(f"Recaptcha {key[:30]} failed!")
# Return error page
return render_template(
"index.html",
public=config["recaptcha"]["public"],
failed="Invalid captcha, try again",
theme=theme,
border=border,
catpcha_theme=catpcha_theme,
)
return render_template(
"index.html",
public=config["recaptcha"]["public"],
failed=None,
theme=theme,
border=border,
catpcha_theme=catpcha_theme,
) # Return normal page
@app.errorhandler(500)
def internalError(error):
return render_template(
"index.html",
public=config["recaptcha"]["public"],
failed="Internal server error, please try again later",
theme=theme,
border=border,
catpcha_theme=catpcha_theme,
)
@app.errorhandler(404)
def notFound(error):
return render_template(
"index.html",
public=config["recaptcha"]["public"],
failed=None,
theme=theme,
border=border,
catpcha_theme=catpcha_theme,
)