コード例 #1
0
ファイル: Tpl.php プロジェクト: noremac13/website
 public static function flag($code)
 {
     $country = Country::getCountryByCode($code);
     return !empty($country) ? '<i title="' . self::out($country['name']) . '" class="flag flag-' . self::out(strtolower($code)) . '"></i>' : '';
 }
コード例 #2
0
ファイル: ProfileController.php プロジェクト: TonyWoo/website
 /**
  * @Route ("/profile/update")
  * @HttpMethod ({"POST"})
  * @Secure ({"USER"})
  *
  * @param array $params
  * @return string
  * @throws Exception
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Exception
  */
 public function profileSave(array $params)
 {
     // Get user
     $userService = UserService::instance();
     $authenticationService = AuthenticationService::instance();
     $userId = Session::getCredentials()->getUserId();
     $user = $userService->getUserById($userId);
     if (empty($user)) {
         throw new Exception('Invalid user');
     }
     $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : $user['username'];
     $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : $user['email'];
     $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : $user['country'];
     $allowGifting = isset($params['allowGifting']) ? $params['allowGifting'] : $user['allowGifting'];
     $minecraftname = isset($params['minecraftname']) && !empty($params['minecraftname']) ? $params['minecraftname'] : $user['minecraftname'];
     try {
         $authenticationService->validateUsername($username, $user);
         $authenticationService->validateEmail($email, $user);
         if (!empty($country)) {
             $countryArr = Country::getCountryByCode($country);
             if (empty($countryArr)) {
                 throw new Exception('Invalid country');
             }
             $country = $countryArr['alpha-2'];
         }
     } catch (Exception $e) {
         Session::set('modelError', $e->getMessage());
         return 'redirect: /profile';
     }
     // Date for update
     $userData = array('username' => $username, 'country' => $country, 'email' => $email, 'minecraftname' => $minecraftname, 'allowGifting' => $allowGifting);
     // Is the user changing their name?
     if (strcasecmp($username, $user['username']) !== 0) {
         $nameChangeCount = intval($user['nameChangedCount']);
         // have they hit their limit
         if ($nameChangeCount >= Config::$a['profile']['nameChangeLimit']) {
             throw new Exception('You have reached your name change limit');
         } else {
             $userData['nameChangedDate'] = Date::getDateTime('NOW')->format('Y-m-d H:i:s');
             $userData['nameChangedCount'] = $nameChangeCount + 1;
         }
     }
     try {
         // Update user
         $userService->updateUser($user['userId'], $userData);
     } catch (\Doctrine\DBAL\DBALException $e) {
         // get PDO exception, extract info
         $info = $e->getPrevious()->errorInfo;
         // a unique key constraint failure
         if ($info[0] === "23000") {
             // extract key name
             if (!preg_match("/^Duplicate entry '.+' for key '(.+)'\$/iu", $info[2], $match)) {
                 throw $e;
             }
             // WELL F**K I GUESS ITS NOT MYSQL
             $key = $match[1];
             $keyToField = array('minecraftname' => '"Minecraft name"');
             throw new Exception('Duplicate value for ' . $keyToField[$key]);
         }
     }
     $authenticationService->flagUserForUpdate($user['userId']);
     Session::set('modelSuccess', 'Your profile has been updated');
     return 'redirect: /profile';
 }
コード例 #3
0
 /**
  * @Route ("/admin/user/{id}/edit")
  * @Secure ({"ADMIN"})
  * @HttpMethod ({"POST"})
  * @Transactional
  *
  * @param array $params         
  * @param ViewModel $model          
  * @throws Exception
  * @return string
  */
 public function adminUserEditProcess(array $params, ViewModel $model)
 {
     $model->title = 'User';
     FilterParams::required($params, 'id');
     $authService = AuthenticationService::instance();
     $userService = UserService::instance();
     $userFeatureService = UserFeaturesService::instance();
     $user = $userService->getUserById($params['id']);
     if (empty($user)) {
         throw new Exception('User was not found');
     }
     $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : $user['username'];
     $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : $user['email'];
     $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : $user['country'];
     $allowGifting = isset($params['allowGifting']) ? $params['allowGifting'] : $user['allowGifting'];
     $authService->validateUsername($username, $user);
     $authService->validateEmail($email, $user);
     if (!empty($country)) {
         $countryArr = Country::getCountryByCode($country);
         if (empty($countryArr)) {
             throw new Exception('Invalid country');
         }
         $country = $countryArr['alpha-2'];
     }
     // Data for update
     $userData = array('username' => $username, 'country' => $country, 'email' => $email, 'allowGifting' => $allowGifting);
     $userService->updateUser($user['userId'], $userData);
     $user = $userService->getUserById($params['id']);
     // Features
     if (!isset($params['features'])) {
         $params['features'] = array();
     }
     // Roles
     if (!isset($params['roles'])) {
         $params['roles'] = array();
     }
     $userFeatureService->setUserFeatures($user['userId'], $params['features']);
     $userService->setUserRoles($user['userId'], $params['roles']);
     $authService->flagUserForUpdate($user['userId']);
     Session::set('modelSuccess', 'User profile updated');
     return 'redirect: /admin/user/' . $user['userId'] . '/edit';
 }
コード例 #4
0
ファイル: profile.php プロジェクト: Alewex/website
                <label>City:</label>
                <input class="form-control" type="text" name="city" value="<?=Tpl::out($model->address['city'])?>" placeholder="City" />
              </div>
              <div class="form-group">
                <label>State/Province/Region:</label>
                <input class="form-control" type="text" name="region" value="<?=Tpl::out($model->address['region'])?>" placeholder="Region" />
              </div>
              <div class="form-group">
                <label>ZIP/Postal Code:</label>
                <input class="form-control" type="text" name="zip" value="<?=Tpl::out($model->address['zip'])?>" placeholder="Zip/Postal Code" />
              </div>
              <div class="form-group">
                <label>Country:</label> 
                <select class="form-control" name="country">
                  <option value="">Select your country</option>
                  <?$countries = Country::getCountries();?>
                  <option value="">&nbsp;</option>
                  <option value="US" <?if($model->address['country'] == 'US'):?>
                    selected="selected" <?endif;?>>United States</option>
                  <option value="GB" <?if($model->address['country'] == 'GB'):?>
                    selected="selected" <?endif;?>>United Kingdom</option>
                  <option value="">&nbsp;</option>
                  <?foreach($countries as $country):?>
                  <option value="<?=$country['alpha-2']?>"<?if($model->address['country'] != 'US' && $model->address['country'] != 'GB' && $model->address['country'] == $country['alpha-2']):?>selected="selected" <?endif;?>><?=Tpl::out($country['name'])?></option>
                  <?endforeach;?>
                </select>
              </div>
            </div>

            <div class="form-actions block-foot">
              <button class="btn btn-lg btn-primary" type="submit">Save address</button>
コード例 #5
0
 /**
  * @Route ("/register")
  * @HttpMethod ({"POST"})
  * @Transactional
  *
  * Handle the confirmation request
  * @param array $params
  * @throws Exception
  */
 public function registerProcess(array $params, ViewModel $model, Request $request)
 {
     $userService = UserService::instance();
     $authService = AuthenticationService::instance();
     $authCreds = $this->getSessionAuthenticationCredentials($params);
     $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : '';
     $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : '';
     $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : '';
     $rememberme = isset($params['rememberme']) && !empty($params['rememberme']) ? true : false;
     $authCreds->setUsername($username);
     $authCreds->setEmail($email);
     try {
         if (!isset($params['g-recaptcha-response']) || empty($params['g-recaptcha-response'])) {
             throw new Exception('You must solve the recaptcha.');
         }
         $googleRecaptchaHandler = new GoogleRecaptchaHandler();
         $googleRecaptchaHandler->resolve(Config::$a['g-recaptcha']['secret'], $params['g-recaptcha-response'], $request->ipAddress());
         $authService->validateUsername($username);
         $authService->validateEmail($email);
         if (!empty($country)) {
             $countryArr = Country::getCountryByCode($country);
             if (empty($countryArr)) {
                 throw new Exception('Invalid country');
             }
             $country = $countryArr['alpha-2'];
         }
         $user = array();
         $user['username'] = $username;
         $user['email'] = $email;
         $user['userStatus'] = 'Active';
         $user['country'] = $country;
         $user['userId'] = $userService->addUser($user);
         $userService->addUserAuthProfile(array('userId' => $user['userId'], 'authProvider' => $authCreds->getAuthProvider(), 'authId' => $authCreds->getAuthId(), 'authCode' => $authCreds->getAuthCode(), 'authDetail' => $authCreds->getAuthDetail()));
         Session::set('authSession');
         $authCredHandler = new AuthenticationRedirectionFilter();
         return $authCredHandler->execute($authCreds);
     } catch (Exception $e) {
         $model->title = 'Register Error';
         $model->username = $username;
         $model->email = $email;
         $model->follow = isset($params['follow']) ? $params['follow'] : '';
         $model->authProvider = $authCreds->getAuthProvider();
         $model->code = $authCreds->getAuthCode();
         $model->error = $e;
         return 'register';
     }
 }
コード例 #6
0
ファイル: ProfileController.php プロジェクト: Alewex/website
 /**
  * @Route ("/profile/update")
  * @HttpMethod ({"POST"})
  * @Secure ({"USER"})
  * @Transactional
  *
  * @param array $params         
  * @param ViewModel $model          
  * @throws Exception
  * @return string
  */
 public function profileSave(array $params, ViewModel $model)
 {
     // Get user
     $userService = UserService::instance();
     $userFeaturesService = UserFeaturesService::instance();
     $subscriptionsService = SubscriptionsService::instance();
     $authenticationService = AuthenticationService::instance();
     $userId = Session::getCredentials()->getUserId();
     $user = $userService->getUserById($userId);
     if (empty($user)) {
         throw new Exception('Invalid user');
     }
     $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : $user['username'];
     $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : $user['email'];
     $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : $user['country'];
     $allowGifting = isset($params['allowGifting']) ? $params['allowGifting'] : $user['allowGifting'];
     try {
         $authenticationService->validateUsername($username, $user);
         $authenticationService->validateEmail($email, $user);
         if (!empty($country)) {
             $countryArr = Country::getCountryByCode($country);
             if (empty($countryArr)) {
                 throw new Exception('Invalid country');
             }
             $country = $countryArr['alpha-2'];
         }
     } catch (Exception $e) {
         Session::set('modelError', $e->getMessage());
         return 'redirect: /profile';
     }
     // Date for update
     $userData = array('username' => $username, 'country' => $country, 'email' => $email, 'allowGifting' => $allowGifting);
     // Is the user changing their name?
     if (strcasecmp($username, $user['username']) !== 0) {
         $nameChangeCount = intval($user['nameChangedCount']);
         // have they hit their limit
         if ($nameChangeCount >= Config::$a['profile']['nameChangeLimit']) {
             throw new Exception('You have reached your name change limit');
         } else {
             $userData['nameChangedDate'] = Date::getDateTime('NOW')->format('Y-m-d H:i:s');
             $userData['nameChangedCount'] = $nameChangeCount + 1;
         }
     }
     // Update user
     $userService->updateUser($user['userId'], $userData);
     $authenticationService->flagUserForUpdate($user['userId']);
     Session::set('modelSuccess', 'Your profile has been updated');
     return 'redirect: /profile';
 }
コード例 #7
0
ファイル: user.php プロジェクト: TonyWoo/website
          </div>
          <div>
            <span class="city"><?php 
    echo Tpl::out($model->address['city']);
    ?>
</span>,
            <span class="region"><?php 
    echo Tpl::out($model->address['region']);
    ?>
</span>,
            <span class="postal-code"><?php 
    echo Tpl::out($model->address['zip']);
    ?>
</span>
            <?php 
    $country = Country::getCountryByCode($model->address['country']);
    if (!empty($country)) {
        ?>
            <br />
            <abbr class="country"><?php 
        echo Tpl::out($country['name']);
        ?>
 <small>(<?php 
        echo Tpl::out($country['alpha-2']);
        ?>
)</small></abbr>
            <?php 
    }
    ?>
          </div>
        </div> 
コード例 #8
0
 /**
  * @Route ("/admin/user/{id}/edit")
  * @Secure ({"ADMIN"})
  * @HttpMethod ({"POST"})
  *
  * @param array $params
  * @param ViewModel $model
  * @return string
  * @throws Exception
  * @throws \Exception
  */
 public function adminUserEditProcess(array $params, ViewModel $model)
 {
     $model->title = 'User';
     FilterParams::required($params, 'id');
     $authService = AuthenticationService::instance();
     $userService = UserService::instance();
     $userFeatureService = UserFeaturesService::instance();
     $user = $userService->getUserById($params['id']);
     if (empty($user)) {
         throw new Exception('User was not found');
     }
     $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : $user['username'];
     $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : $user['email'];
     $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : $user['country'];
     $allowGifting = isset($params['allowGifting']) ? $params['allowGifting'] : $user['allowGifting'];
     $minecraftname = isset($params['minecraftname']) && !empty($params['minecraftname']) ? $params['minecraftname'] : $user['minecraftname'];
     $minecraftuuid = isset($params['minecraftuuid']) && !empty($params['minecraftuuid']) ? $params['minecraftuuid'] : $user['minecraftuuid'];
     $authService->validateEmail($email, $user);
     if (!empty($country)) {
         $countryArr = Country::getCountryByCode($country);
         if (empty($countryArr)) {
             throw new Exception('Invalid country');
         }
         $country = $countryArr['alpha-2'];
     }
     $userData = array('username' => $username, 'country' => $country, 'email' => $email, 'minecraftname' => $minecraftname, 'minecraftuuid' => $minecraftuuid, 'allowGifting' => $allowGifting);
     $log = Application::instance()->getLogger();
     $conn = Application::instance()->getConnection();
     $conn->beginTransaction();
     try {
         $userService->updateUser($user['userId'], $userData);
         $user = $userService->getUserById($params['id']);
         if (!isset($params['features'])) {
             $params['features'] = array();
         }
         if (!isset($params['roles'])) {
             $params['roles'] = array();
         }
         $userFeatureService->setUserFeatures($user['userId'], $params['features']);
         $userService->setUserRoles($user['userId'], $params['roles']);
         $authService->flagUserForUpdate($user['userId']);
         $conn->commit();
     } catch (\Exception $e) {
         $log->critical("Error updating user", $user);
         $conn->rollBack();
         throw $e;
     }
     Session::set('modelSuccess', 'User profile updated');
     return 'redirect: /admin/user/' . $user['userId'] . '/edit';
 }