lingthio / Flask-User

Customizable User Authorization & User Management: Register, Confirm, Login, Change username/password, Forgot password and more.
http://flask-user.readthedocs.io/
MIT License
1.06k stars 294 forks source link

Flask-User with sub domains(Blueprint) #197

Open ghost opened 6 years ago

ghost commented 6 years ago

I need to have different login managers for different Blueprints. Blueprint 1 - mysite.com Blueprint 2 - sub.mysite.com

DB and user model same for both.

Currently sub.mysite.com/dashboard protected by @login_required. After login it redirects me to the mysite.com/dashboard.

I'd like to have a different logins to different blueprints. Is there any easy way to handle it? Please, if this question doesn't in the right place, let me know.

P.S. I really liked Flask-User using it for my previous app. Therefor looking for a way to use it with different subdomains, based on Blueprints.

ghost commented 6 years ago

Right now I have next structure:

/myapp
    portal/
        templates/
        static/
        __init__.py
        views.py
    site/
        templates/
        static/
        __init__.py
        views.py
    __init__.py
    config.py
run.py

What I was thinking is to have two different app is one of the ways, but I can't go this way for now.

The problem is that user_manager= UserManager(db_adapter,app) is specified for the whole App.

lingthio commented 6 years ago

If I understand you correctly:

Flask-User allows a 'next' query parameter to be specified in the login URL. The login button of one website could be: /users/sign-in?next=http://mysite.com/ and the login button of the other website could be: /users/sign-in?next=http://sub.mysite.com/

Since you're allowing TWO hostnames in the 'next' parameter, you will have to specify a custom 'make_safe_url()' function. The default implementation will strip off the hostname. You'll need to write one that accepts 'mysite.com' and 'sub.mysite.com' (but not anything else -- for safety reasons).

Ling