diff options
author | Andrew Godwin | 2022-12-05 19:21:00 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-05 19:24:46 -0700 |
commit | a31f676b46a4d904954b8b7227dcde779aedca54 (patch) | |
tree | d00fa3e022ff08f154f431777ba37e2f43127fd6 /users | |
parent | da9a3d853eda1173ac8913908d512fb9babbd136 (diff) | |
download | takahe-a31f676b46a4d904954b8b7227dcde779aedca54.tar.gz takahe-a31f676b46a4d904954b8b7227dcde779aedca54.tar.bz2 takahe-a31f676b46a4d904954b8b7227dcde779aedca54.zip |
Policy pages and signup tests.
Fixes #113
Diffstat (limited to 'users')
-rw-r--r-- | users/views/admin/__init__.py | 6 | ||||
-rw-r--r-- | users/views/admin/settings.py | 33 | ||||
-rw-r--r-- | users/views/auth.py | 37 |
3 files changed, 73 insertions, 3 deletions
diff --git a/users/views/admin/__init__.py b/users/views/admin/__init__.py index 04e1195..b8ebc40 100644 --- a/users/views/admin/__init__.py +++ b/users/views/admin/__init__.py @@ -17,7 +17,11 @@ from users.views.admin.hashtags import ( # noqa HashtagEdit, Hashtags, ) -from users.views.admin.settings import BasicSettings, TuningSettings # noqa +from users.views.admin.settings import ( # noqa + BasicSettings, + PoliciesSettings, + TuningSettings, +) @method_decorator(admin_required, name="dispatch") diff --git a/users/views/admin/settings.py b/users/views/admin/settings.py index dc56693..a4e0190 100644 --- a/users/views/admin/settings.py +++ b/users/views/admin/settings.py @@ -44,7 +44,7 @@ class BasicSettings(AdminSettingsPage): }, "site_about": { "title": "About This Site", - "help_text": "Displayed on the homepage and the about page.\nNewlines are preserved; HTML also allowed.", + "help_text": "Displayed on the homepage and the about page.\nUse Markdown for formatting.", "display": "textarea", }, "site_icon": { @@ -155,3 +155,34 @@ class TuningSettings(AdminSettingsPage): "cache_timeout_identity_feed", ], } + + +class PoliciesSettings(AdminSettingsPage): + + section = "policies" + + options = { + "policy_terms": { + "title": "Terms of Service Page", + "help_text": "Will only be shown if it has content. Use Markdown for formatting.", + "display": "textarea", + }, + "policy_privacy": { + "title": "Privacy Policy Page", + "help_text": "Will only be shown if it has content. Use Markdown for formatting.", + "display": "textarea", + }, + "policy_rules": { + "title": "Server Rules Page", + "help_text": "Will only be shown if it has content. Use Markdown for formatting.", + "display": "textarea", + }, + } + + layout = { + "Policies": [ + "policy_rules", + "policy_terms", + "policy_privacy", + ], + } diff --git a/users/views/auth.py b/users/views/auth.py index 61e9a29..acb22b6 100644 --- a/users/views/auth.py +++ b/users/views/auth.py @@ -30,10 +30,40 @@ class Signup(FormView): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # Add the invite field if it's enabled if Config.system.signup_invite_only: self.fields["invite_code"] = forms.CharField( help_text="Your invite code from one of our admins" ) + # Add the policies if they're defined + policies = [] + if Config.system.policy_rules: + policies.append("<a href='/pages/rules/'>Server Rules</a>") + if Config.system.policy_terms: + policies.append("<a href='/pages/terms/'>Terms of Service</a>") + if Config.system.policy_privacy: + policies.append("<a href='/pages/privacy/'>Privacy Policy</a>") + if policies: + links = "" + for i, policy in enumerate(policies): + if i == 0: + links += policy + elif i == len(policies) - 1: + if len(policies) > 2: + links += ", and " + else: + links += " and " + links += policy + else: + links += ", " + links += policy + self.fields["policy"] = forms.BooleanField( + label="Policies", + help_text=f"Have you read the {links}, and agree to them?", + widget=forms.Select( + choices=[(False, "I do not agree"), (True, "I agree")] + ), + ) def clean_email(self): email = self.cleaned_data.get("email").lower() @@ -45,8 +75,13 @@ class Signup(FormView): def clean_invite_code(self): invite_code = self.cleaned_data["invite_code"].lower().strip() - if not Invite.objects.filter(token=invite_code).exists(): + invite = Invite.objects.filter(token=invite_code).first() + if not invite: raise forms.ValidationError("That is not a valid invite code") + if invite.email and invite.email != self.cleaned_data.get("email"): + raise forms.ValidationError( + "That is not a valid invite code for this email address" + ) return invite_code def clean(self): |