Skip to content
Snippets Groups Projects
Commit 2d9f751a authored by kaiyou's avatar kaiyou
Browse files

Add a warning about upcoming account deletion

parent ff6e47b4
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ DEFAULT_CONFIG = {
'MAIL_DOMAIN': 'tedomum.net',
'WEBSITE_NAME': 'Hiboo',
'OPEN_SIGNUP': True,
'USER_TIMEOUT': 86400,
'API_TOKEN': 'changeMe'
}
......
......@@ -117,12 +117,26 @@ class User(db.Model):
return profile
@classmethod
def get_unused(cls, interval=datetime.timedelta(days=24)):
def get_timeout(self):
""" Return the configured timeout delta as a timedelta
"""
return datetime.timedelta(seconds=int(app.config.get("USER_TIMEOUT")))
def time_to_deletion(self):
""" Return timeout for the current account or None
"""
if self.profiles.count():
return None
last = self.updated_at or self.created_at
return datetime.datetime.now() - User.get_timeout() - last
@classmethod
def get_unused(cls):
return (cls.query
.join(cls.profiles.and_(Profile.status != Profile.PURGED), isouter=True)
.filter(Profile.uuid == None)
.filter(
datetime.datetime.now() - interval >
datetime.datetime.now() - cls.get_timeout() >
sqlalchemy.sql.func.coalesce(cls.updated_at, cls.created_at)
)
)
......
......@@ -84,6 +84,9 @@
{% for category, message in get_flashed_messages(with_categories=True) or [] %}
<div class="alert alert-{{ category or "info" }}">{{ message }}</div>
{% endfor %}
{% if current_user.time_to_deletion and current_user.time_to_deletion() %}
<div class="alert alert-warning">{% trans %}Your account has no active profile, it will be deleted in{% endtrans %} {{ utils.babel.dates.format_timedelta(current_user.time_to_deletion()) }}</div>
{% endif %}
{% block content %}{% endblock %}
</div>
</section>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment