Skip to content

Commit 68d9e50

Browse files
committed
Improve 404 page, redirect to paste after authentication when possible.
1 parent 7120a54 commit 68d9e50

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

app/Http/Controllers/PasteController.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use \Input;
1010
use \Hash;
1111
use Session;
12+
use Route;
1213
use Cookie;
1314
use DB;
1415
use \Carbon;
@@ -115,7 +116,10 @@ public function view($link, Request $request){
115116
if ($paste->burnAfter == 0){
116117
if (time() > strtotime($paste->expiration)){
117118
if ($isSameUser) $expiration = "Expired";
118-
else abort('404');
119+
else {
120+
$request->session()->flash("link", $link);
121+
abort('404');
122+
}
119123
}
120124
else $expiration = Carbon\Carbon::parse($paste->expiration)->diffForHumans();
121125
}
@@ -136,12 +140,16 @@ public function view($link, Request $request){
136140
// https://stackoverflow.com/questions/30212390/laravel-middleware-return-variable-to-controller
137141
if ($paste->privacy == "private") {
138142
if($isSameUser) $privacy = __('edpaste.paste.option.privacy.private');
139-
else abort('404');
143+
else {
144+
$request->session()->flash("link", $link);
145+
abort('404');
146+
}
140147
}
141148
elseif ($paste->privacy == "internal"){
142149
if (cas()->isAuthenticated()) {
143150
$privacy = __('edpaste.paste.option.privacy.internal');
144151
} else {
152+
$request->session()->flash("link", $link);
145153
return abort('404');
146154
}
147155
}
@@ -330,4 +338,16 @@ public function raw($link){
330338
}
331339
return response($paste->content, 200)->header('Content-Type', 'text/plain');
332340
}
341+
342+
343+
public function retryAfterAuth(Request $request){
344+
if (!cas()->isAuthenticated()) {
345+
cas()->authenticate();
346+
} else {
347+
$link = session("link", "");
348+
return redirect('/'.$link);
349+
}
350+
}
351+
333352
}
353+

resources/lang/en/edpaste.php

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
'paste.views' => '{1} :count view|[2,*] :count views',
5050
'paste.username' => 'Username',
5151
'password.title' => 'Password',
52+
'paste.notfound' => 'Content may be not found or expired, or access may be denied. Please <a href="/users/dashboard">log-in here</a>',
53+
'button.goto.home' => 'Return to home page',
54+
'button.goto.auth' => 'Try authenticating first',
5255

5356
/* Password prompt page */
5457
'page.title.password.prompt' => 'Password prompt - EdPaste',

resources/lang/fr/edpaste.php

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
'paste.views' => '{1} :count vue|[2,*] :count vues',
5050
'paste.username' => 'Auteur',
5151
'password.title' => 'Mot de passe',
52+
'paste.notfound' => 'Page non trouvée - Le post-it n\'existe pas, a expiré, ou nécessite une authentification.',
53+
'button.goto.home' => 'Retourner à la page d\'accueil',
54+
'button.goto.auth' => 'Essayez en vous authentifiant d\'abord',
5255

5356
/* Password prompt page */
5457
'page.title.password.prompt' => 'Demande de mot de passe - Post-it',

resources/views/errors/404.blade.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
<div class="text-center">
1212
<div class="jumbotron">
1313
<h1><i>Page not found</i></h1>
14-
<p class="lead hidden-xs">Content may be not found or expired, or access may be denied.</p>
14+
<p class="lead hidden-xs">{{ __('edpaste.paste.notfound') }}</p>
1515
<hr class="m-y-2">
16+
@if (cas()->isAuthenticated())
1617
<p class="lead">
17-
<a class="btn btn-danger btn-lg" href="/" role="button">Return To Homepage</a>
18+
<a class="btn btn-danger btn-lg" href="/" role="button">{{ __('edpaste.button.goto.home') }}</a>
1819
</p>
20+
@else
21+
<p class="lead">
22+
<a id="authlink" class="btn btn-danger btn-lg" href="/retryAfterAuth" role="button">{{ __('edpaste.button.goto.auth') }}</a>
23+
</p>
24+
@endif
1925
</div>
2026
</div>
2127
</div>

resources/views/paste/password.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@extends('default')
22

3-
@section('pagetitle') {{ __('edpaste.page.password.prompt') }} @endsection
3+
@section('pagetitle') {{ __('edpaste.page.title.password.prompt') }} @endsection
44

55
@section('navbar')
66
<li class="nav-item"><a href="/" class="nav-link">{{ __('edpaste.menu.home') }}</a></li>
@@ -27,7 +27,7 @@
2727
<input style="display:none" type="password" name="fakepasswordremembered"/>
2828

2929
<div class="form-group @if (isset($wrongPassword)) has-error @endif" id="passwordInput">
30-
<input type="password" class="form-control" name="pastePassword" id="pastePassword" placeholder="{{ __('edpaste.password.prompt') }}" maxlength="40" autofocus="true">
30+
<input type="password" class="form-control" name="pastePassword" id="pastePassword" placeholder="{{ __('edpaste.password.field.placeholder') }}" maxlength="40" autofocus="true">
3131
<button type="submit" id="submit" class="btn @if (isset($wrongPassword)) btn-danger @else btn-outline-success @endif">{{ __('edpaste.password.submit') }}</button>
3232
</div>
3333
</form>

routes/web.php

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
Route::get('/', 'PasteController@index');
1919
Route::post('/', 'PasteController@submit');
20+
Route::get('/retryAfterAuth', 'PasteController@retryAfterAuth');
2021
Route::get('/{link}', 'PasteController@view')->where('link', '[a-zA-Z0-9]+');
2122
Route::post('/{link}', 'PasteController@view')->where('link', '[a-zA-Z0-9]+');
2223
Route::get('/edit/{link}', 'EditPasteController@index')->where('link', '[a-zA-Z0-9]+');

0 commit comments

Comments
 (0)