Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show legal agreement checkbox when agreement files exist #21

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 27 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,42 @@
import hashlib
import time
import json
import os.path

import resources as res

# Application instance
app = Flask(__name__)


class Resources():
def _does_resource_exist(self, file_name):
static_folder = app.static_folder

if file_name is None or static_folder is None:
return False

return os.path.isfile(os.path.join(static_folder, file_name))

def __init__(self) -> None:
self.LOGO = res.LOGO or 'logo/logo.png'

self.PRIVACY_POLICY = res.PRIVACY_POLICY
self.TERMS_OF_USE = res.TERMS_OF_USE

resources = Resources()
legal_agreement_resources = [res.PRIVACY_POLICY, res.TERMS_OF_USE]
missing_legal_agreement_resources = [file for file in legal_agreement_resources if not self._does_resource_exist(file)]

# Application instance
app = Flask(__name__)
# If any of the files are present, require user agreement
self.requires_user_agreement = len(missing_legal_agreement_resources) < len(legal_agreement_resources)
# Require that either all files are missing, or all files are present; otherwise print a warning
if self.requires_user_agreement and missing_legal_agreement_resources:
print("Warning: Missing legal resource files:")
for file in missing_legal_agreement_resources:
print(" " + file)


resources = Resources()

# SQL instance
db = SQLAlchemy()
Expand Down Expand Up @@ -330,7 +353,7 @@ def account_creation(key):
agree = request.form['agree'] if 'agree' in request.form else False

# If the user didn't agree to the terms, return an error.
if not agree:
if resources.requires_user_agreement and not agree:
return render_template('public/account_creation.html', error="You must agree to the Privacy Policy and Terms of Service to continue.", resources=resources)

# If the passwords don't match, return an error.
Expand Down
3 changes: 1 addition & 2 deletions templates/private/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h3>Key Creation</h3>
{# Key count input #}
<div class="form-group">
<label for="key_count">Generate keys</label>
<input type="number" class="form-control" name="key_count" placeholder="Enter number of keys..." required min="1">
<input type="number" class="form-control" id="key_count" name="key_count" placeholder="Enter number of keys..." required min="1">
<small class="form-text text-muted">Number of keys to create.</small>
</div>

Expand All @@ -86,7 +86,6 @@ <h3>Key Creation</h3>
</div>
<div class="col-lg-3">
</div>
</div>
</div>

{# Activity graphs #}
Expand Down
3 changes: 1 addition & 2 deletions templates/private/data_download.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{# Account Name input #}
<div class="form-group">
<label for="character_name">Character Name</label>
<input type="text" class="form-control" name="character_name" placeholder="Enter username..." required minlength="1">
<input type="text" class="form-control" id="character_name" name="character_name" placeholder="Enter username..." required minlength="1">
<small class="form-text text-muted">Full character name.</small>
</div>

Expand All @@ -48,6 +48,5 @@
</div>
<div class="col-lg-3">
</div>
</div>
</div>
{% endblock %}
7 changes: 3 additions & 4 deletions templates/private/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@
{# Admin Username input #}
<div class="form-group">
<label for="account_name">Username</label>
<input type="text" class="form-control" name="account_name" placeholder="Enter username..." required minlength="1">
<input type="text" class="form-control" id="account_name" name="account_name" placeholder="Enter username..." required minlength="1">
</div>

{# Admin password input #}
<div class="form-group">
<label for="account_password">Password</label>
<input type="password" class="form-control" name="account_password" placeholder="Enter password..." required minlength="1">
<input type="password" class="form-control" id="account_password" name="account_password" placeholder="Enter password..." required minlength="1">
<small class="form-text text-muted"></small>
</div>

{# Remember Me #}
<div class="form-group">
<label for="remember_me">Remember Me</label>
<input type="checkbox" class="form-control" name="remember_me">
<input type="checkbox" class="form-control" id="remember_me" name="remember_me">
<small class="form-text text-muted"></small>
</div>

Expand All @@ -72,6 +72,5 @@
</div>
<div class="col-lg-3">
</div>
</div>
</div>
{% endblock %}
23 changes: 12 additions & 11 deletions templates/public/account_creation.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,40 @@
{# Play Key input #}
<div class="form-group">
<label for="play_key">Play Key</label>
<input type="text" class="form-control" name="play_key" aria-describedby="emailHelp" placeholder="AAAA-BBBB-CCCC-DDDD" value="{{ key }}" required pattern="([A-Z0-9]{4}-){3}[A-Z0-9]{4}">
<input type="text" class="form-control" id="play_key" name="play_key" aria-describedby="emailHelp" placeholder="AAAA-BBBB-CCCC-DDDD" value="{{ key }}" required pattern="([A-Z0-9]{4}-){3}[A-Z0-9]{4}">
<small class="form-text text-muted">In the format: AAAA-BBBB-CCCC-DDDD</small>
</div>

{# Account Name input #}
<div class="form-group">
<label for="account_name">Username</label>
<input type="text" class="form-control" name="account_name" placeholder="Enter username..." required pattern="[a-zA-Z0-9]{1,32}">
<input type="text" class="form-control" id="account_name" name="account_name" placeholder="Enter username..." required pattern="[a-zA-Z0-9]{1,32}">
<small class="form-text text-muted">Limited to a-z, A-Z, and 0-9. No spaces or special characters. Max 32 characters.</small>
</div>

{# Account Password input #}
<div class="form-group">
<label for="account_password">Password</label>
<input type="password" class="form-control" name="account_password" placeholder="Enter password..." required minlength="4">
<input type="password" class="form-control" id="account_password" name="account_password" placeholder="Enter password..." required minlength="4">
<small class="form-text text-muted"></small>
</div>

{# Account Repeat Password input #}
<div class="form-group">
<label for="account_repeat_password">Repeat Password</label>
<input type="password" class="form-control" name="account_repeat_password" placeholder="Repeat password..." required minlength="4">
<input type="password" class="form-control" id="account_repeat_password name="account_repeat_password" placeholder="Repeat password..." required minlength="4">
<small class="form-text text-muted"></small>
</div>

{# Agree to the Privacy Policy and Terms of Service #}
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" name="agree">
I agree to the <a href="{{ url_for('static', filename=resources.PRIVACY_POLICY) }}" target="_blank">Privacy Policy</a> and <a href="{{ url_for('static', filename=resources.TERMS_OF_USE) }}" target="_blank">Terms of Service</a>
</label>
</div>
{% if resources.requires_user_agreement %}
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" name="agree">
I agree to the <a href="{{ url_for('static', filename=resources.PRIVACY_POLICY) }}" target="_blank">Privacy Policy</a> and <a href="{{ url_for('static', filename=resources.TERMS_OF_USE) }}" target="_blank">Terms of Service</a>
</label>
</div>
{% endif %}

{# Submit button #}
<div class="form-group">
Expand All @@ -77,6 +79,5 @@
</div>
<div class="col-lg-3">
</div>
</div>
</div>
{% endblock %}