コード例 #1
0
ファイル: HomeController.php プロジェクト: usragung/E-Vote
 public function pick(Request $request)
 {
     $auth = Auth::user();
     if ($this->checkVoteStatus($auth->username)->isEmpty() && $request->candidate_id != null) {
         $vote = new Votes();
         $vote->username = $auth->username;
         $vote->candidate_id = $request->input('candidate_id');
         if ($vote->save()) {
             return Response::json(["message" => 'Data telah tersimpan, terima kasih atas partisipasi yang dilakukan']);
         } else {
             return Response::json(["message" => 'Terjadi kesalahan saat melakukan pemilihan kandidat, silahkan dicoba kembali']);
         }
     }
     return Response::json(["message" => 'Anda tidak memiliki hak karena telah melakukan vote sebelumnya']);
 }
コード例 #2
0
 public function store(Request $request)
 {
     if (!($count = $this->redis->get(COUNTER_KEY))) {
         $count = Votes::count();
     }
     $vote = new Votes();
     $vote->ip_address = $request->getClientIp();
     if ($vote->save()) {
         $count = (int) $count + 1;
         $this->redis->set(COUNTER_KEY, $count);
     }
     // Set session
     session(['voted' => true]);
     $total = str_pad($count, 6, 0, STR_PAD_LEFT);
     echo $total;
 }
コード例 #3
0
ファイル: Page.php プロジェクト: alex4ndru/proiectbitacad
 public function servePetitiiVoteAgainst($id)
 {
     $data = Request::all();
     $citizen = Auth::user()->toArray();
     $where = ['citizenId' => $citizen['id'], 'petitionId' => $id];
     $votedBefore = Citizensvotes::where($where)->get()->first();
     if ($votedBefore === null) {
         //inregistrare vot in lista
         $row = new Votes();
         $row->petitionId = $id;
         $row->voteNo = 1;
         $row->save();
         //marcare citizen ca a votat pe aceasta petitie
         $row = new Citizensvotes();
         $row->citizenId = $citizen['id'];
         $row->petitionId = $id;
         $row->save();
         return redirect('petitii')->with(['userName' => $this->userName, 'logIn' => $this->logIn, 'logOut' => $this->logOut]);
     } else {
         echo "can't vote again !";
     }
 }