User can export their data
This commit is contained in:
parent
642b6531b1
commit
0955f13593
|
@ -57,6 +57,16 @@
|
|||
<button class="btn btn-outline-primary">Change password</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
<h3 class="mb-0">Export Data</h3>
|
||||
<div class="small-text mb-3">
|
||||
You can download all aliases you have created on SimpleLogin along with other data.
|
||||
</div>
|
||||
<form method="post">
|
||||
<input type="hidden" name="form-name" value="export-data">
|
||||
<button class="btn btn-outline-info">Export Data</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
<h3 class="mb-0">Delete Account</h3>
|
||||
<div class="small-text mb-3">Please note that this operation is irreversible.
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import json
|
||||
from io import BytesIO
|
||||
|
||||
import arrow
|
||||
from flask import render_template, request, redirect, url_for, flash
|
||||
from flask import render_template, request, redirect, url_for, flash, Response
|
||||
from flask_login import login_required, current_user, logout_user
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField
|
||||
|
@ -20,6 +21,8 @@ from app.models import (
|
|||
User,
|
||||
GenEmail,
|
||||
DeletedAlias,
|
||||
CustomDomain,
|
||||
Client,
|
||||
)
|
||||
from app.utils import random_string
|
||||
|
||||
|
@ -118,6 +121,34 @@ def setting():
|
|||
logout_user()
|
||||
return redirect(url_for("auth.register"))
|
||||
|
||||
elif request.form.get("form-name") == "export-data":
|
||||
data = {
|
||||
"email": current_user.email,
|
||||
"name": current_user.name,
|
||||
"aliases": [],
|
||||
"apps": [],
|
||||
"custom_domains": [],
|
||||
}
|
||||
|
||||
for alias in GenEmail.filter_by(
|
||||
user_id=current_user.id
|
||||
).all(): # type: GenEmail
|
||||
data["aliases"].append(dict(email=alias.email, enabled=alias.enabled))
|
||||
|
||||
for custom_domain in CustomDomain.filter_by(user_id=current_user.id).all():
|
||||
data["custom_domains"].append(custom_domain.domain)
|
||||
|
||||
for app in Client.filter_by(user_id=current_user.id): # type: Client
|
||||
data["apps"].append(
|
||||
dict(name=app.name, home_url=app.home_url, published=app.published)
|
||||
)
|
||||
|
||||
return Response(
|
||||
json.dumps(data),
|
||||
mimetype="text/json",
|
||||
headers={"Content-Disposition": "attachment;filename=data.json"},
|
||||
)
|
||||
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
|
||||
return render_template(
|
||||
|
|
Loading…
Reference in a new issue