Browse Source

Do not allow votes on a closed poll

master
Les De Ridder 4 years ago
parent
commit
8d01a2689d
  1. 18
      app/Http/Controllers/PollController.php
  2. 9
      resources/views/edit_poll.blade.php
  3. 6
      resources/views/view_poll_results.blade.php

18
app/Http/Controllers/PollController.php

@ -72,6 +72,10 @@ class PollController extends Controller
public function view(Request $request, Poll $poll)
{
if($poll->closed) {
return redirect()->action('PollController@viewResults', ['poll' => $poll])->with('alreadyClosed', true);
}
$new = $request->session()->pull('new', false);
if($request->format() == 'json') {
@ -95,12 +99,14 @@ class PollController extends Controller
public function viewResults(Request $request, Poll $poll)
{
$voted = $request->session()->pull('voted', false);
$alreadyClosed = $request->session()->pull('alreadyClosed', false);
$this->createPieChart($poll);
return view('view_poll_results')
->with('poll', $poll)
->with('voted', $voted);
->with('voted', $voted)
->with('alreadyClosed', $alreadyClosed);
}
private static function imageToDataUri($image)
@ -208,6 +214,10 @@ class PollController extends Controller
public function vote(Request $request, Poll $poll)
{
if($poll->closed) {
return redirect()->action('PollController@viewResults', ['poll' => $poll])->with('alreadyClosed', true);
}
if($this->hasVoted($request, $poll)) {
return view('view_poll')
->with('poll', $poll)
@ -255,13 +265,13 @@ class PollController extends Controller
public function admin(Request $request, Poll $poll)
{
$changed = $request->session()->pull('changed', false);
$extraCodes = $request->session()->pull('extra_codes', null);
$extraCodes = $request->session()->pull('extraCodes', null);
if($poll->admin_password == null || $request->query('password') != $poll->admin_password) {
return redirect()->action('PollController@view', ['poll' => $poll]);
}
return view('edit_poll')->with('poll', $poll)->with('changed', $changed)->with('extra_codes', $extraCodes);
return view('edit_poll')->with('poll', $poll)->with('changed', $changed)->with('extraCodes', $extraCodes);
}
public function edit(Request $request, Poll $poll)
@ -279,7 +289,7 @@ class PollController extends Controller
return redirect()
->action('PollController@admin', ['poll' => $poll, 'password' => $poll->admin_password])
->with('extra_codes', $codes);
->with('extraCodes', $codes);
} else {
$request['allow_multiple_answers'] = $request->has('allow_multiple_answers');
$request['hide_results_until_closed'] = $request->has('hide_results_until_closed');

9
resources/views/edit_poll.blade.php

@ -8,16 +8,13 @@
<span>The poll is closed and can no longer be edited.</span>
</div>
@else
@if ($changed || $extra_codes != null)
@php (debug($changed))
@php (debug($extra_codes))
@if ($changed || $extraCodes != null)
<div class="primary-box">
@if ($changed)
<span>Your changes have been saved.</span>
@elseif ($extra_codes != null)
@elseif ($extraCodes != null)
<span>Your extra voting URLs have been generated:</span>
<textarea class="copyarea" readonly>{{collect($extra_codes)->map(function($c) use($poll) { return action('PollController@view', ['poll' => $poll, 'code' => $c]); })->implode("\n")}}</textarea>
<textarea class="copyarea" readonly>{{collect($extraCodes)->map(function($c) use($poll) { return action('PollController@view', ['poll' => $poll, 'code' => $c]); })->implode("\n")}}</textarea>
@endif
</div>

6
resources/views/view_poll_results.blade.php

@ -8,6 +8,12 @@
<span>Your vote has been recorded!</span><br>
</section>
<div class="text-browser"><br></div>
@elseif ($alreadyClosed)
<section class="primary-box">
<span>The poll is already closed.</span><br>
</section>
<div class="text-browser"><br></div>
@endif

Loading…
Cancel
Save