Skip to content

Commit

Permalink
Add 403 login suggestion and redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Mulder committed Feb 2, 2024
1 parent 819614c commit b5a8cfc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 6 additions & 3 deletions modules/login/jsx/loginIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ class Login extends Component {
})
.then((response) => {
if (response.ok) {
response.json().then((data) => {
// success - refresh page and user is logged in.
window.location.href = window.location.origin;
response.json().then(() => {
// Redirect if there is a "redirect" param, refresh the page otherwise
window.location.href = this.props.redirect !== null
? this.props.redirect
: window.location.origin;
});
} else {
response.json().then((data) => {
Expand Down Expand Up @@ -353,6 +355,7 @@ window.addEventListener('load', () => {
defaultRequestFirstName={getParam('firstname', '')}
defaultRequestLastName={getParam('lastname', '')}
defaultRequestEmail={getParam('email', '')}
redirect={getParam('redirect', null)}
module={'login'}
/>
);
Expand Down
9 changes: 8 additions & 1 deletion smarty/templates/403.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<div class="container">
<h2>403: Forbidden</h2>
<h3>{$message}</h3>
<div><a href="{$baseurl}">Go to main page</a> | <a onclick="window.history.back();" href="#">Go back one page</a></div>
<div>
<a href="{$baseurl}">Go to main page</a>
| <a onclick="window.history.back();" href="#">Go back one page</a>
{if $anonymous}
| <a href="/login?redirect={$url}">Try logging in</a>
{/if}
</div>
</div>
5 changes: 5 additions & 0 deletions src/Http/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function __construct(
$lorisInstance = $request->getAttribute('loris');
$user = $request->getAttribute('user') ?? new \LORIS\AnonymousUser();

// Variables used to suggest the user to login and later redirect them if they
// are not authenticated in a 403.
$tpl_data['anonymous'] = $user instanceof \LORIS\AnonymousUser;
$tpl_data['url'] = urlencode($_SERVER['REQUEST_URI']);

// Add a link to the issue tracker as long as a LORIS Instance object
// is present in the request.
if (! $user instanceof \LORIS\AnonymousUser
Expand Down

0 comments on commit b5a8cfc

Please sign in to comment.