def password_recovery(self, request, pk=None): username_or_email = request.DATA.get('username', None) self.check_permissions(request, "password_recovery", None) if not username_or_email: raise exc.WrongArguments(_("Invalid username or email")) try: queryset = models.User.objects.all() user = queryset.get( Q(username=username_or_email) | Q(email=username_or_email)) except models.User.DoesNotExist: raise exc.WrongArguments(_("Invalid username or email")) user.token = str(uuid.uuid1()) user.save(update_fields=["token"]) mbuilder = MagicMailBuilder() email = mbuilder.password_recovery(user.email, {"user": user}) email.send() return Response({ "detail": _("Mail sended successful!"), "email": user.email })
def password_recovery(self, request): """ Get a token to email for change password via token. --- serializer: AccountRecoverySerializer """ username_or_email = request.data.get('username', None) if not username_or_email: raise WrongArguments(_("Invalid username or email")) try: queryset = User.objects.all() user = queryset.get( Q(username=username_or_email) | Q(email=username_or_email)) except User.DoesNotExist: raise WrongArguments(_("Invalid username or email")) user.token = str(uuid.uuid1()) user.save(update_fields=["token"]) mbuilder = MagicMailBuilder() email = mbuilder.password_recovery( user.email, { "user": user, "base_url": settings.WEBSITE_BASE_URL, }) email.send() return Response( { "success": _("Mail sended successful!"), "email": user.email, }, status=status.HTTP_200_OK)
def password_recovery(self, request, pk=None): username_or_email = request.DATA.get('username', None) if not username_or_email: raise exc.WrongArguments(_("Invalid username or email")) try: queryset = User.objects.all() user = queryset.get(Q(username=username_or_email) | Q(email=username_or_email)) except User.DoesNotExist: raise exc.WrongArguments(_("Invalid username or email")) user.token = str(uuid.uuid1()) user.save(update_fields=["token"]) mbuilder = MagicMailBuilder() email = mbuilder.password_recovery(user.email, {"user": user}) email.send() return Response({"detail": _("Mail sended successful!")})
def password_recovery(self, request, pk=None): username_or_email = request.DATA.get('username', None) self.check_permissions(request, "password_recovery", None) if not username_or_email: raise exc.WrongArguments(_("Invalid username or email")) try: queryset = models.User.objects.all() user = queryset.get(Q(username=username_or_email) | Q(email=username_or_email)) except models.User.DoesNotExist: raise exc.WrongArguments(_("Invalid username or email")) user.token = str(uuid.uuid1()) user.save(update_fields=["token"]) mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail) email = mbuilder.password_recovery(user, {"user": user}) email.send() return response.Ok({"detail": _("Mail sended successful!")})
def handle(self, *args, **options): if len(args) != 1: print("Usage: ./manage.py test_emails <email-address>") return test_email = args[0] mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail) # Register email context = {"user": User.objects.all().order_by("?").first(), "cancel_token": "cancel-token"} email = mbuilder.registered_user(test_email, context) email.send() # Membership invitation context = {"membership": Membership.objects.order_by("?").filter(user__isnull=True).first()} email = mbuilder.membership_invitation(test_email, context) email.send() # Membership notification context = {"membership": Membership.objects.order_by("?").filter(user__isnull=False).first()} email = mbuilder.membership_notification(test_email, context) email.send() # Feedback context = { "feedback_entry": { "full_name": "Test full name", "email": "*****@*****.**", "comment": "Test comment", }, "extra": { "key1": "value1", "key2": "value2", }, } email = mbuilder.feedback_notification(test_email, context) email.send() # Password recovery context = {"user": User.objects.all().order_by("?").first()} email = mbuilder.password_recovery(test_email, context) email.send() # Change email context = {"user": User.objects.all().order_by("?").first()} email = mbuilder.change_email(test_email, context) email.send() # Notification emails notification_emails = [ "issues/issue-change", "issues/issue-create", "issues/issue-delete", "milestones/milestone-change", "milestones/milestone-create", "milestones/milestone-delete", "projects/project-change", "projects/project-create", "projects/project-delete", "tasks/task-change", "tasks/task-create", "tasks/task-delete", "userstories/userstory-change", "userstories/userstory-create", "userstories/userstory-delete", "wiki/wikipage-change", "wiki/wikipage-create", "wiki/wikipage-delete", ] context = { "snapshot": HistoryEntry.objects.filter(is_snapshot=True).order_by("?")[0].snapshot, "project": Project.objects.all().order_by("?").first(), "changer": User.objects.all().order_by("?").first(), "history_entries": HistoryEntry.objects.all().order_by("?")[0:5], "user": User.objects.all().order_by("?").first(), } for notification_email in notification_emails: cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail,), {"name": notification_email}) email = cls() email.send(test_email, context)
def handle(self, *args, **options): if len(args) != 1: print("Usage: ./manage.py test_emails <email-address>") return test_email = args[0] mbuilder = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail) # Register email context = {"user": User.objects.all().order_by("?").first(), "cancel_token": "cancel-token"} email = mbuilder.registered_user(test_email, context) email.send() # Membership invitation membership = Membership.objects.order_by("?").filter(user__isnull=True).first() membership.invited_by = User.objects.all().order_by("?").first() membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example" context = {"membership": membership} email = mbuilder.membership_invitation(test_email, context) email.send() # Membership notification context = {"membership": Membership.objects.order_by("?").filter(user__isnull=False).first()} email = mbuilder.membership_notification(test_email, context) email.send() # Feedback context = { "feedback_entry": { "full_name": "Test full name", "email": "*****@*****.**", "comment": "Test comment", }, "extra": { "key1": "value1", "key2": "value2", }, } email = mbuilder.feedback_notification(test_email, context) email.send() # Password recovery context = {"user": User.objects.all().order_by("?").first()} email = mbuilder.password_recovery(test_email, context) email.send() # Change email context = {"user": User.objects.all().order_by("?").first()} email = mbuilder.change_email(test_email, context) email.send() # Export/Import emails context = { "user": User.objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), "error_subject": "Error generating project dump", "error_message": "Error generating project dump", } email = mbuilder.export_error(test_email, context) email.send() context = { "user": User.objects.all().order_by("?").first(), "error_subject": "Error importing project dump", "error_message": "Error importing project dump", } email = mbuilder.import_error(test_email, context) email.send() deletion_date = timezone.now() + datetime.timedelta(seconds=60*60*24) context = { "url": "http://dummyurl.com", "user": User.objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), "deletion_date": deletion_date, } email = mbuilder.dump_project(test_email, context) email.send() context = { "user": User.objects.all().order_by("?").first(), "project": Project.objects.all().order_by("?").first(), } email = mbuilder.load_dump(test_email, context) email.send() # Notification emails notification_emails = [ ("issues.Issue", "issues/issue-change"), ("issues.Issue", "issues/issue-create"), ("issues.Issue", "issues/issue-delete"), ("tasks.Task", "tasks/task-change"), ("tasks.Task", "tasks/task-create"), ("tasks.Task", "tasks/task-delete"), ("userstories.UserStory", "userstories/userstory-change"), ("userstories.UserStory", "userstories/userstory-create"), ("userstories.UserStory", "userstories/userstory-delete"), ("milestones.Milestone", "milestones/milestone-change"), ("milestones.Milestone", "milestones/milestone-create"), ("milestones.Milestone", "milestones/milestone-delete"), ("wiki.WikiPage", "wiki/wikipage-change"), ("wiki.WikiPage", "wiki/wikipage-create"), ("wiki.WikiPage", "wiki/wikipage-delete"), ] context = { "project": Project.objects.all().order_by("?").first(), "changer": User.objects.all().order_by("?").first(), "history_entries": HistoryEntry.objects.all().order_by("?")[0:5], "user": User.objects.all().order_by("?").first(), } for notification_email in notification_emails: model = get_model(*notification_email[0].split(".")) snapshot = { "subject": "Tests subject", "ref": 123123, "name": "Tests name", "slug": "test-slug" } queryset = model.objects.all().order_by("?") for obj in queryset: end = False entries = get_history_queryset_by_model_instance(obj).filter(is_snapshot=True).order_by("?") for entry in entries: if entry.snapshot: snapshot = entry.snapshot end = True break if end: break context["snapshot"] = snapshot cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail,), {"name": notification_email[1]}) email = cls() email.send(test_email, context)