Browse Source

Return user to login page in case of 401

Son NK 5 years ago
parent
commit
e9208810af
2 changed files with 3 additions and 17 deletions
  1. 3 2
      server.py
  2. 0 15
      templates/error/401.html

+ 3 - 2
server.py

@@ -4,7 +4,7 @@ import ssl
 import arrow
 import arrow
 import flask_profiler
 import flask_profiler
 import sentry_sdk
 import sentry_sdk
-from flask import Flask, redirect, url_for, render_template, request, jsonify
+from flask import Flask, redirect, url_for, render_template, request, jsonify, flash
 from flask_admin import Admin
 from flask_admin import Admin
 from flask_cors import cross_origin
 from flask_cors import cross_origin
 from flask_login import current_user
 from flask_login import current_user
@@ -281,7 +281,8 @@ def setup_error_page(app):
 
 
     @app.errorhandler(401)
     @app.errorhandler(401)
     def page_not_found(e):
     def page_not_found(e):
-        return render_template("error/401.html", current_url=request.full_path), 401
+        flash("You need to login to see this page", "error")
+        return redirect(url_for("auth.login", next=request.full_path))
 
 
     @app.errorhandler(403)
     @app.errorhandler(403)
     def page_not_found(e):
     def page_not_found(e):

+ 0 - 15
templates/error/401.html

@@ -1,15 +0,0 @@
-{% extends "error.html" %}
-
-{% block error_name %}
-  You need to login to see this page.
-{% endblock %}
-
-{% block error_description %}
-  We are sorry but you are not authorized to access this page.
-{% endblock %}
-
-{% block suggestion %}
-  <a class="btn btn-primary" href="{{ url_for('auth.login', next=current_url) }}">
-    <i class="fe fe-log-in mr-2"></i>Login
-  </a>
-{% endblock %}