Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register view while logged in #328

Open
najibfahs opened this issue Dec 6, 2020 · 2 comments
Open

register view while logged in #328

najibfahs opened this issue Dec 6, 2020 · 2 comments

Comments

@najibfahs
Copy link

Hello, first time user of Flask-user.
While logged in, I don't expect to have access to the registration view. I but I do. I don't believe it is supposed to work this way.
Just like the log in view is not accessible while logged in, access to the register view must be denied.
So I looked at the code in the login_view function and the following snippet is what prevents access:

Immediately redirect already logged in users

if self.call_or_get(current_user.is_authenticated) and self.USER_AUTO_LOGIN_AT_LOGIN:
return redirect(safe_next_url)

But I dont see this under the register_view.

Or am I missing something?
thanks!

@dometto
Copy link

dometto commented Jan 10, 2021

I second this: this is strange behavior, and there should at least be an option to disable this. Are there any plans to address this?

Thanks for your work on Flask-User!

@Chaostheorie
Copy link

You can in this particular case customize the view, if that's important for you.

Below is an example of using customize and a custom function. It's been a while since I touched flask_user so use this as a reference and don't copy-pasta-it. The code is mostly copied from the source code. Reading it will most likely yield you a similar result.

from flask_user.user_manager import UserManager
from flask import redirect

class CustomUserManager(UserManager):
    def custom_register_view(self):
        """Prepare and process the login form."""
        safe_next_url = self._get_safe_next_url('next', self.USER_AFTER_LOGIN_ENDPOINT)

        # Immediately redirect already logged in users
        if self.call_or_get(current_user.is_authenticated) and self.USER_AUTO_LOGIN_AT_LOGIN:
            return redirect(safe_next_url)

        # run normal register view view
        self.register_view_old()


    def customize(self, app):
        self.register_view_old = self.register_view
        self.register_view = self.custom_register_view

user_manager = CustomUserManager(app, db, User)

The Project is on hiatus (not maintained) since about the start of 2020. I would recommend you to either implement the required parts in flask_login or search for another solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants