示例#1
0
 public function teamsAction()
 {
     $this->checkLogin();
     if ($this->request->isPost() && $this->request->hasPost("type") && $this->security->checkToken()) {
         $this->session->set("changeOccurred", true);
         $this->session->set("changeSuccessful", true);
         $this->session->set("teamsGenerated", false);
         switch ($this->request->getPost("type")) {
             case 'update':
                 $team = Teams::findFirst(intval($this->request->getPost("id")));
                 if ($team) {
                     $team->setUsername($this->request->getPost("user"));
                     if ($this->request->getPost("pass") != "") {
                         $team->setPassword($this->request->getPost("pass"));
                     }
                     $team->save();
                 } else {
                     $this->session->set("changeSuccessful", false);
                 }
                 break;
             case 'create':
                 $team = new Teams();
                 $team->setUsername($this->request->getPost("user"));
                 $team->setPassword($this->request->getPost("pass"));
                 if (!$team->save()) {
                     $this->session->set("changeSuccessful", false);
                 }
                 break;
             case 'generate':
                 $this->session->set("teamsGenerated", true);
                 $num = intval($this->request->getPost("num"));
                 $name = $this->request->getPost("user");
                 $teams = array();
                 $info = "";
                 for ($i = 0; $i < $num; $i++) {
                     $teams[$i] = new Teams();
                     $teams[$i]->setUsername(str_replace("#", $i + 1, $name));
                     $pass = Phalcon\Text::random(Phalcon\Text::RANDOM_ALNUM, 8);
                     $teams[$i]->setPassword($pass);
                     $info .= $teams[$i]->getUsername() . ":" . $pass . ",";
                     if ($teams[$i]->save() == false) {
                         $this->session->set("changeSuccessful", false);
                         $this->session->set("teamsGenerated", false);
                         for ($j = 0; $j <= $i; $j++) {
                             $teams[$j]->delete();
                         }
                         break;
                     }
                 }
                 $info = substr($info, 0, strlen($info) - 1);
                 $this->session->set("generatedInfo", $info);
                 break;
             case 'delete':
                 $team = Teams::findFirst(intval($this->request->getPost("id")));
                 if ($team->delete() == false) {
                     $this->session->set("changeSuccessful", false);
                 }
                 break;
             default:
                 $this->session->set("changeSuccessful", false);
                 break;
         }
         return $this->response->redirect("/admin/teams");
     } else {
         if ($this->session->has("changeOccurred")) {
             $this->view->changeOccurred = $this->session->get("changeOccurred");
             $this->session->remove("changeOccurred");
         }
         if ($this->session->has("changeSuccessful")) {
             $this->view->changeSuccessful = $this->session->get("changeSuccessful");
             $this->session->remove("changeSuccessful");
         }
         if ($this->session->has("teamsGenerated")) {
             $this->view->teamsGenerated = $this->session->get("teamsGenerated");
             $this->session->remove("teamsGenerated");
         }
         if ($this->session->has("generatedInfo")) {
             $genInfo = $this->session->get("generatedInfo");
             $tempArr = explode(",", $genInfo);
             $genTeams = array();
             for ($i = 0; $i < count($tempArr); $i++) {
                 $tempTeam = explode(":", $tempArr[$i]);
                 $genTeams[$i] = array("username" => $tempTeam[0], "password" => $tempTeam[1]);
             }
             $this->view->genTeams = $genTeams;
             //die(print_r($genInfo));
             $this->session->remove("generatedInfo");
         }
     }
     $this->view->teams = Teams::find();
 }
示例#2
0
 public function checkLogin()
 {
     if ($this->request->isPost()) {
         $user = $this->request->getPost("user");
         $pass = $this->request->getPost("pass");
         $team = Teams::findFirst(array("conditions" => "user = :user:"******"bind" => array("user" => $user)));
         if ($team && $this->security->checkHash($pass, $team->getPassword())) {
             $this->session->set("team_user", $user);
             $this->session->set("team_id", $team->getId());
             $this->session->set("team_key", $team->getPassword());
             $this->session->set("team_timeout", time() + $this->timeout);
         } else {
             $this->flashSession->error("This username and password combination is incorrect");
             return $this->response->redirect("");
         }
         $this->response->redirect("/team");
     } else {
         if ($this->session->has("team_user") && $this->session->has("team_user") && $this->session->has("team_timeout") && $this->session->get("team_id")) {
             $user = $this->session->get("team_user");
             $id = $this->session->get("team_id");
             $pass = $this->session->get("team_key");
             $time = $this->session->get("team_timeout");
             if (time() > intval($time)) {
                 $this->session->remove("team_user");
                 $this->session->remove("team_id");
                 $this->session->remove("team_key");
                 $this->session->remove("team_timeout");
                 $this->flashSession->error("Your session has expired. Please sign in again.");
                 return $this->response->redirect("");
             }
             $team = Teams::findFirst(array("conditions" => "user = :user: AND pass = :pass:"******"bind" => array("user" => $user, "pass" => $pass)));
             if ($team) {
                 $this->session->set("team_user", $user);
                 $this->session->set("team_id", $id);
                 $this->session->set("team_key", $pass);
                 $this->session->set("team_timeout", time() + $this->timeout);
             } else {
                 $this->flashSession->error("There was an error, please sign in again");
                 return $this->response->redirect("");
             }
         } else {
             $this->flashSession->error("Please sign in first");
             return $this->response->redirect("");
         }
     }
 }