diff --git a/app/app/urls.py b/app/app/urls.py index a161995dec9..27d9d764ce7 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -213,6 +213,7 @@ re_path(r'^settings/feedback/?', marketing.views.feedback_settings, name='feedback_settings'), re_path(r'^settings/slack/?', marketing.views.slack_settings, name='slack_settings'), re_path(r'^settings/ens/?', marketing.views.ens_settings, name='ens_settings'), + re_path(r'^settings/account/?', marketing.views.account_settings, name='account_settings'), re_path(r'^settings/(.*)?', marketing.views.email_settings, name='settings'), # marketing views diff --git a/app/dashboard/models.py b/app/dashboard/models.py index f2ac2416f78..34da9743b2d 100644 --- a/app/dashboard/models.py +++ b/app/dashboard/models.py @@ -908,7 +908,7 @@ class Profile(SuperModel): """ - user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True) + user = models.OneToOneField(User, on_delete=models.SET_NULL, null=True, blank=True) data = JSONField() handle = models.CharField(max_length=255, db_index=True) last_sync_date = models.DateTimeField(null=True) @@ -1280,7 +1280,7 @@ class UserAction(SuperModel): ('removed_slack_integration', 'Removed Slack Integration'), ] action = models.CharField(max_length=50, choices=ACTION_TYPES) - user = models.ForeignKey(User, related_name='actions', on_delete=models.CASCADE, null=True) + user = models.ForeignKey(User, related_name='actions', on_delete=models.SET_NULL, null=True) profile = models.ForeignKey('dashboard.Profile', related_name='actions', on_delete=models.CASCADE, null=True) ip_address = models.GenericIPAddressField(null=True) location_data = JSONField(default={}) diff --git a/app/dashboard/templates/ens/account.html b/app/dashboard/templates/ens/account.html new file mode 100644 index 00000000000..d4f2d30affb --- /dev/null +++ b/app/dashboard/templates/ens/account.html @@ -0,0 +1,28 @@ +{% extends 'ens/base.html' %} +{% load i18n static %} +{% block 'scripts' %} + + + {% block 'ens_script' %} + {% endblock %} +{% endblock %} + +{% block 'main' %} +
+ {% include 'shared/current_balance.html' %} +
+
+
+
+ + + + + +
+
+ {% block 'body_block' %} + {% endblock %} +
+
+{% endblock %} diff --git a/app/marketing/views.py b/app/marketing/views.py index cd43f77b875..18574adf8f0 100644 --- a/app/marketing/views.py +++ b/app/marketing/views.py @@ -23,6 +23,7 @@ import random from django.conf import settings +from django.contrib import messages from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.decorators import login_required from django.core.validators import validate_email @@ -66,8 +67,11 @@ def get_settings_navs(request): 'body': 'Slack', 'href': reverse('slack_settings'), }, { - 'body': f"{subdomain}{settings.ENS_TLD}", + 'body': "ENS", 'href': reverse('ens_settings'), + }, { + 'body': "Account", + 'href': reverse('account_settings'), }] @@ -389,6 +393,51 @@ def ens_settings(request): return TemplateResponse(request, 'settings/ens.html', context) +def account_settings(request): + """Displays and saves user's Account settings. + + Returns: + TemplateResponse: The user's Account settings template response. + + """ + msg = '' + profile, es, user, is_logged_in = settings_helper_get_auth(request) + + if not user or not is_logged_in: + login_redirect = redirect('/login/github?next=' + request.get_full_path()) + return login_redirect + + if request.POST: + + if request.POST.get('disconnect', False): + profile.github_access_token = '' + profile.save() + messages.success(request, _('Your account has been disconnected from Github')) + logout_redirect = redirect(reverse('logout') + '?next=/') + return logout_redirect + if request.POST.get('delete', False): + profile.hide_profile = True + profile.save() + request.user.delete() + messages.success(request, _('Your account has been deleted')) + logout_redirect = redirect(reverse('logout') + '?next=/') + return logout_redirect + else: + msg = _('Error: did not understand your request') + + context = { + 'is_logged_in': is_logged_in, + 'nav': 'internal', + 'active': '/settings/account', + 'title': _('Account Settings'), + 'navs': get_settings_navs(request), + 'es': es, + 'profile': profile, + 'msg': msg, + } + return TemplateResponse(request, 'settings/account.html', context) + + def _leaderboard(request): return leaderboard(request, '') diff --git a/app/retail/templates/settings/account.html b/app/retail/templates/settings/account.html new file mode 100644 index 00000000000..c2591a5e11a --- /dev/null +++ b/app/retail/templates/settings/account.html @@ -0,0 +1,53 @@ +{% extends 'settings/settings.html' %} +{% load i18n static %} +{% block settings_content %} + +
+
{% trans " Account Settings" %}
+
+
+
+
+ {% csrf_token %} + +
+
{% trans "Github" %}
+

{% trans "Connected as " %}{{github_handle}}

+
+
+
+
+
+ {% csrf_token %} + +
+
{% trans "Delete My Account" %}
+

{% trans "This action deletes all of your data" %}

+
+
+ +{% endblock %} +{% block scripts %} + +{% endblock %} diff --git a/app/retail/templates/shared/footer_scripts.html b/app/retail/templates/shared/footer_scripts.html index fd3ada58e13..b59bfbad505 100644 --- a/app/retail/templates/shared/footer_scripts.html +++ b/app/retail/templates/shared/footer_scripts.html @@ -28,6 +28,7 @@ + @@ -54,3 +55,4 @@ + {% include 'shared/messages.html' %}