in data_annotation_platform/app/auth/routes.py [0:0]
def login():
form = LoginForm()
if form.validate_on_submit():
# log the user in if exists
user = User.query.filter_by(username=form.username.data).first()
if user is None or not user.check_password(form.password.data):
flash("Invalid username or password", "error")
return redirect(url_for("auth.login"))
login_user(user)
# record last_active time
current_user.last_active = datetime.datetime.utcnow()
db.session.commit()
# remove any assigned unfinished datasets, as these may no longer be
# needed
user_tasks = Task.query.filter_by(
annotator_id=current_user.id, done=False
).all()
for task in user_tasks:
if task.admin_assigned:
continue
anns = Annotation.query.filter_by(task_id=task.id).all()
if len(anns) > 0:
flash(
"Internal error, unfinished tasks has annotations!",
"error",
)
db.session.delete(task)
db.session.commit()
# redirect if not confirmed yet
if not user.is_confirmed:
return redirect(url_for("auth.not_confirmed"))
# Get the next page from the request (default to index)
next_page = request.args.get("next")
if not next_page or url_parse(next_page).netloc != "":
next_page = url_for("main.index")
# redirect if not introduced yet
if not user.is_introduced:
return redirect(url_for("main.index"))
return redirect(next_page)
return render_template("auth/login.html", title="Sign In", form=form)