Esempio n. 1
0
 public function postVote(Request $request, $id)
 {
     $vote = Vote::find($id);
     if (!$vote->is_active) {
         return redirect('/');
     } else {
         $voted = Voter::where('vote_id', '=', $id)->where('ip', '=', sprintf('%u', ip2long($request->ip())))->count();
         if ($voted) {
             return redirect('auth/logout');
         }
     }
     $inputs = $request->all();
     $voter = new Voter();
     $voter->ip = $request->ip();
     $voter->name = trim($inputs['name']);
     $voter->department = trim($inputs['department']);
     $voter->mobile = str_replace(' ', '', $inputs['mobile']);
     $voter->type_id = $inputs['type'];
     $voter->vote_id = $id;
     if ($voter->save()) {
         Voter::find($voter->id)->nominations()->sync($inputs['vote']);
         return redirect('vote/statistics/' . $id)->with('status', '投票保存成功');
     } else {
         return back()->withErrors('投票保存失败');
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('voters')->delete();
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 100; $i++) {
         Voter::create(['first_name' => $faker->firstName, 'middle_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->email, 'contact_number' => $faker->phoneNumber, 'batch_number' => rand(1, 12)]);
     }
 }
 public function vote(VoteOnPoll $request)
 {
     $poll = Option::findOrFail($request->input('option.0'))->poll;
     foreach ($request->input('option') as $option) {
         Option::findOrFail($option)->increment('votes');
     }
     if ($poll->ip_checking == 1) {
         $voter = Voter::create(['poll_id' => $poll->id, 'ip_address' => $request->ip()]);
     }
     session()->flash('flash_message', ['title' => 'Success!', 'message' => 'Your vote has been counted.', 'type' => 'success']);
     return redirect('poll/' . $poll->slug . '/result');
 }
 public function resendBallot($id)
 {
     $voter = Voter::find($id);
     if ($voter->voted == true) {
         return Redirect::to('/dashboard/voter')->with('message', 'User already voted. Cannot resend ballot');
     }
     $voter->key->delete();
     $key = Key::createKey($voter);
     //$this->sendEmail($voter->email,"Hello, ".$voter->first_name. ', http://election.yesalumnibd.org/ballot?key='.$key->key);
     $this->sendEmail($voter->email, "Dear YES Alumni,\n\n        \nHope you are well. This is your official email for voting. The link below has been uniquely generated in your name; so you can only vote once. Click on the URL, and you will be directed to the ballot page where you can cast your vote.\n        \nPlease note that the voting system will ONLY be active from 12:00AM to 11:59PM of Tuesday, 26 July, 2016. You must cast your vote within this time window.\n        \nAfter you have submitted your votes, you will be lead to an end page - that is the confirmation of your vote. If you face any problems during voting, please contact me at the given information below; the necessary actions will be taken.\n        \nThe results will be published after 5:00PM on Wednesday, 27 July, 2016.\n\n" . 'The ballot link: http://election.yesalumnibd.org/ballot?key=' . $key->key . "\n\n        \nThis event marks a great significance in the practice of democracy for the YES Alumni association in Bangladesh. Wishing you and the association all the very best!\n\n        \nBest regards,\n\n        \nMuhammad Maruf Ibne Wali\n        \nElection Commissioner\n        \nYES Alumni EC Elections 2016\n        \nPhone: 01716788220\n        \nemail: marufwali@yahoo.com");
     return Redirect::to('/dashboard/voter')->with('message', 'Ballot was resent to ' . $voter->first_name . '. Link: election.yesalumnibd.org/ballot?key=' . $key->key);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //If user hasn't selected any options, carry on to form validation / rejection
     if (!$request->input('option.0')) {
         return $next($request);
     }
     $poll = Option::findOrFail($request->input('option.0'))->poll;
     //if we already have this user's IP stored and linked to the poll they are trying to vote on
     //flash an error and redirect to results.
     if ($poll->ip_checking == 1) {
         if (Voter::where('ip_address', '=', $request->ip())->where('poll_id', '=', $poll->id)->exists()) {
             session()->flash('flash_message_confirm', ['title' => 'Error!', 'message' => 'You have already vote on this poll. Your vote has not been counted.', 'type' => 'error']);
             return redirect('poll/' . $poll->slug . '/result');
         }
     }
     return $next($request);
 }
Esempio n. 6
0
 public function getList($id)
 {
     $voters = Voter::where('vote_id', '=', $id)->orderBy('created_at')->get();
     return view('voter.list', ['title' => '投票者列表', 'voters' => $voters]);
 }
 public function destroy($id)
 {
     $voter = Voter::find($id);
     $voter->delete();
     return Redirect::to('/dashboard/voter')->with('message', 'Voter deleted Successfully.');
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Voter::created(function ($voter) {
         Key::createKey($voter);
     });
 }