def form_valid(self, form): # Send email to notify team about account being deleted buffer_date = (date.today() + timedelta( days=ccsettings.ACCOUNT_DELETION_BUFFER)).strftime('%A, %B %d %Y') subject = "Kolibri Studio account deleted" message = render_to_string( 'settings/account_deleted_notification_email.txt', { "user": self.request.user, "buffer_date": buffer_date }) send_mail(subject, message, ccsettings.DEFAULT_FROM_EMAIL, [ccsettings.REGISTRATION_INFORMATION_EMAIL]) # Send email to user regarding account deletion site = get_current_site(self.request) subject = _("Kolibri Studio account deleted") message = render_to_string( 'settings/account_deleted_user_email.txt', { "user": self.request.user, "buffer_date": buffer_date, "legal_email": ccsettings.POLICY_EMAIL, "num_days": ccsettings.ACCOUNT_DELETION_BUFFER, "site_name": site and site.name, }) send_mail(subject, message, ccsettings.DEFAULT_FROM_EMAIL, [ ccsettings.REGISTRATION_INFORMATION_EMAIL, self.request.user.email ]) # Delete user csv files csv_path = generate_user_csv_filename( self.request.user) # Remove any generated csvs if os.path.exists(csv_path): os.unlink(csv_path) self.request.user.delete()
def delete_user_account(request, user_email): if request.user.email != user_email: return HttpResponseForbidden(_("Cannot delete another user's account")) elif request.user.is_admin or request.user.is_staff: return HttpResponseBadRequest(_("Cannot delete admin accounts")) # Send email to notify team about account being deleted buffer_date = (date.today() + timedelta( days=ccsettings.ACCOUNT_DELETION_BUFFER)).strftime('%A, %B %d %Y') subject = "Kolibri Studio Account Deleted" message = render_to_string( 'settings/account_deleted_notification_email.txt', { "user": request.user, "buffer_date": buffer_date }) send_mail(subject, message, ccsettings.DEFAULT_FROM_EMAIL, [ccsettings.REGISTRATION_INFORMATION_EMAIL]) # Send email to user regarding account deletion site = get_current_site(request) subject = _("Kolibri Studio Account Deleted") message = render_to_string( 'settings/account_deleted_user_email.txt', { "user": request.user, "buffer_date": buffer_date, "legal_email": ccsettings.POLICY_EMAIL, "num_days": ccsettings.ACCOUNT_DELETION_BUFFER, "site_name": site and site.name, }) send_mail(subject, message, ccsettings.DEFAULT_FROM_EMAIL, [ccsettings.REGISTRATION_INFORMATION_EMAIL]) # Delete user, any previously deleted channels, channel sets, and csvs for c in request.user.editable_channels.all(): if c.editors.count() == 1: c.delete() for cs in request.user.channel_sets.all(): if cs.editors.count() == 1: cs.delete() csv_path = generate_user_csv_filename( request.user) # Remove any generated csvs if os.path.exists(csv_path): os.unlink(csv_path) request.user.delete() return HttpResponse({"success": True})