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
550a5055d3
commit
118bd6ea40
@ -22,6 +22,7 @@ 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)
|
||||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -168,3 +169,4 @@ class Post(db.Model):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Post {}>'.format(self.body)
|
return '<Post {}>'.format(self.body)
|
||||||
|
|
@ -45,6 +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()
|
||||||
return render_template('home.html')
|
return render_template('home.html')
|
||||||
|
|
||||||
@app.route('/twitter')
|
@app.route('/twitter')
|
||||||
@ -389,8 +390,18 @@ def logout():
|
|||||||
@app.route('/settings')
|
@app.route('/settings')
|
||||||
@login_required
|
@login_required
|
||||||
def settings():
|
def settings():
|
||||||
|
active = 1
|
||||||
|
for user in User.query.all():
|
||||||
|
if not user.last_seen == None:
|
||||||
|
t = datetime.datetime.utcnow() - user.last_seen
|
||||||
|
s = t.total_seconds()
|
||||||
|
m = s/60
|
||||||
|
if m < 40:
|
||||||
|
active = active+1
|
||||||
|
|
||||||
instanceInfo = {
|
instanceInfo = {
|
||||||
"totalUsers":db.session.query(User).count(),
|
"totalUsers":db.session.query(User).count(),
|
||||||
|
"active":active,
|
||||||
"location":config['serverLocation'],
|
"location":config['serverLocation'],
|
||||||
"serverName":config['serverName']
|
"serverName":config['serverName']
|
||||||
}
|
}
|
||||||
@ -734,3 +745,4 @@ def getYoutubePosts(ids):
|
|||||||
video.description = re.sub(r'^https?:\/\/.*[\r\n]*', '', video.description[0:120]+"...", flags=re.MULTILINE)
|
video.description = re.sub(r'^https?:\/\/.*[\r\n]*', '', video.description[0:120]+"...", flags=re.MULTILINE)
|
||||||
videos.append(video)
|
videos.append(video)
|
||||||
return videos
|
return videos
|
||||||
|
|
@ -90,6 +90,9 @@
|
|||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
<p><b>Total users:</b> {{info.totalUsers}}</p>
|
<p><b>Total users:</b> {{info.totalUsers}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui segment">
|
||||||
|
<p><b>Active users:</b> {{info.active}}</p>
|
||||||
|
</div>
|
||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
<p><b>Server location:</b> {{info.location}}</p>
|
<p><b>Server location:</b> {{info.location}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user