/** * @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'; }
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>' : ''; }
/** * @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'; }
/** * @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'; } }
/** * @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'; }
</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>
/** * @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'; }