Skip to content

Commit

Permalink
Adding SECURITY_POST_LOGIN_VIEW option (#22)
Browse files Browse the repository at this point in the history
* added SECURITY_POST_LOGIN_VIEW to login_redirect

* removed core.py~

* left in a mistake, sorry
  • Loading branch information
danielhomola authored and wooyek committed May 18, 2016
1 parent 12b6b4b commit b82f78d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/flask_social_blueprint/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@


class SocialBlueprint(Blueprint):
def __init__(self, name, import_name, connection_adapter=None, providers=None, *args, **kwargs):
def __init__(self, name, import_name, connection_adapter=None, providers=None, login_redirect_url='/', *args, **kwargs):
super(SocialBlueprint, self).__init__(name, import_name, *args, **kwargs)
self.connection_adapter = connection_adapter
self.providers = providers or {}
self.login_redirect_url = login_redirect_url

def get_provider(self, provider_name):
provider = self.providers[provider_name]
Expand Down Expand Up @@ -75,7 +76,7 @@ def login_connection(self, connection, profile, provider):

def login_redirect(self, profile, provider):
next_ = session.pop('next', '')
return redirect(next_ or '/')
return redirect(next_ or self.login_redirect_url)

def login_failed_redirect(self, profile, provider):
return redirect("/")
Expand All @@ -84,8 +85,8 @@ def create_connection(self, profile, provider):
return self.connection_adapter.from_profile(current_user, profile)

@classmethod
def create_bp(cls, name, connection_adapter, providers, *args, **kwargs):
bp = cls(name, __name__, connection_adapter, providers, *args, **kwargs)
def create_bp(cls, name, connection_adapter, providers, login_redirect_url, *args, **kwargs):
bp = cls(name, __name__, connection_adapter, providers, login_redirect_url, *args, **kwargs)
bp.route('/login/<provider>', endpoint="login")(bp.authenticate)
bp.route('/callback/<provider>', endpoint="callback")(bp.callback)
return bp
Expand All @@ -105,7 +106,10 @@ def setup_providers(cls, config):
def init_bp(cls, app, connection_adapter, *args, **kwargs):
config = app.config.get("SOCIAL_BLUEPRINT")
providers = cls.setup_providers(config)
bp = cls.create_bp('social', connection_adapter, providers, *args, **kwargs)
login_redirect_url = app.config.get("SECURITY_POST_LOGIN_VIEW")
if login_redirect_url is None:
login_redirect_url = '/'
bp = cls.create_bp('social', connection_adapter, providers, login_redirect_url, *args, **kwargs)
app.register_blueprint(bp)


Expand Down

0 comments on commit b82f78d

Please sign in to comment.