Skip to content

Commit a24ba73

Browse files
committed
Automatically redirect to requested page after login
1 parent b801be3 commit a24ba73

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

back/app_flask.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def should_be_connected(message):
116116
if request.path.startswith('/api'):
117117
return {'message': 'Authentication failed: '+message}, 401
118118

119-
response = make_response(redirect('/login'))
119+
response = make_response(redirect('/login?'+urllib.parse.urlencode({'dest': request.path})))
120120
unset_jwt_cookies(response)
121121
return response
122122

@@ -307,13 +307,20 @@ def login():
307307
# something other than 'session'
308308
# this sets 1 year in the future, but jwt expiration prevails
309309
app.config['JWT_SESSION_COOKIE'] = False
310+
310311
token = LoginAPI.authenticate(
311312
form['login'],
312313
form['password'],
313314
expires
314315
)
316+
317+
requestedPage = '/'
318+
referrerParams = urllib.parse.parse_qs(urllib.parse.urlparse(request.referrer).query)
319+
if 'dest' in referrerParams:
320+
requestedPage = referrerParams['dest'][0]
321+
315322
if token not in [None, 'expired']:
316-
response = make_response(redirect('/'))
323+
response = make_response(redirect(requestedPage))
317324
set_access_cookies(response, token)
318325
return response
319326
else:
@@ -322,7 +329,7 @@ def login():
322329
default_theme=settings.default_theme), 401
323330
elif get_jwt_identity() is not None:
324331
# Already connected
325-
return redirect('/')
332+
return redirect(requestedPage)
326333
# GET
327334
return render_template('login.html', **lang,
328335
default_theme=settings.default_theme)

front/src/event_comments.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function loadComments (event: CurrentEvent): void
2323
};
2424
var event_comment_avatar = id("event_comment_avatar");
2525
Object.keys(attributes).forEach(attr =>
26-
event_comment_avatar.setAttribute(attr, (attributes[attr] as string|number).toString()));
26+
event_comment_avatar.setAttribute(attr, (attributes[attr as keyof typeof attributes] as string|number).toString()));
2727

2828
var event_comments = id('event_comments');
2929
event_comments.innerHTML = '<div class="spinner-border m-auto" role="status"></div>';
@@ -39,7 +39,7 @@ export default function loadComments (event: CurrentEvent): void
3939
},
4040
function (type: string, ex: XMLHttpRequest)
4141
{
42-
CheckAuthentication(ex);
42+
CheckAuthentication(ex, event.event_id);
4343

4444
event_comments.innerHTML = ''; // Remove spinner
4545
console.error(type, ex.responseText);
@@ -51,11 +51,11 @@ export default function loadComments (event: CurrentEvent): void
5151
});
5252
}
5353

54-
function CheckAuthentication (ex: XMLHttpRequest)
54+
function CheckAuthentication (ex: XMLHttpRequest, event_id: number)
5555
{
5656
if (ex.status === 401)
5757
{
58-
window.location.assign('/login');
58+
window.location.assign('/login?dest='+encodeURIComponent('/event:'+event_id));
5959
}
6060
}
6161

@@ -306,7 +306,7 @@ function registerToEvent (event_id: number, interest: number, button_id: string,
306306
},
307307
function (type: string, ex: XMLHttpRequest)
308308
{
309-
CheckAuthentication(ex);
309+
CheckAuthentication(ex, event_id);
310310
console.error(type, ex);
311311
});
312312
}
@@ -320,7 +320,7 @@ function unregisterFromEvent (event_id: number, button_id: string, container: HT
320320
},
321321
function (type: string, ex: XMLHttpRequest)
322322
{
323-
CheckAuthentication(ex);
323+
CheckAuthentication(ex, event_id);
324324
console.error(type, ex);
325325
});
326326
}

front/src/event_plan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function planAnEvent (start_date: Date, end_date: Date, editedEvent?: Eve
104104
{
105105
if (!get_connected_user())
106106
{
107-
window.location.assign('/login');
107+
window.location.assign('/login'); // ?dest='+encodeURIComponent('/event:new') potential bad date thus commented out
108108
return;
109109
}
110110

@@ -333,7 +333,7 @@ function SubmitEvent (onCreate: (event: EventInput) => void)
333333
{
334334
if (ex.status === 401)
335335
{
336-
window.location.assign('/login');
336+
window.location.assign('/login'); // ?dest='+encodeURIComponent('/event:new') potential bad date thus commented out
337337
}
338338
else if (ex.status === 400)
339339
{

front/src/event_show.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function showEvent (calEvent: EventApi): void
114114
var connected_user: ConnectedUser = get_connected_user();
115115
if (!connected_user)
116116
{
117-
window.location.assign('/login');
117+
window.location.assign('/login?dest='+encodeURIComponent('/event:'+calEvent.id));
118118
return;
119119
}
120120

@@ -505,7 +505,7 @@ function SubmitComment ()
505505
{
506506
if (ex.status === 401)
507507
{
508-
window.location.assign('/login');
508+
window.location.assign('/login?dest='+encodeURIComponent('/event:'+current_event.event_id));
509509
}
510510
console.error(type, ex.responseText)
511511
comment_post_error.innerHTML = i18n('Unable to save');

last_release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* Fix previous_role
1+
* Automatically redirect to requested page after login

0 commit comments

Comments
 (0)