Skip to content

Commit

Permalink
chore: Redirect to prev url on login (#1747)
Browse files Browse the repository at this point in the history
* Redirect to prev url on login

* Format

* Add next_url to AuthOIDView

* Revert order of imports

Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
  • Loading branch information
geido and dpgaspar authored Dec 2, 2021
1 parent f726f8a commit e09e629
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions flask_appbuilder/security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from ..views import expose, ModelView, SimpleFormView
from ..widgets import ListWidget, ShowWidget


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -514,7 +513,10 @@ def login(self):
flash(as_unicode(self.invalid_login_message), "warning")
return redirect(self.appbuilder.get_url_for_login)
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
next_url = request.args.get("next", "")
if not next_url:
next_url = self.appbuilder.get_url_for_index
return redirect(next_url)
return self.render_template(
self.login_template, title=self.title, form=form, appbuilder=self.appbuilder
)
Expand All @@ -536,7 +538,10 @@ def login(self):
flash(as_unicode(self.invalid_login_message), "warning")
return redirect(self.appbuilder.get_url_for_login)
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
next_url = request.args.get("next", "")
if not next_url:
next_url = self.appbuilder.get_url_for_index
return redirect(next_url)
return self.render_template(
self.login_template, title=self.title, form=form, appbuilder=self.appbuilder
)
Expand Down Expand Up @@ -584,7 +589,10 @@ def after_login(resp):
session.pop("remember_me", None)

login_user(user, remember=remember_me)
return redirect(self.appbuilder.get_url_for_index)
next_url = request.args.get("next", "")
if not next_url:
next_url = self.appbuilder.get_url_for_index
return redirect(next_url)

return login_handler(self)

Expand Down

0 comments on commit e09e629

Please sign in to comment.