From 8e22119de9c621c4b514adf942393b0a08af0bcc Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Wed, 5 Feb 2020 13:32:42 +0300 Subject: [PATCH] team --- apps/account/models.py | 1 + apps/account/urls/web.py | 2 + apps/account/views/web.py | 37 +++++++++++++++++++ .../invite_est_team_existing_user.html | 4 +- .../account/invite_est_team_new_user.html | 2 +- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/apps/account/models.py b/apps/account/models.py index dd60086e..33a44569 100644 --- a/apps/account/models.py +++ b/apps/account/models.py @@ -388,6 +388,7 @@ class User(PhoneModelMixin, AbstractUser): 'twitter_page_url': socials.twitter_page_url if socials else '#', 'instagram_page_url': socials.instagram_page_url if socials else '#', 'facebook_page_url': socials.facebook_page_url if socials else '#', + 'contact_email': socials.contact_email if socials else '-', 'send_to': username, } diff --git a/apps/account/urls/web.py b/apps/account/urls/web.py index e590e76d..039ea3fd 100644 --- a/apps/account/urls/web.py +++ b/apps/account/urls/web.py @@ -10,6 +10,8 @@ urlpatterns_api = [ path('reset-password/', views.PasswordResetView.as_view(), name='password-reset'), path('reset-password/confirm///', views.PasswordResetConfirmView.as_view(), name='password-reset-confirm'), + path('join-establishment-team///', views.ApplyUserEstablishmentRole.as_view(), + name='join-establishment-team'), ] urlpatterns = urlpatterns_api + \ diff --git a/apps/account/views/web.py b/apps/account/views/web.py index f8853d3e..d8254fe4 100644 --- a/apps/account/views/web.py +++ b/apps/account/views/web.py @@ -72,3 +72,40 @@ class PasswordResetConfirmView(JWTGenericViewMixin, generics.GenericAPIView): access_token=tokens.get('access_token'), refresh_token=tokens.get('refresh_token')), response=Response(status=status.HTTP_200_OK)) + + +class ApplyUserEstablishmentRole(JWTGenericViewMixin, generics.GenericAPIView): + + queryset = models.User.objects.all() + permission_classes = (permissions.AllowAny,) + + def get_object(self): + """Overridden get_object method""" + queryset = self.filter_queryset(self.get_queryset()) + uidb64 = self.kwargs.get('uidb64') + + user_id = force_text(urlsafe_base64_decode(uidb64)) + token = self.kwargs.get('token') + + user = get_object_or_404(queryset, id=user_id) + + if not GMTokenGenerator(GMTokenGenerator.RESET_PASSWORD).check_token( + user, token): + raise utils_exceptions.NotValidTokenError() + + # May raise a permission denied + self.check_object_permissions(self.request, user) + + return get_object_or_404(klass=models.UserRole, pk=self.kwargs['role_id'], user=user), user + + def patch(self, request, *args, **kwargs): + instance, user = self.get_object() + instance.state = models.UserRole.VALIDATED + instance.save() + # Create tokens + tokens = user.create_jwt_tokens() + return self._put_cookies_in_response( + cookies=self._put_data_in_cookies( + access_token=tokens.get('access_token'), + refresh_token=tokens.get('refresh_token')), + response=Response(status=status.HTTP_200_OK)) diff --git a/project/templates/account/invite_est_team_existing_user.html b/project/templates/account/invite_est_team_existing_user.html index fcdca24a..a70c225b 100644 --- a/project/templates/account/invite_est_team_existing_user.html +++ b/project/templates/account/invite_est_team_existing_user.html @@ -31,7 +31,7 @@

- {% blocktrans %}Hi, you are receiving this email because you have been granted to manage the establishment %restaurant_name%. + {% blocktrans %}Hi, you are receiving this email because you have been granted to manage the establishment {{ restaurant_name }}. From now, you can manage information about this place and have it published in {{ site_name }}.{% endblocktrans %}

@@ -66,7 +66,7 @@ From now, you can manage information about this place and have it published in {
In case that you were not already a Gault&Millau user, a temporary account with your email has been temporarily created by a Gault&Millau administrator. By completing the creation process of your account, you agree to have this account permanently created. -This temporary account will be deleted after 7 days if you don't complete the registration process. Please contact %license_contact_email% if you have any questions. +This temporary account will be deleted after 7 days if you don't complete the registration process. Please contact {{ contact_email }} if you have any questions.