1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-09-19 23:21:47 +02:00

Handle when short URL not exist

- Add setup config for define handle type when short URL not exist
- Add setup config for define default URL if handle short URL not exist
with redirect
This commit is contained in:
Untung Ginardi 2016-09-07 10:25:12 +07:00
parent fbb6568042
commit 5edaf41346
4 changed files with 52 additions and 17 deletions

View File

@ -49,32 +49,30 @@ class LinkController extends Controller {
->first();
if ($link == null) {
return abort(404);
return $this->handleShortUrlNotExist();
}
$link_secret_key = $link->secret_key;
if ($link_secret_key) {
if (!$secret_key) {
// if we do not receieve a secret key
// when we are expecting one, return a 403
return abort(403);
}
else {
if ($link_secret_key != $secret_key) {
// a secret key is provided, but it is incorrect
return abort(403);
}
}
}
if ($link->is_disabled == 1) {
return view('error', [
'message' => 'Sorry, but this link has been disabled by an administrator.'
]);
}
if ($link_secret_key) {
if (!$secret_key) {
// if we do not receieve a secret key
// when we are expecting one, return a 403
return abort(403);
}
else {
if ($link_secret_key != $secret_key) {
// a secret key is provided, but it is incorrect
return abort(403);
}
}
}
$long_url = $link->long_url;
$clicks = intval($link->clicks);
@ -90,4 +88,15 @@ class LinkController extends Controller {
return redirect()->to($long_url);
}
private function handleShortUrlNotExist() {
$urlNotExistHandleType = env('SETTING_REDIRECT_URL_NOT_EXIST');
$urlNotExistRedirect = env('SETTING_NOT_EXIST_REDIRECT');
if (($urlNotExistHandleType == true) && ($urlNotExistRedirect)) {
return redirect()->to($urlNotExistRedirect);
} else {
return abort(404);
}
}
}

View File

@ -102,6 +102,8 @@ class SetupController extends Controller {
// if true, only logged in users can shorten
$st_shorten_permission = $request->input('setting:shorten_permission');
$st_index_redirect = $request->input('setting:index_redirect');
$st_url_not_exist_handle_type = $request->input('setting:url_not_exist_handle');
$st_url_not_found_redirect = $request->input('setting:url_not_exist_redirect');
$st_password_recov = $request->input('setting:password_recovery');
$st_base = $request->input('setting:base');
@ -143,6 +145,8 @@ class SetupController extends Controller {
'POLR_ACCT_ACTIVATION' => $polr_acct_activation,
'ST_SHORTEN_PERMISSION' => $st_shorten_permission,
'ST_INDEX_REDIRECT' => $st_index_redirect,
'ST_URL_NOT_EXIST_HANDLE_TYPE' => $st_url_not_exist_handle_type,
'ST_URL_NOT_EXIST_REDIRECT' => $st_url_not_found_redirect,
'ST_PASSWORD_RECOV' => $st_password_recov,
'MAIL_ENABLED' => $mail_enabled,

View File

@ -58,6 +58,14 @@ SETTING_SHORTEN_PERMISSION={{$ST_SHORTEN_PERMISSION}}
# Polr will redirect logged off users to this URL
SETTING_INDEX_REDIRECT={{$ST_INDEX_REDIRECT}}
# Set value to true if you want to redirect to specified URL
# when requested short URL not exist
SETTING_REDIRECT_URL_NOT_EXIST={{$ST_URL_NOT_EXIST_HANDLE_TYPE}}
# You must set SETTING_NOT_EXIST_REDIRECT if SETTING_REDIRECT_URL_NOT_EXIST is true
# Polr will redirect to this URL if requested URL not exist
SETTING_NOT_EXIST_REDIRECT={{$ST_URL_NOT_EXIST_REDIRECT}}
# Set to true to enable password recovery
SETTING_PASSWORD_RECOV={{$ST_PASSWORD_RECOV}}

View File

@ -77,6 +77,20 @@ Setup
http://yoursite.com/login before you can access the index
page.
</p>
<p>
Short URL not exist handle type :
</p>
<select name='setting:url_not_exist_handle' class='form-control'>
<option value='false' selected='selected'>Show error message (Default)</option>
<option value='true'>Redirect to URL</option>
</select>
<p>
If short URL not exist, redirect to :
<button data-content="This will be used if you handle not exist URL as redirect to URL" type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
</p>
<input type='text' class='form-control' name='setting:url_not_exist_redirect' placeholder='http://your-main-site.com'>
<p>
Default URL Ending Type: