Browse Source

Flask-Login uses properties instead of methods now

Since version 0.3.0. For more information visit see the changelog of
Flask-Login:
https://github.com/maxcountryman/flask-login/blob/master/CHANGES
Peter Justin 9 years ago
parent
commit
b216dd2bfe

+ 3 - 3
flaskbb/app.py

@@ -148,7 +148,7 @@ def configure_extensions(app):
     @babel.localeselector
     @babel.localeselector
     def get_locale():
     def get_locale():
         # if a user is logged in, use the locale from the user settings
         # if a user is logged in, use the locale from the user settings
-        if current_user.is_authenticated() and current_user.language:
+        if current_user.is_authenticated and current_user.language:
             return current_user.language
             return current_user.language
         # otherwise we will just fallback to the default language
         # otherwise we will just fallback to the default language
         return flaskbb_config["DEFAULT_LANGUAGE"]
         return flaskbb_config["DEFAULT_LANGUAGE"]
@@ -213,7 +213,7 @@ def configure_before_handlers(app):
         """Updates `lastseen` before every reguest if the user is
         """Updates `lastseen` before every reguest if the user is
         authenticated."""
         authenticated."""
 
 
-        if current_user.is_authenticated():
+        if current_user.is_authenticated:
             current_user.lastseen = datetime.datetime.utcnow()
             current_user.lastseen = datetime.datetime.utcnow()
             db.session.add(current_user)
             db.session.add(current_user)
             db.session.commit()
             db.session.commit()
@@ -221,7 +221,7 @@ def configure_before_handlers(app):
     if app.config["REDIS_ENABLED"]:
     if app.config["REDIS_ENABLED"]:
         @app.before_request
         @app.before_request
         def mark_current_user_online():
         def mark_current_user_online():
-            if current_user.is_authenticated():
+            if current_user.is_authenticated:
                 mark_online(current_user.username)
                 mark_online(current_user.username)
             else:
             else:
                 mark_online(request.remote_addr, guest=True)
                 mark_online(request.remote_addr, guest=True)

+ 8 - 6
flaskbb/auth/views.py

@@ -31,7 +31,7 @@ def login():
     Logs the user in
     Logs the user in
     """
     """
 
 
-    if current_user is not None and current_user.is_authenticated():
+    if current_user is not None and current_user.is_authenticated:
         return redirect(url_for("user.profile"))
         return redirect(url_for("user.profile"))
 
 
     form = LoginForm(request.form)
     form = LoginForm(request.form)
@@ -81,8 +81,9 @@ def register():
     Register a new user
     Register a new user
     """
     """
 
 
-    if current_user is not None and current_user.is_authenticated():
-        return redirect(url_for("user.profile", username=current_user.username))
+    if current_user is not None and current_user.is_authenticated:
+        return redirect(url_for("user.profile",
+                                username=current_user.username))
 
 
     if current_app.config["RECAPTCHA_ENABLED"]:
     if current_app.config["RECAPTCHA_ENABLED"]:
         from flaskbb.auth.forms import RegisterRecaptchaForm
         from flaskbb.auth.forms import RegisterRecaptchaForm
@@ -100,7 +101,8 @@ def register():
         login_user(user)
         login_user(user)
 
 
         flash(_("Thanks for registering."), "success")
         flash(_("Thanks for registering."), "success")
-        return redirect(url_for("user.profile", username=current_user.username))
+        return redirect(url_for("user.profile",
+                                username=current_user.username))
 
 
     return render_template("auth/register.html", form=form)
     return render_template("auth/register.html", form=form)
 
 
@@ -111,7 +113,7 @@ def forgot_password():
     Sends a reset password token to the user.
     Sends a reset password token to the user.
     """
     """
 
 
-    if not current_user.is_anonymous():
+    if not current_user.is_anonymous:
         return redirect(url_for("forum.index"))
         return redirect(url_for("forum.index"))
 
 
     form = ForgotPasswordForm()
     form = ForgotPasswordForm()
@@ -136,7 +138,7 @@ def reset_password(token):
     Handles the reset password process.
     Handles the reset password process.
     """
     """
 
 
-    if not current_user.is_anonymous():
+    if not current_user.is_anonymous:
         return redirect(url_for("forum.index"))
         return redirect(url_for("forum.index"))
 
 
     form = ResetPasswordForm()
     form = ResetPasswordForm()

+ 6 - 6
flaskbb/forum/models.py

@@ -374,7 +374,7 @@ class Topic(db.Model, CRUDMixin):
                            read.
                            read.
         """
         """
         # User is not logged in - abort
         # User is not logged in - abort
-        if not user.is_authenticated():
+        if not user.is_authenticated:
             return False
             return False
 
 
         topicsread = TopicsRead.query.\
         topicsread = TopicsRead.query.\
@@ -676,7 +676,7 @@ class Forum(db.Model, CRUDMixin):
                            forumsread relation should be updated and
                            forumsread relation should be updated and
                            therefore is unread.
                            therefore is unread.
         """
         """
-        if not user.is_authenticated() or topicsread is None:
+        if not user.is_authenticated or topicsread is None:
             return False
             return False
 
 
         read_cutoff = None
         read_cutoff = None
@@ -810,7 +810,7 @@ class Forum(db.Model, CRUDMixin):
         :param user: The user object is needed to check if we also need their
         :param user: The user object is needed to check if we also need their
                      forumsread object.
                      forumsread object.
         """
         """
-        if user.is_authenticated():
+        if user.is_authenticated:
             forum, forumsread = Forum.query.\
             forum, forumsread = Forum.query.\
                 filter(Forum.id == forum_id).\
                 filter(Forum.id == forum_id).\
                 options(db.joinedload("category")).\
                 options(db.joinedload("category")).\
@@ -836,7 +836,7 @@ class Forum(db.Model, CRUDMixin):
         :param page: The page whom should be loaded
         :param page: The page whom should be loaded
         :param per_page: How many topics per page should be shown
         :param per_page: How many topics per page should be shown
         """
         """
-        if user.is_authenticated():
+        if user.is_authenticated:
             topics = Topic.query.filter_by(forum_id=forum_id).\
             topics = Topic.query.filter_by(forum_id=forum_id).\
                 outerjoin(TopicsRead,
                 outerjoin(TopicsRead,
                           db.and_(TopicsRead.topic_id == Topic.id,
                           db.and_(TopicsRead.topic_id == Topic.id,
@@ -924,7 +924,7 @@ class Category(db.Model, CRUDMixin):
         """
         """
         # import Group model locally to avoid cicular imports
         # import Group model locally to avoid cicular imports
         from flaskbb.user.models import Group
         from flaskbb.user.models import Group
-        if user.is_authenticated():
+        if user.is_authenticated:
             # get list of user group ids
             # get list of user group ids
             user_groups = [gr.id for gr in user.groups]
             user_groups = [gr.id for gr in user.groups]
             # filter forums by user groups
             # filter forums by user groups
@@ -976,7 +976,7 @@ class Category(db.Model, CRUDMixin):
                      forumsread object.
                      forumsread object.
         """
         """
         from flaskbb.user.models import Group
         from flaskbb.user.models import Group
-        if user.is_authenticated():
+        if user.is_authenticated:
             # get list of user group ids
             # get list of user group ids
             user_groups = [gr.id for gr in user.groups]
             user_groups = [gr.id for gr in user.groups]
             # filter forums by user groups
             # filter forums by user groups

+ 1 - 1
flaskbb/forum/views.py

@@ -138,7 +138,7 @@ def view_topic(topic_id, slug=None):
 
 
     # Update the topicsread status if the user hasn't read it
     # Update the topicsread status if the user hasn't read it
     forumsread = None
     forumsread = None
-    if current_user.is_authenticated():
+    if current_user.is_authenticated:
         forumsread = ForumsRead.query.\
         forumsread = ForumsRead.query.\
             filter_by(user_id=current_user.id,
             filter_by(user_id=current_user.id,
                       forum_id=topic.forum.id).first()
                       forum_id=topic.forum.id).first()

+ 0 - 1
flaskbb/templates/forum/new_post.html

@@ -22,7 +22,6 @@
             </div>
             </div>
 
 
             <div class="panel-body page-body">
             <div class="panel-body page-body">
-                {{ form.hidden_tag() }}
                 <div class="col-md-12 col-sm-12 col-xs-12">
                 <div class="col-md-12 col-sm-12 col-xs-12">
 
 
                     <div class="form-group">
                     <div class="form-group">

+ 1 - 1
flaskbb/templates/forum/search_result.html

@@ -39,7 +39,7 @@
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                     <div class="author-pm">
                     <div class="author-pm">
-                        {% if current_user.is_authenticated() and post.user_id %}
+                        {% if current_user.is_authenticated and post.user_id %}
                         <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                         <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                         {% endif %}
                         {% endif %}
                     </div>
                     </div>

+ 2 - 2
flaskbb/templates/forum/topic.html

@@ -43,7 +43,7 @@
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                     <div class="author-pm">
                     <div class="author-pm">
-                        {% if current_user.is_authenticated() and post.user_id %}
+                        {% if current_user.is_authenticated and post.user_id %}
                         <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                         <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                         {% endif %}
                         {% endif %}
                     </div>
                     </div>
@@ -128,7 +128,7 @@
 
 
                             {% endif %}
                             {% endif %}
 
 
-                            {% if current_user.is_authenticated() %}
+                            {% if current_user.is_authenticated %}
                             <!-- Report post -->
                             <!-- Report post -->
                                 <a href="{{ url_for('forum.report_post', post_id=post.id) }}" onclick="window.open(this.href, 'wio_window','width=500,height=500'); return false;" class="btn btn-icon icon-report" data-toggle="tooltip" data-placement="top" title="Report this post"></a>
                                 <a href="{{ url_for('forum.report_post', post_id=post.id) }}" onclick="window.open(this.href, 'wio_window','width=500,height=500'); return false;" class="btn btn-icon icon-report" data-toggle="tooltip" data-placement="top" title="Report this post"></a>
                             {% endif %}
                             {% endif %}

+ 1 - 1
flaskbb/templates/forum/topic_controls.html

@@ -5,7 +5,7 @@
         </div>
         </div>
     </div> <!-- end span pagination -->
     </div> <!-- end span pagination -->
 
 
-{% if current_user.is_authenticated() %}
+{% if current_user.is_authenticated %}
     <div class="col-md-6 col-sm-6 col-xs-12 controls-col">
     <div class="col-md-6 col-sm-6 col-xs-12 controls-col">
         <div class="pull-right">
         <div class="pull-right">
             {% if current_user|can_moderate(topic.forum) or current_user|delete_topic(topic)%}
             {% if current_user|can_moderate(topic.forum) or current_user|delete_topic(topic)%}

+ 2 - 2
flaskbb/templates/forum/topic_horizontal.html

@@ -54,7 +54,7 @@
                             <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                             <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                             <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                             <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                             <div class="author-pm">
                             <div class="author-pm">
-                                {% if current_user.is_authenticated() and post.user_id %}
+                                {% if current_user.is_authenticated and post.user_id %}
                                 <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                                 <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
                                 {% endif %}
                                 {% endif %}
                             </div>
                             </div>
@@ -133,7 +133,7 @@
 
 
                             {% endif %}
                             {% endif %}
 
 
-                            {% if current_user.is_authenticated() %}
+                            {% if current_user.is_authenticated %}
                             <!-- Report post -->
                             <!-- Report post -->
                                 <a href="{{ url_for('forum.report_post', post_id=post.id) }}" onclick="window.open(this.href, 'wio_window','width=500,height=500'); return false;" class="btn btn-icon icon-report" data-toggle="tooltip" data-placement="top" title="Report this post"></a>
                                 <a href="{{ url_for('forum.report_post', post_id=post.id) }}" onclick="window.open(this.href, 'wio_window','width=500,height=500'); return false;" class="btn btn-icon icon-report" data-toggle="tooltip" data-placement="top" title="Report this post"></a>
                             {% endif %}
                             {% endif %}

+ 1 - 1
flaskbb/templates/layout.html

@@ -80,7 +80,7 @@
                         <!-- navbar right -->
                         <!-- navbar right -->
                         <ul class="nav navbar-nav navbar-right">
                         <ul class="nav navbar-nav navbar-right">
 
 
-                            {% if current_user and current_user.is_authenticated() %}
+                            {% if current_user and current_user.is_authenticated %}
                             <!-- Inbox -->
                             <!-- Inbox -->
                             <li class="dropdown {{ is_active('message.inbox') }}">
                             <li class="dropdown {{ is_active('message.inbox') }}">
                                 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                 <a href="#" class="dropdown-toggle" data-toggle="dropdown">

+ 1 - 1
flaskbb/templates/navigation.html

@@ -23,7 +23,7 @@
                 {{ emit_event("after-last-navigation-element") }}
                 {{ emit_event("after-last-navigation-element") }}
             </ul>
             </ul>
 
 
-        {% if current_user and current_user.is_authenticated() %}
+        {% if current_user and current_user.is_authenticated %}
             <div class="btn-group navbar-btn navbar-right" style="padding-left: 15px; margin-right: -10px">
             <div class="btn-group navbar-btn navbar-right" style="padding-left: 15px; margin-right: -10px">
                 <a class="btn btn-primary" href="{{ url_for('user.profile', username=current_user.username) }}">
                 <a class="btn btn-primary" href="{{ url_for('user.profile', username=current_user.username) }}">
                     <span class="fa fa-user"></span> {{ current_user.username }}
                     <span class="fa fa-user"></span> {{ current_user.username }}

+ 1 - 1
flaskbb/templates/user/profile_layout.html

@@ -42,7 +42,7 @@
                             </div>
                             </div>
 
 
                             <div class="profile-buttons">
                             <div class="profile-buttons">
-                                {% if current_user.is_authenticated() %}
+                                {% if current_user.is_authenticated %}
                                 <a class="btn btn-primary" href="{{url_for('message.new_conversation') }}?to_user={{ user.username }}">
                                 <a class="btn btn-primary" href="{{url_for('message.new_conversation') }}?to_user={{ user.username }}">
                                     {% trans %}Message{% endtrans %}
                                     {% trans %}Message{% endtrans %}
                                 </a>
                                 </a>

+ 6 - 6
flaskbb/utils/helpers.py

@@ -52,7 +52,7 @@ def render_template(template, **context):  # pragma: no cover
     """A helper function that uses the `render_theme_template` function
     """A helper function that uses the `render_theme_template` function
     without needing to edit all the views
     without needing to edit all the views
     """
     """
-    if current_user.is_authenticated() and current_user.theme:
+    if current_user.is_authenticated and current_user.theme:
         theme = current_user.theme
         theme = current_user.theme
     else:
     else:
         theme = session.get('theme', flaskbb_config['DEFAULT_THEME'])
         theme = session.get('theme', flaskbb_config['DEFAULT_THEME'])
@@ -140,7 +140,7 @@ def get_categories_and_forums(query_result, user):
 
 
     forums = []
     forums = []
 
 
-    if user.is_authenticated():
+    if user.is_authenticated:
         for key, value in it:
         for key, value in it:
             forums.append((key, [(item[1], item[2]) for item in value]))
             forums.append((key, [(item[1], item[2]) for item in value]))
     else:
     else:
@@ -167,7 +167,7 @@ def get_forums(query_result, user):
     """
     """
     it = itertools.groupby(query_result, operator.itemgetter(0))
     it = itertools.groupby(query_result, operator.itemgetter(0))
 
 
-    if user.is_authenticated():
+    if user.is_authenticated:
         for key, value in it:
         for key, value in it:
             forums = key, [(item[1], item[2]) for item in value]
             forums = key, [(item[1], item[2]) for item in value]
     else:
     else:
@@ -187,7 +187,7 @@ def forum_is_unread(forum, forumsread, user):
     :param user: The user who should be checked if he has read the forum
     :param user: The user who should be checked if he has read the forum
     """
     """
     # If the user is not signed in, every forum is marked as read
     # If the user is not signed in, every forum is marked as read
-    if not user.is_authenticated():
+    if not user.is_authenticated:
         return False
         return False
 
 
     read_cutoff = datetime.utcnow() - timedelta(
     read_cutoff = datetime.utcnow() - timedelta(
@@ -234,7 +234,7 @@ def topic_is_unread(topic, topicsread, user, forumsread=None):
                        read, than you will also need to pass an forumsread
                        read, than you will also need to pass an forumsread
                        object.
                        object.
     """
     """
-    if not user.is_authenticated():
+    if not user.is_authenticated:
         return False
         return False
 
 
     read_cutoff = datetime.utcnow() - timedelta(
     read_cutoff = datetime.utcnow() - timedelta(
@@ -365,7 +365,7 @@ def time_since(time):  # pragma: no cover
     delta = time - datetime.utcnow()
     delta = time - datetime.utcnow()
 
 
     locale = "en"
     locale = "en"
-    if current_user.is_authenticated() and current_user.language is not None:
+    if current_user.is_authenticated and current_user.language is not None:
         locale = current_user.language
         locale = current_user.language
 
 
     return format_timedelta(delta, add_direction=True, locale=locale)
     return format_timedelta(delta, add_direction=True, locale=locale)

+ 1 - 1
flaskbb/utils/requirements.py

@@ -27,7 +27,7 @@ class Has(Requirement):
 
 
 class IsAuthed(Requirement):
 class IsAuthed(Requirement):
     def fulfill(self, user, request):
     def fulfill(self, user, request):
-        return user.is_authenticated()
+        return user.is_authenticated
 
 
 
 
 class IsModeratorInForum(IsAuthed):
 class IsModeratorInForum(IsAuthed):