Add last_seen for better administration
This will allow admins to remove users who have not been logged in in a long time
This commit is contained in:
parent
cd7fa8e233
commit
30b40adb80
@ -22,12 +22,15 @@ class User(UserMixin, db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
username = db.Column(db.String(64), index=True, unique=True)
|
username = db.Column(db.String(64), index=True, unique=True)
|
||||||
password_hash = db.Column(db.String(128))
|
password_hash = db.Column(db.String(128))
|
||||||
#last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
last_seen = db.Column(db.DateTime, default=datetime.utcnow())
|
||||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User {}>'.format(self.username)
|
return '<User {}>'.format(self.username)
|
||||||
|
|
||||||
|
def set_last_seen(self):
|
||||||
|
self.last_seen = datetime.utcnow()
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
self.password_hash = generate_password_hash(password)
|
self.password_hash = generate_password_hash(password)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ ALLOWED_EXTENSIONS = {'json', 'db'}
|
|||||||
@app.route('/index')
|
@app.route('/index')
|
||||||
@login_required
|
@login_required
|
||||||
def index():
|
def index():
|
||||||
#current_user.last_seen = datetime.datetime.utcnow()
|
current_user.set_last_seen()
|
||||||
return render_template('home.html')
|
return render_template('home.html')
|
||||||
|
|
||||||
@app.route('/twitter')
|
@app.route('/twitter')
|
||||||
@ -400,18 +400,18 @@ def logout():
|
|||||||
@app.route('/settings')
|
@app.route('/settings')
|
||||||
@login_required
|
@login_required
|
||||||
def settings():
|
def settings():
|
||||||
'''active = 1
|
active = 1
|
||||||
for user in User.query.all():
|
for user in User.query.all():
|
||||||
if not user.last_seen == None:
|
if not user.last_seen == None:
|
||||||
t = datetime.datetime.utcnow() - user.last_seen
|
t = datetime.datetime.utcnow() - user.last_seen
|
||||||
s = t.total_seconds()
|
s = t.total_seconds()
|
||||||
m = s/60
|
m = s/60
|
||||||
if m < 40:
|
if m < 40:
|
||||||
active = active+1'''
|
active = active+1
|
||||||
|
|
||||||
instanceInfo = {
|
instanceInfo = {
|
||||||
"totalUsers":db.session.query(User).count(),
|
"totalUsers":db.session.query(User).count(),
|
||||||
"active":"unknown",
|
"active":active,
|
||||||
"location":config['serverLocation'],
|
"location":config['serverLocation'],
|
||||||
"serverName":config['serverName']
|
"serverName":config['serverName']
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
<link rel="stylesheet"href= "{{ url_for('static',filename='semantic/semantic.min.css') }}">
|
<link rel="stylesheet"href= "{{ url_for('static',filename='semantic/semantic.min.css') }}">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="ui warning message">
|
||||||
|
<div class="header">
|
||||||
|
Server under maintenance.
|
||||||
|
</div>
|
||||||
|
You can experience some downtimes.
|
||||||
|
</div>
|
||||||
<div class="ui icon menu overflow-auto">
|
<div class="ui icon menu overflow-auto">
|
||||||
<a href="{{ url_for('index') }}"><div class="item">
|
<a href="{{ url_for('index') }}"><div class="item">
|
||||||
<img alt="Yotter simple logo" src="{{ url_for('static',filename='img/logo_simple.png') }}">
|
<img alt="Yotter simple logo" src="{{ url_for('static',filename='img/logo_simple.png') }}">
|
||||||
|
Reference in New Issue
Block a user