Esempio n. 1
0
 def get(self, request):
     token = request.GET.get('token')
     if not token:
         return HttpResponseBadRequest(_('Token missing'))
     payload, __ = token_utils.decode_token(token,
                                            Token.PASSWORD_CHANGE_TOKEN)
     user = User.objects.get(pk=payload['user_id'], is_active=True)
     new_password = User.objects.make_random_password()
     user.set_password(new_password)
     user.save()
     send_mail(
         subject=_('Reset password'),
         recipient_list=[user.email],
         err_msg=_('Sending email failed'),
         template_name='drjr_email_reset_password_confirm.html',
         context={
             'user': user,
             'new_password': new_password,
         },
     )
     return render(request,
                   'drjr_reset_password_confirm.html',
                   context={
                       'user': user,
                   })
Esempio n. 2
0
 def post(self, request):
     serializer = self.serializer_class(data=request.data)
     serializer.is_valid(raise_exception=True)
     try:
         user = User.objects.get(
             email=serializer.validated_data.get('email'), is_active=True)
     except User.DoesNotExist:
         return Response({
             'detail':
             _('Confirmation email sent if a user with given email address exists'
               )
         })
     token_db_instance = token_utils.encode_token(
         {'user_id': user.id}, Token.PASSWORD_CHANGE_TOKEN)
     send_mail(
         subject=_('Reset password'),
         recipient_list=[user.email],
         err_msg=_('Sending confirmation email failed'),
         template_name='drjr_email_reset_password.html',
         context={
             'user': user,
             'confirm_url': self.build_confirm_url(token_db_instance.token),
         },
     )
     return Response({
         'detail':
         _('Confirmation email sent if a user with given email address exists'
           )
     })
Esempio n. 3
0
 def delete(self, request):
     user = self.get_object()
     token_db_instance = token_utils.encode_token(
         {'user_id': user.id}, Token.REGISTRATION_DELETE_TOKEN)
     send_mail(
         subject=_('Delete account'),
         recipient_list=[user.email],
         err_msg=_('Sending confirmation email failed'),
         template_name='drjr_email_registration_delete.html',
         context={
             'user': user,
             'confirm_url': self.build_confirm_url(token_db_instance.token),
         },
     )
     return Response({'detail': _('Confirmation email sent')})
Esempio n. 4
0
 def _change_password(self, request):
     user = self.get_object()
     serializer = self.serializer_class(instance=user, data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     send_mail(
         subject=_('Password changed'),
         recipient_list=[user.email],
         err_msg=_('Sending email failed'),
         template_name='drjr_email_change_password.html',
         context={
             'user': user,
         },
     )
     return Response({'detail': _('Password changed')})
Esempio n. 5
0
 def _change_email(self, request):
     user = self.get_object()
     serializer = self.serializer_class(instance=user, data=request.data)
     serializer.is_valid(raise_exception=True)
     email = serializer.validated_data.get('email')
     token_db_instance = token_utils.encode_token(
         {
             'user_id': user.id,
             'email': email,
         }, Token.EMAIL_CHANGE_TOKEN)
     send_mail(
         subject=_('Change email'),
         recipient_list=[email],
         err_msg=_('Sending confirmation email failed'),
         template_name='drjr_email_change_email.html',
         context={
             'user': user,
             'confirm_url': self.build_confirm_url(token_db_instance.token),
         },
     )
     return Response(
         {'detail': _('Confirmation email sent if given email exists')})
Esempio n. 6
0
 def post(self, request):
     serializer = self.serializer_class(data=request.data)
     serializer.is_valid(raise_exception=True)
     data = dict(serializer.validated_data)
     token_db_instance = token_utils.encode_token({},
                                                  Token.REGISTRATION_TOKEN)
     user = User.objects.create(is_active=False, **data)
     user.set_password(data['password'])
     user.save()
     token_db_instance.user = user
     token_db_instance.save()
     send_mail(
         subject=_('Confirm registration'),
         recipient_list=[data['email']],
         err_msg=_('Sending confirmation email failed'),
         template_name='drjr_email_registration.html',
         context={
             'user': user,
             'confirm_url': self.build_confirm_url(token_db_instance.token),
         },
     )
     return Response({'detail': _('Confirmation email sent')})
Esempio n. 7
0
 def get(self, request):
     token = request.GET.get('token')
     if not token:
         return HttpResponseBadRequest(_('Token missing'))
     payload, __ = token_utils.decode_token(token,
                                            Token.REGISTRATION_DELETE_TOKEN)
     user = User.objects.get(pk=payload['user_id'], is_active=True)
     user.delete()
     send_mail(
         subject=_('Account deleted'),
         recipient_list=[user.email],
         err_msg=_('Sending email failed'),
         template_name='drjr_email_registration_delete_confirm.html',
         context={
             'user': user,
         },
     )
     return render(request,
                   'drjr_registration_delete_confirm.html',
                   context={
                       'user': user,
                   })
Esempio n. 8
0
 def get(self, request):
     token = request.GET.get('token')
     if not token:
         return HttpResponseBadRequest(_('Token missing'))
     __, token_db_instance = token_utils.decode_token(
         token, Token.REGISTRATION_TOKEN)
     user = token_db_instance.user
     user.is_active = True
     user.save()
     send_mail(
         subject=_('Registration activated'),
         recipient_list=[user.email],
         err_msg=_('Sending email failed'),
         template_name='drjr_email_registration_confirm.html',
         context={
             'user': user,
         },
     )
     return render(request,
                   'drjr_registration_confirm.html',
                   context={
                       'user': user,
                   })
Esempio n. 9
0
 def get(self, request):
     token = request.GET.get('token')
     if not token:
         return HttpResponseBadRequest(_('Token missing'))
     payload, __ = token_utils.decode_token(token, Token.EMAIL_CHANGE_TOKEN)
     user = User.objects.get(pk=payload['user_id'], is_active=True)
     new_email = payload['email']
     user.email = new_email
     user.save()
     send_mail(
         subject=_('Email changed'),
         recipient_list=[user.email],
         err_msg=_('Sending email failed'),
         template_name='drjr_email_change_email_confirm.html',
         context={
             'user': user,
             'new_email': new_email,
         },
     )
     return render(request,
                   'drjr_email_change_confirm.html',
                   context={
                       'user': user,
                   })