Skip to content

Commit 8cb0d64

Browse files
committed
feat: customize route after login
1 parent 72ef938 commit 8cb0d64

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ ckanext.vip_portal.extra_allowed_prefixes = /dataset /organization /group /stati
8787
# (optional, default: )
8888
ckanext.vip_portal.extra_allowed_suffixes = .svg .html .css
8989

90+
# Allows to customize the route that the user will get redirected to
91+
# after a successful login. Empty value allow user to be redirected to the page
92+
# requested before displaying login page
93+
# (optional, default: )
94+
ckan.auth.route_after_login = dataset.search
95+
9096
```
9197

9298

ckanext/vip_portal/plugin.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import ckan.plugins as p
77
import ckan.plugins.toolkit as tk
8+
import ckan.lib.helpers as h
89

910
from . import config, utils, interfaces
1011

@@ -79,7 +80,13 @@ def identify(self):
7980
if user:
8081
resp = tk.abort(403, tk._("Not authorized to view this page"))
8182
else:
82-
resp = tk.h.redirect_to(config.login_endpoint())
83+
came_from = None
84+
if tk.config.get("ckan.auth.route_after_login"):
85+
came_from = h.url_for(tk.config.get("ckan.auth.route_after_login"))
86+
resp = tk.h.redirect_to(
87+
config.login_endpoint(),
88+
came_from=came_from or tk.request.path
89+
)
8390

8491
resp.headers.update(
8592
{

0 commit comments

Comments
 (0)