Skip to content

Commit 5d38c18

Browse files
authored
Merge pull request #46 from AlexStack/alex_dev
Add inquiry_verify_str for basic spam check
2 parents 8807491 + 46d2e73 commit 5d38c18

6 files changed

Lines changed: 60 additions & 13 deletions

File tree

src/Helpers/LaravelCmsPluginInquiry.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ public function submitForm(Request $request)
140140
return json_encode($result);
141141
}
142142

143+
// inquiry_verify_str for basic spam check
144+
if (! isset($form_data['inquiry_verify_str']) || ! strpos($form_data['inquiry_verify_str'], '-')) {
145+
$result['success'] = false;
146+
$result['error_message'] = 'Verify inquiry_verify_str failed.';
147+
148+
return json_encode($result);
149+
} else {
150+
$verify_str_ary = explode('-', $form_data['inquiry_verify_str']);
151+
if (3 != count($verify_str_ary) || $verify_str_ary[0] != $form_data['page_id'] || $verify_str_ary[1] < 5 || $verify_str_ary[2] < 4) {
152+
$result['success'] = false;
153+
$result['error_message'] = 'Verify inquiry_verify_str failed! Message too short?';
154+
155+
return json_encode($result);
156+
}
157+
}
158+
143159
$inquiry = new LaravelCmsInquiry();
144160
foreach ($inquiry->fillable as $field) {
145161
if (isset($form_data[$field])) {

src/Repositories/LaravelCmsPageAdminRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function create()
3838
$data['helper'] = $this->helper;
3939
$data['page_tab_blades'] = $this->extraPageTabs();
4040

41-
$this->extraPageTabs('create');
41+
$data['plugins'] = $this->extraPageTabs('create');
4242

4343
return $data;
4444
}

src/Repositories/LaravelCmsPageRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ public function search($slug, $search_type = 'content')
214214

215215
return $query;
216216
})
217+
->orderBy('sort_value', 'desc')
217218
->orderBy('id', 'desc')
218219
->paginate($this->helper->s('template.number_per_search') ?? 24);
219220
} elseif ('tag' == $search_type) {
220221
$data['search_results'] = LaravelCmsPage::when($keyword, function ($query, $keyword) {
221222
return $query->where('tags', 'like', '%"'.trim($keyword).'"%');
222223
})
224+
->orderBy('sort_value', 'desc')
223225
->orderBy('id', 'desc')
224226
->paginate($this->helper->s('template.number_per_search') ?? 20);
225227
}

src/assets/frontend/js/bottom.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function adjustAllLinks() {
1919
// location.href = $(this).attr('href');
2020
// });
2121

22-
$("a").each(function () {
22+
$("a").each(function() {
2323
if (this.href.match("_blank")) {
2424
$(this).attr("target", "_blank");
2525
}
@@ -30,7 +30,33 @@ function submitInquiryForm() {
3030
if (document.querySelector("#laravel-cms-inquiry-form") == null) {
3131
return false;
3232
}
33-
$("#laravel-cms-inquiry-form").submit(function (event) {
33+
34+
// add inquiry_verify_str to prevent low level spam
35+
var inputStartTime = null;
36+
$('#laravel-cms-inquiry-form textarea[name="message"]')
37+
.after(
38+
'<input name="inquiry_verify_str" id="inquiry_verify_str" type="hidden" value="0-0-0" />'
39+
)
40+
.focus(function() {
41+
if (inputStartTime == null) {
42+
inputStartTime = new Date().getTime();
43+
}
44+
})
45+
.keyup(function(event) {
46+
var extra_verify_ary = $("#inquiry_verify_str")
47+
.val()
48+
.split("-");
49+
var spent_time = parseInt(new Date().getTime() - inputStartTime);
50+
$("#inquiry_verify_str").val(
51+
$('#laravel-cms-inquiry-form input[name="page_id"]').val() +
52+
"-" +
53+
(parseInt(extra_verify_ary[1]) + 1) +
54+
"-" +
55+
parseInt((new Date().getTime() - inputStartTime) / 1000)
56+
);
57+
});
58+
59+
$("#laravel-cms-inquiry-form").submit(function(event) {
3460
event.preventDefault();
3561
if (
3662
typeof grecaptcha != "undefined" &&
@@ -55,7 +81,7 @@ function submitInquiryForm() {
5581
cache: false,
5682
processData: false,
5783
dataType: "json",
58-
success: function (data) {
84+
success: function(data) {
5985
//console.log("Submission was successful.");
6086
//console.log(data);
6187
if (data.success) {
@@ -74,7 +100,7 @@ function submitInquiryForm() {
74100
).remove();
75101
}
76102
},
77-
error: function (data) {
103+
error: function(data) {
78104
$("#laravel-cms-inquiry-form .error_message").html(
79105
"Error: " + data.responseJSON.message
80106
);
@@ -88,15 +114,14 @@ function submitInquiryForm() {
88114
//console.log("laravel-cms-inquiry-form : An error occurred.");
89115
//console.log(data);
90116
}
91-
}).done(function (data) {
117+
}).done(function(data) {
92118
// console.log("laravel-cms-inquiry-form submitted");
93119
//console.log(data);
94120
});
95121
});
96122
}
97123

98-
99-
$(function () {
124+
$(function() {
100125
submitInquiryForm();
101126

102127
adjustAllLinks();

src/resources/views/backend/dashboard.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
@else
6666
{{$item->title}}
6767
@endif
68-
</a></li>
68+
</a>
69+
<a class="text-secondary float-right ml-2 " href="{{$helper->url($item)}}" target="_blank"><i
70+
class="fas fa-external-link-square-alt small"></i></a>
71+
</li>
6972
@endforeach
7073
</ul>
7174
</div>

src/tests/Feature/LaravelCmsInquiryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public function test_submitForm()
4242
$inquiry->save();
4343

4444
$form_data = [
45-
'first_name' => 'Name'.rand(0, 999),
46-
'email' => 'email'.rand(0, 999).'@example.com',
47-
'message' => 'Message '.rand(0, 999),
48-
'page_id' => 2,
45+
'first_name' => 'Name'.rand(0, 999),
46+
'email' => 'email'.rand(0, 999).'@example.com',
47+
'message' => 'Message '.rand(0, 999),
48+
'page_id' => 2,
49+
'inquiry_verify_str' => '2-8-9',
4950
];
5051
$request = new \Illuminate\Http\Request($form_data);
5152

0 commit comments

Comments
 (0)