Пример #1
0
 public function loginUser()
 {
     try {
         $min_data = ['email', 'password'];
         $form = $this->getApp()->request()->post();
         foreach ($min_data as $required_field) {
             if (!isset($form[$required_field])) {
                 throw new \Exception("Missing required field " . $required_field . ". Required fields are " . implode(",", $min_data));
             }
         }
         $email = $form["email"];
         //-- In order to check the user password we need to retrieve the row by email and compare encoded passwords
         $user_auth = UserAuth::getByUserName($email);
         if (is_null($user_auth)) {
             throw new \Exception("No user with that email address");
         }
         //-- Ok, we have the user_auth info, lets check the password
         $salt = $user_auth->getSalt();
         $salt = base64_decode($salt);
         $password = $form["password"] . $salt;
         if (sha1($password) != $user_auth->getPassword()) {
             throw new \Exception("Wrong password");
         }
         $user_auth->setLastSuccessfulLogin(Utilities::now());
         $user_auth->persist();
         $token_info = ["user_id" => $user_auth->getUserId(), "user_name" => $user_auth->getUserName(), "created" => Utilities::now(), "env_secret" => _TOKEN_SECRET];
         $token = Utilities::generate_signed_request($token_info, _ENCODING_SECRET);
         $response_data = $user_auth->toArray();
         $response_data["token"] = $token;
         $this->getApp()->render(200, ['data' => $response_data]);
     } catch (\Exception $e) {
         $this->getApp()->render(200, ['error' => $e->getMessage()]);
     }
 }
Пример #2
0
 public function getUserInfoFromToken($user_token)
 {
     $token_info = Utilities::parse_signed_request($user_token, _ENCODING_SECRET);
     if (is_null($token_info)) {
         throw new \Exception("Invalid token");
     }
     //-- TODO:: Token expiration?
     $user_id = $token_info["user_id"];
     $user_info = User::getByUserId($user_id);
     return $user_info;
 }
Пример #3
0
 private function buildMatchAndTeamsResponse(Match $match)
 {
     if (is_null($this->match_logic)) {
         $this->match_logic = new MatchLogic();
     }
     $match_id = $match->getMatchId();
     //-- Build Response. Get current Match and check if we have teams
     $current_teams = $this->match_logic->getMatchTeams($match_id);
     $current_match = $match->toArray();
     MatchUtilities::addMoreInfoToMatch($current_match);
     $api_response = ["match" => $current_match];
     //-- Fetch Players In teams Again from DB TODO:: Maybe we can skip this db query with what we have in memory
     $all_players = $this->match_logic->getAllMatchPlayers($match_id);
     $players_in_teams = Utilities::getPlayersInTeams($all_players);
     if (count($current_teams) > 0) {
         foreach ($current_teams as $team) {
             $match_team_id = intval($team['match_team_id']);
             $api_response["teams"][$match_team_id] = array_merge($team, ["players" => $players_in_teams[$match_team_id]]);
         }
     } else {
         $api_response["players"] = $all_players;
     }
     return $api_response;
 }
Пример #4
0
 public function sendCurrentMatchEmail(Match $match)
 {
     $match_players = $this->getAllMatchPlayers($match->getMatchId());
     $match_info = $match->toArray();
     MatchUtilities::addMoreInfoToMatch($match_info);
     $render_data = [];
     $render_data["match_day"] = Utilities::SpanishDate(strtotime($match_info["match_date_time"]));
     $render_data["venue_name"] = $match_info["venue"]["venue_name"];
     foreach ($match_players as $mp) {
         $render_data["players"][] = ["row_id" => $mp["row_id"], "nickname" => $mp["nickname"]];
     }
     $me = new \Mustache_Engine();
     $email_body = $me->render(file_get_contents(_APP_PATH . '/email_templates/convocatoria.html'), $render_data);
 }