Add user last_seen

This will facilitate maintenance in the future. Running a script to clean the database from dead accounts will now be much easier
This commit is contained in:
pluja 2020-09-06 11:24:03 +02:00
parent e325fdd08a
commit 6bd045ba6b
2 changed files with 5 additions and 0 deletions

View File

@ -23,6 +23,7 @@ class User(UserMixin, db.Model):
username = db.Column(db.String(64), index=True, unique=True)
password_hash = db.Column(db.String(128))
posts = db.relationship('Post', backref='author', lazy='dynamic')
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '<User {}>'.format(self.username)

View File

@ -369,7 +369,10 @@ def login():
flash('Invalid username or password')
return redirect(url_for('login'))
login_user(user, remember=form.remember_me.data)
current_user.last_seen = datetime.datetime.utcnow()
db.session.commit()
next_page = request.args.get('next')
print(current_user.last_seen)
if not next_page or url_parse(next_page).netloc != '':
next_page = url_for('index')
return redirect(next_page)
@ -526,6 +529,7 @@ def register():
return redirect(url_for('login'))
return render_template('register.html', title='Register', registrations=REGISTRATIONS, form=form)
@app.route('/error/<errno>')
def error(errno):