Browse Source

Config updates. You are now able to define the url_prefixes in the config.
If you want to use recaptcha, you can now enable it with RECAPTCHA_ENABLED = True. I will eventually add more captcha later.

sh4nks 11 years ago
parent
commit
f4b86a6c63

+ 10 - 17
flaskbb/app.py

@@ -35,22 +35,10 @@ from flaskbb.utils.helpers import (format_date, time_since, crop_title,
                                    forum_is_unread, topic_is_unread)
                                    forum_is_unread, topic_is_unread)
 
 
 
 
-DEFAULT_BLUEPRINTS = (
-    (forum, "/forum"),
-    (auth, "/auth"),
-    (user, "/user"),
-    (admin, "/admin")
-)
-
-
-def create_app(config=None, blueprints=None):
+def create_app(config=None):
     """
     """
     Creates the app.
     Creates the app.
     """
     """
-
-    if blueprints is None:
-        blueprints = DEFAULT_BLUEPRINTS
-
     # Initialize the app
     # Initialize the app
     app = Flask("flaskbb")
     app = Flask("flaskbb")
 
 
@@ -61,9 +49,7 @@ def create_app(config=None, blueprints=None):
     # try to update the config via the environment variable
     # try to update the config via the environment variable
     app.config.from_envvar("FLASKBB_SETTINGS", silent=True)
     app.config.from_envvar("FLASKBB_SETTINGS", silent=True)
 
 
-    for blueprint, url_prefix in blueprints:
-        app.register_blueprint(blueprint, url_prefix=url_prefix)
-
+    configure_blueprints(app)
     configure_extensions(app)
     configure_extensions(app)
     configure_template_filters(app)
     configure_template_filters(app)
     configure_before_handlers(app)
     configure_before_handlers(app)
@@ -73,6 +59,13 @@ def create_app(config=None, blueprints=None):
     return app
     return app
 
 
 
 
+def configure_blueprints(app):
+    app.register_blueprint(forum, url_prefix=app.config["FORUM_URL_PREFIX"])
+    app.register_blueprint(user, url_prefix=app.config["USER_URL_PREFIX"])
+    app.register_blueprint(auth, url_prefix=app.config["AUTH_URL_PREFIX"])
+    app.register_blueprint(admin, url_prefix=app.config["ADMIN_URL_PREFIX"])
+
+
 def configure_extensions(app):
 def configure_extensions(app):
     """
     """
     Configures the extensions
     Configures the extensions
@@ -157,7 +150,7 @@ def configure_before_handlers(app):
     def get_user_permissions():
     def get_user_permissions():
         current_user.permissions = current_user.get_permissions()
         current_user.permissions = current_user.get_permissions()
 
 
-    if app.config["USE_REDIS"]:
+    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():

+ 5 - 1
flaskbb/auth/forms.py

@@ -10,7 +10,7 @@
 """
 """
 from datetime import datetime
 from datetime import datetime
 
 
-from flask.ext.wtf import Form
+from flask.ext.wtf import Form, RecaptchaField
 from wtforms import TextField, PasswordField, BooleanField, HiddenField
 from wtforms import TextField, PasswordField, BooleanField, HiddenField
 from wtforms.validators import Required, Email, EqualTo, regexp, ValidationError
 from wtforms.validators import Required, Email, EqualTo, regexp, ValidationError
 
 
@@ -68,6 +68,10 @@ class RegisterForm(Form):
         return user.save()
         return user.save()
 
 
 
 
+class RegisterRecaptchaForm(RegisterForm):
+    recaptcha = RecaptchaField("Captcha")
+
+
 class ReauthForm(Form):
 class ReauthForm(Form):
     password = PasswordField('Password', [Required()])
     password = PasswordField('Password', [Required()])
 
 

+ 10 - 4
flaskbb/auth/views.py

@@ -10,12 +10,12 @@
     :license: BSD, see LICENSE for more details.
     :license: BSD, see LICENSE for more details.
 """
 """
 from flask import (Blueprint, flash, redirect, render_template,
 from flask import (Blueprint, flash, redirect, render_template,
-                   url_for, request)
+                   url_for, request, current_app)
 from flask.ext.login import (current_user, login_user, login_required,
 from flask.ext.login import (current_user, login_user, login_required,
                              logout_user, confirm_login, login_fresh)
                              logout_user, confirm_login, login_fresh)
 from flaskbb.email import send_reset_token
 from flaskbb.email import send_reset_token
-from flaskbb.auth.forms import (LoginForm, ReauthForm, RegisterForm,
-                                ForgotPasswordForm, ResetPasswordForm)
+from flaskbb.auth.forms import (LoginForm, ReauthForm, ForgotPasswordForm,
+                                ResetPasswordForm)
 from flaskbb.user.models import User
 from flaskbb.user.models import User
 
 
 auth = Blueprint("auth", __name__)
 auth = Blueprint("auth", __name__)
@@ -80,7 +80,13 @@ def register():
     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 = RegisterForm(request.form)
+    if current_app.config["RECAPTCHA_ENABLED"]:
+        from flaskbb.auth.forms import RegisterRecaptchaForm
+        form = RegisterRecaptchaForm(request.form)
+    else:
+        from flaskbb.auth.forms import RegisterForm
+        form = RegisterForm(request.form)
+
     if form.validate_on_submit():
     if form.validate_on_submit():
         user = form.save()
         user = form.save()
         login_user(user)
         login_user(user)

+ 7 - 2
flaskbb/configs/default.py

@@ -59,7 +59,7 @@ class DefaultConfig(object):
     CACHE_DEFAULT_TIMEOUT = 60
     CACHE_DEFAULT_TIMEOUT = 60
 
 
     ## Captcha
     ## Captcha
-    RECAPTCHA_ENABLE = False
+    RECAPTCHA_ENABLED = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_PUBLIC_KEY = "your_public_recaptcha_key"
     RECAPTCHA_PUBLIC_KEY = "your_public_recaptcha_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_recaptcha_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_recaptcha_key"
@@ -91,7 +91,7 @@ class DefaultConfig(object):
     TITLE_LENGTH = 15
     TITLE_LENGTH = 15
 
 
     # This is really handy if you do not have an redis instance like on windows
     # This is really handy if you do not have an redis instance like on windows
-    USE_REDIS = True
+    REDIS_ENABLED = True
     REDIS_HOST = 'localhost'
     REDIS_HOST = 'localhost'
     REDIS_PORT = 6379
     REDIS_PORT = 6379
     REDIS_DB = 0
     REDIS_DB = 0
@@ -99,3 +99,8 @@ class DefaultConfig(object):
     # The days for how long the forum should deal with unread topics
     # The days for how long the forum should deal with unread topics
     # 0 - Disable it
     # 0 - Disable it
     TRACKER_LENGTH = 7
     TRACKER_LENGTH = 7
+
+    FORUM_URL_PREFIX = "/forum"
+    USER_URL_PREFIX = "/user"
+    AUTH_URL_PREFIX = "/auth"
+    ADMIN_URL_PREFIX = "/admin"

+ 1 - 1
flaskbb/configs/development.py.example

@@ -28,7 +28,7 @@ class DevelopmentConfig(DefaultConfig):
     # Recaptcha
     # Recaptcha
     # To get recaptcha, visit the link below:
     # To get recaptcha, visit the link below:
     # https://www.google.com/recaptcha/admin/create
     # https://www.google.com/recaptcha/admin/create
-    RECAPTCHA_ENABLE = False
+    RECAPTCHA_ENABLED = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_PUBLIC_KEY = "your_public_key"
     RECAPTCHA_PUBLIC_KEY = "your_public_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_key"

+ 17 - 1
flaskbb/configs/production.py.example

@@ -41,7 +41,7 @@ class ProductionConfig(DefaultConfig):
     ## Captcha
     ## Captcha
     # To get recaptcha, visit the link below:
     # To get recaptcha, visit the link below:
     # https://www.google.com/recaptcha/admin/create
     # https://www.google.com/recaptcha/admin/create
-    RECAPTCHA_ENABLE = False
+    RECAPTCHA_ENABLED = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_USE_SSL = False
     RECAPTCHA_PUBLIC_KEY = "your_public_recaptcha_key"
     RECAPTCHA_PUBLIC_KEY = "your_public_recaptcha_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_recaptcha_key"
     RECAPTCHA_PRIVATE_KEY = "your_private_recaptcha_key"
@@ -69,6 +69,11 @@ class ProductionConfig(DefaultConfig):
     INFO_LOG = "info.log"
     INFO_LOG = "info.log"
     ERROR_LOG = "error.log"
     ERROR_LOG = "error.log"
 
 
+    # Redis
+    REDIS_ENABLED = True
+    REDIS_HOST = 'localhost'
+    REDIS_PORT = 6379
+    REDIS_DB = 0
 
 
     ## FlaskBB Configs
     ## FlaskBB Configs
     # Pagination
     # Pagination
@@ -85,3 +90,14 @@ class ProductionConfig(DefaultConfig):
     ONLINE_LAST_MINUTES = 15
     ONLINE_LAST_MINUTES = 15
     # The length of the topic title in characters on the index
     # The length of the topic title in characters on the index
     TITLE_LENGTH = 15
     TITLE_LENGTH = 15
+
+    # The days for how long the forum should deal with unread topics
+    # 0 - Disable it
+    TRACKER_LENGTH = 7
+
+    # URL Prefixes. For example if you do not want a prefix for your forum,
+    # you can easily change "FORUM_URL_PREFIX" to "/"
+    FORUM_URL_PREFIX = "/forum"
+    USER_URL_PREFIX = "/user"
+    AUTH_URL_PREFIX = "/auth"
+    ADMIN_URL_PREFIX = "/admin"

+ 1 - 1
flaskbb/forum/views.py

@@ -53,7 +53,7 @@ def index():
     newest_user = User.query.order_by(User.id.desc()).first()
     newest_user = User.query.order_by(User.id.desc()).first()
 
 
     # Check if we use redis or not
     # Check if we use redis or not
-    if not current_app.config["USE_REDIS"]:
+    if not current_app.config["REDIS_ENABLED"]:
         online_users = User.query.filter(User.lastseen >= time_diff()).count()
         online_users = User.query.filter(User.lastseen >= time_diff()).count()
         online_guests = None
         online_guests = None
     else:
     else:

+ 9 - 5
flaskbb/templates/auth/register.html

@@ -2,16 +2,20 @@
 
 
 {% extends "layout.html" %}
 {% extends "layout.html" %}
 {% block content %}
 {% block content %}
-{% import "macros.html" as wtf %}
+{% from "macros.html" import horizontal_field %}
 
 
 <form class="form-horizontal" role="form" method="POST">
 <form class="form-horizontal" role="form" method="POST">
     <h2>Register</h2>
     <h2>Register</h2>
     <hr>
     <hr>
     {{ form.hidden_tag() }}
     {{ form.hidden_tag() }}
-    {{ wtf.horizontal_field(form.username)}}
-    {{ wtf.horizontal_field(form.email)}}
-    {{ wtf.horizontal_field(form.password)}}
-    {{ wtf.horizontal_field(form.confirm_password)}}
+    {{ horizontal_field(form.username)}}
+    {{ horizontal_field(form.email)}}
+    {{ horizontal_field(form.password)}}
+    {{ horizontal_field(form.confirm_password)}}
+
+    {% if config["RECAPTCHA_ENABLED"] %}
+        {{ horizontal_field(form.recaptcha) }}
+    {% endif %}
 
 
     <div class="form-group">
     <div class="form-group">
         <div class="col-lg-offset-2 col-lg-3">
         <div class="col-lg-offset-2 col-lg-3">

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

@@ -1,4 +1,4 @@
-{% set page_title = forum.title ~ " - Forum" %}
+{% set page_title = forum[0].title ~ " - Forum" %}
 {% set active_forum_nav=True %}
 {% set active_forum_nav=True %}
 
 
 {% extends "layout.html" %}
 {% extends "layout.html" %}

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

@@ -98,7 +98,7 @@
             <td>
             <td>
                 Newest registered user: {% if newest_user %}<a href="{{ url_for('user.profile', username=newest_user.username) }}">{{ newest_user.username }}</a>{% else %}No users{% endif %}<br />
                 Newest registered user: {% if newest_user %}<a href="{{ url_for('user.profile', username=newest_user.username) }}">{{ newest_user.username }}</a>{% else %}No users{% endif %}<br />
                 Registered users online: <strong>{{ online_users }}</strong> <br />
                 Registered users online: <strong>{{ online_users }}</strong> <br />
-                {% if config["USE_REDIS"] %}
+                {% if config["REDIS_ENABLED"] %}
                 Guests online: <strong>{{ online_guests }}</strong> <br />
                 Guests online: <strong>{{ online_guests }}</strong> <br />
                 {% endif %}
                 {% endif %}
             </td>
             </td>