|
@@ -202,6 +202,11 @@ def flaskbb_event_topic_save_after(topic, is_new):
|
|
def flaskbb_event_user_registered(username):
|
|
def flaskbb_event_user_registered(username):
|
|
"""Hook for handling events after a user is registered
|
|
"""Hook for handling events after a user is registered
|
|
|
|
|
|
|
|
+ .. warning::
|
|
|
|
+
|
|
|
|
+ This hook is deprecated in favor of
|
|
|
|
+ :func:`~flaskbb.plugins.spec.flaskbb_registration_post_processor`
|
|
|
|
+
|
|
:param username: The username of the newly registered user.
|
|
:param username: The username of the newly registered user.
|
|
"""
|
|
"""
|
|
|
|
|
|
@@ -223,13 +228,16 @@ def flaskbb_gather_registration_validators():
|
|
raise ValidationError(('username', 'Cannot name user fred'))
|
|
raise ValidationError(('username', 'Cannot name user fred'))
|
|
|
|
|
|
@impl
|
|
@impl
|
|
- def flaskbb_gather_validate_user_registration():
|
|
|
|
- return cannot_be_named_fred
|
|
|
|
|
|
+ def flaskbb_gather_registration_validators():
|
|
|
|
+ return [cannot_be_named_fred]
|
|
|
|
|
|
.. note::
|
|
.. note::
|
|
|
|
|
|
This is implemented as a hook that returns callables since the
|
|
This is implemented as a hook that returns callables since the
|
|
- callables are designed to raise exceptions.
|
|
|
|
|
|
+ callables are designed to raise exceptions that are aggregated to
|
|
|
|
+ form the failure message for the registration response.
|
|
|
|
+
|
|
|
|
+ See Also: :class:`~flaskbb.core.auth.registration.UserValidator`
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
|
|
@@ -239,13 +247,38 @@ def flaskbb_registration_failure_handler(user_info, failures):
|
|
Hook for dealing with user registration failures, receives the info
|
|
Hook for dealing with user registration failures, receives the info
|
|
that user attempted to register with as well as the errors that failed
|
|
that user attempted to register with as well as the errors that failed
|
|
the registration.
|
|
the registration.
|
|
- """
|
|
|
|
|
|
+
|
|
|
|
+ Example::
|
|
|
|
+
|
|
|
|
+ from .utils import fuzz_username
|
|
|
|
+
|
|
|
|
+ def has_already_registered(failures):
|
|
|
|
+ return any(
|
|
|
|
+ attr = "username" and "already registered" in msg
|
|
|
|
+ for (attr, msg) in failures
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def suggest_alternate_usernames(user_info, failures):
|
|
|
|
+ if has_already_registered(failures):
|
|
|
|
+ suggestions = fuzz_username(user_info.username)
|
|
|
|
+ failures.append(("username", "Try: {}".format(suggestions)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @impl
|
|
|
|
+ def flaskbb_registration_failure_handler(user_info, failures):
|
|
|
|
+ suggest_alternate_usernames(user_info, failures)
|
|
|
|
+
|
|
|
|
+ See Also: :class:`~flaskbb.core.auth.registration.RegistrationFailureHandler`
|
|
|
|
+ """ # noqa
|
|
|
|
|
|
|
|
|
|
@spec
|
|
@spec
|
|
def flaskbb_registration_post_processor(user):
|
|
def flaskbb_registration_post_processor(user):
|
|
"""
|
|
"""
|
|
- Hook for handling actions after a user has successfully registered.
|
|
|
|
|
|
+ Hook for handling actions after a user has successfully registered. This
|
|
|
|
+ spec receives the user object after it has been successfully persisted
|
|
|
|
+ to the database.
|
|
|
|
|
|
Example::
|
|
Example::
|
|
|
|
|
|
@@ -255,7 +288,9 @@ def flaskbb_registration_post_processor(user):
|
|
@impl
|
|
@impl
|
|
def flaskbb_registration_post_processor(user):
|
|
def flaskbb_registration_post_processor(user):
|
|
greet_user(user)
|
|
greet_user(user)
|
|
- """
|
|
|
|
|
|
+
|
|
|
|
+ See Also: :class:`~flaskbb.core.auth.registration.RegistrationPostProcessor`
|
|
|
|
+ """ # noqa
|
|
|
|
|
|
|
|
|
|
@spec(firstresult=True)
|
|
@spec(firstresult=True)
|