Beispiel #1
0
	/**
	 * Does the user authentication.
	 */
	protected function initAuth() {
		// this is a work-around since neither RequestHandler
		// nor RouteHandler are populated right now
		$pathInfo = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
		if (empty($pathInfo) || !preg_match('~^/(ACPCaptcha|Login|Logout)/~', $pathInfo)) {
			if (WCF::getUser()->userID == 0) {
				// build redirect path
				$application = ApplicationHandler::getInstance()->getActiveApplication();
				$path = $application->getPageURL() . 'acp/index.php/Login/' . SID_ARG_1ST;
				
				HeaderUtil::redirect($path);
				exit;
			}
			else {
				// work-around for AJAX-requests within ACP
				if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
					try {
						WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
					}
					catch (PermissionDeniedException $e) {
						throw new AJAXException(self::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString());
					}
				}
				else {
					WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
				}
			}
		}
	}
Beispiel #2
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // set cookies
     if ($this->useCookies == 1) {
         UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($this->user, $this->username, $this->password);
     }
     $oldSessionID = WCF::getSession()->sessionID;
     // change user
     WCF::getSession()->changeUser($this->user);
     // get redirect url
     $this->checkURL();
     $this->saved();
     if (isset($_REQUEST['s']) && $_REQUEST['s'] == $oldSessionID && $oldSessionID != WCF::getSession()->sessionID) {
         // force instant redirect to avoid issues with non-cookie login and the already defined SID_ARG_* constants
         if (preg_match('~[?&]s=[a-f0-9]{40}~i', $this->url)) {
             $this->url = preg_replace('~([?&])s=[a-f0-9]{40}~i', '$1s=' . WCF::getSession()->sessionID, $this->url);
         } else {
             $this->url .= mb_strpos($this->url, '?') === false ? '?' : '&';
             $this->url .= 's=' . WCF::getSession()->sessionID;
         }
         HeaderUtil::redirect($this->url);
         exit;
     }
     // redirect to url
     WCF::getTPL()->assign('__hideUserMenu', true);
     HeaderUtil::delayedRedirect($this->url, WCF::getLanguage()->get('wcf.user.login.redirect'));
     exit;
 }
 public function execute()
 {
     parent::execute();
     $entryEditor = new EntryEditor($this->entry);
     $entryEditor->updateCounters(array('visits' => $this->entry->visits + 1));
     $this->executed();
     HeaderUtil::redirect($this->entry->website);
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     WCF::getSession()->register('disclaimerAccepted', true);
     $this->saved();
     WCF::getSession()->update();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Register'));
     exit;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save the news update
     $this->objectAction = new NewsUpdateAction(array($this->update), 'update', array('data' => array('subject' => $this->subject, 'text' => $this->text)));
     $this->objectAction->executeAction();
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('News', array('application' => 'news', 'object' => $this->news)));
     exit;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save file
     $data = array_merge($this->additionalFields, array('description' => $this->text, 'subject' => $this->subject));
     $this->objectAction = new EntryFileAction(array($this->entryFile), 'update', array('data' => $data));
     $this->objectAction->executeAction();
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Entry', array('application' => 'filebase', 'object' => $this->entry)));
     exit;
 }
Beispiel #7
0
 /**
  * @see	\wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // do logout
     WCF::getSession()->delete();
     $this->executed();
     // forward to index page
     // warning: if doLogout() writes a cookie this is buggy in MS IIS
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Login'));
     exit;
 }
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (WCF::getSession()->getPermission('admin.user.canViewIpAddress')) {
         $this->validSortFields[] = 'ipAddress';
         $this->validSortFields[] = 'userAgent';
     }
     if (!empty($_POST)) {
         HeaderUtil::redirect(LinkHandler::getInstance()->getLink('UsersOnlineList', array(), 'sortField=' . $this->sortField . '&sortOrder=' . $this->sortOrder));
         exit;
     }
 }
 /**
  * @see	wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // mark as trashed
     $this->statementAction = new UserJcoinsStatementAction($this->statementList->objectIDs, 'trashAll');
     $this->statementAction->executeAction();
     $this->statementAction = new UserJcoinsStatementAction(array(), 'create', array('data' => array('reason' => 'wcf.jcoins.summaryOfAccountBalances', 'sum' => WCF::getUser()->jCoinsBalance, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID)));
     $this->statementAction->executeAction();
     $this->executed();
     $url = LinkHandler::getInstance()->getLink('OwnCoinsStatement');
     HeaderUtil::delayedRedirect($url, WCF::getLanguage()->get('wcf.jcoins.statement.successfullsumup'));
     exit;
 }
 /**
  * @see wcf\page\IPage::show()
  */
 public function show()
 {
     // use detailed view if accessing WCF ACP directly
     if (PACKAGE_ID == 1) {
         // base tag is determined on runtime
         $host = RouteHandler::getHost();
         $path = RouteHandler::getPath();
         HeaderUtil::redirect($host . $path . 'index.php/PackageListDetailed/' . SID_ARG_1ST, false);
         exit;
     }
     // enable menu item
     ACPMenu::getInstance()->setActiveMenuItem('wcf.acp.menu.link.package.list');
     parent::show();
 }
 /**
  * @see wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // update session
     WCF::getSession()->register('masterPassword', 1);
     WCF::getSession()->update();
     WCF::getSession()->disableUpdate();
     // forward
     if (empty($this->url)) {
         $this->url = LinkHandler::getInstance()->getLink('Index');
     }
     HeaderUtil::redirect($this->url, false);
     exit;
 }
Beispiel #12
0
 /**
  * @see wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // validate
     if (!WCF::getUser()->userID) {
         throw new IllegalLinkException();
     }
     // do logout
     WCF::getSession()->delete();
     $this->executed();
     // forward to index page
     // warning: if doLogout() writes a cookie this is buggy in MS IIS
     HeaderUtil::redirect('index.php' . SID_ARG_1ST);
     exit;
 }
 /**
  * @see	\wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // reset stylesheets
     StyleHandler::resetStylesheets();
     // delete language cache and compiled templates as well
     LanguageFactory::getInstance()->deleteLanguageCache();
     // get package dirs
     CacheHandler::getInstance()->flushAll();
     $this->executed();
     if (!isset($_POST['noRedirect'])) {
         HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList'));
     }
     exit;
 }
	/**
	 * @see	wcf\system\user\authentication\IUserAuthentication::loginAutomatically()
	 */
	public function loginAutomatically($persistent = false, $userClassname = 'wcf\data\user\User') {
		if (!$persistent) return null;
		
		$user = null;
		if (isset($_COOKIE[COOKIE_PREFIX.'userID']) && isset($_COOKIE[COOKIE_PREFIX.'password'])) {
			if (!($user = $this->getUserAutomatically(intval($_COOKIE[COOKIE_PREFIX.'userID']), $_COOKIE[COOKIE_PREFIX.'password'], $userClassname))) {
				$user = null;
				// reset cookie
				HeaderUtil::setCookie('userID', '');
				HeaderUtil::setCookie('password', '');
			}
		}
		
		return $user;
	}
Beispiel #15
0
 /**
  * Does the user authentication.
  */
 protected function initAuth()
 {
     // this is a work-around since neither RequestHandler
     // nor RouteHandler are populated right now
     $pathInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
     if (empty($pathInfo) || !preg_match('~^/(ACPCaptcha|Login|Logout)/~', $pathInfo)) {
         if (WCF::getUser()->userID == 0) {
             // build redirect path
             $application = ApplicationHandler::getInstance()->getActiveApplication();
             $path = $application->domainName . $application->domainPath . 'acp/index.php/Login/' . SID_ARG_1ST;
             util\HeaderUtil::redirect($path, false);
             exit;
         } else {
             WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
         }
     }
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // generate activation code
     $activationCode = UserRegistrationUtil::getActivationCode();
     // save user
     $this->objectAction = new UserAction(array($this->user), 'update', array('data' => array_merge($this->additionalFields, array('reactivationCode' => $activationCode))));
     $this->objectAction->executeAction();
     // send activation mail
     $messageData = array('username' => $this->user->username, 'userID' => $this->user->userID, 'activationCode' => $activationCode);
     $mail = new Mail(array($this->user->username => $this->user->newEmail), WCF::getLanguage()->getDynamicVariable('wcf.user.changeEmail.needReactivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.changeEmail.needReactivation.mail', $messageData));
     $mail->send();
     $this->saved();
     // forward to index page
     HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable('wcf.user.changeEmail.needReactivation'), 10);
     exit;
 }
Beispiel #17
0
 /**
  * @see	\wcf\action\IAction::execute()
  */
 public function execute()
 {
     AbstractSecureAction::execute();
     // do logout
     WCF::getSession()->delete();
     // remove cookies
     if (isset($_COOKIE[COOKIE_PREFIX . 'userID'])) {
         HeaderUtil::setCookie('userID', 0);
     }
     if (isset($_COOKIE[COOKIE_PREFIX . 'password'])) {
         HeaderUtil::setCookie('password', '');
     }
     $this->executed();
     // forward to index page
     HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->get('wcf.user.logout.redirect'));
     exit;
 }
 /**
  * @see	\wcf\system\session\ACPSessionFactory::init()
  */
 protected function init()
 {
     $usesCookies = true;
     if (isset($_COOKIE[COOKIE_PREFIX . 'cookieHash'])) {
         if ($_COOKIE[COOKIE_PREFIX . 'cookieHash'] != SessionHandler::getInstance()->sessionID) {
             $usesCookies = false;
         }
     } else {
         $usesCookies = false;
     }
     if (!$usesCookies) {
         // cookie support will be enabled upon next request
         HeaderUtil::setCookie('cookieHash', SessionHandler::getInstance()->sessionID);
     } else {
         // enable cookie support
         SessionHandler::getInstance()->enableCookies();
     }
     parent::init();
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save the news update
     $this->objectAction = new EntryUpdateAction(array($this->update), 'update', array('data' => array('subject' => $this->subject, 'message' => $this->text)));
     $this->objectAction->executeAction();
     // set news as new
     if ($this->setEntryAsNew) {
         $sql = "UPDATE    cms" . WCF_N . "_news_entry\n                    SET    time = ?\n                    WHERE    entryID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(TIME_NOW, $this->entryID));
         $sql = "DELETE FROM    wcf" . WCF_N . "_tracked_visit\n                    WHERE        objectTypeID = ?\n                    AND        objectID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(VisitTracker::getInstance()->getObjectTypeID('de.incendium.cms.news.entry'), $this->entryID));
         // reset the user storage data
         UserStorageHandler::getInstance()->resetAll('cmsUnreadNewsEntries');
     }
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('NewsEntry', array('application' => 'cms', 'object' => $this->entry)));
     exit;
 }
 /**
  * @see	\wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!$this->notification->confirmTime) {
         UserNotificationHandler::getInstance()->markAsConfirmedByID($this->notification->notificationID);
     }
     $event = new UserNotificationEvent($this->notification->eventID);
     $objectType = ObjectTypeCache::getInstance()->getObjectType($event->objectTypeID);
     $objects = $objectType->getProcessor()->getObjectsByIDs(array($this->notification->objectID));
     $userProfile = null;
     if ($this->notification->authorID) {
         $userProfile = new UserProfile(new User($this->notification->authorID));
     } else {
         $userProfile = new UserProfile(new User(null, array('userID' => null, 'username' => WCF::getLanguage()->get('wcf.user.guest'))));
     }
     $className = $event->className;
     $notificationEvent = new $className($event);
     $notificationEvent->setObject($this->notification, $objects[$this->notification->objectID], $userProfile, $this->notification->additionalData);
     HeaderUtil::redirect($notificationEvent->getLink());
     exit;
 }
 /**
  * @see wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // delete language cache and compiled templates as well
     LanguageFactory::getInstance()->deleteLanguageCache();
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
     $conditions->add("isApplication = ?", array(1));
     // get package dirs
     $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
         try {
             CacheHandler::getInstance()->clear($packageDir . 'cache', '*.php');
         } catch (SystemException $e) {
         }
     }
     $this->executed();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList'));
     exit;
 }
Beispiel #22
0
 /**
  * @see	\wcf\page\IPage::show()
  */
 public function show()
 {
     // check if active user is logged in
     if ($this->loginRequired && !WCF::getUser()->userID) {
         throw new PermissionDeniedException();
     }
     // check if current request URL matches the canonical URL
     if ($this->canonicalURL && empty($_POST)) {
         $canoncialURL = parse_url(preg_replace('~[?&]s=[a-f0-9]{40}~', '', $this->canonicalURL));
         // use $_SERVER['REQUEST_URI'] because it represents the URL used to access the site and not the internally rewritten one
         // IIS Rewrite-Module has a bug causing the REQUEST_URI to be ISO-encoded
         $requestURI = !empty($_SERVER['UNENCODED_URL']) ? $_SERVER['UNENCODED_URL'] : $_SERVER['REQUEST_URI'];
         $requestURI = preg_replace('~[?&]s=[a-f0-9]{40}~', '', $requestURI);
         if (!StringUtil::isUTF8($requestURI)) {
             $requestURI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $requestURI);
         }
         // some webservers output lower-case encoding (e.g. %c3 instead of %C3)
         $requestURI = preg_replace_callback('~%(?P<encoded>[a-zA-Z0-9]{2})~', function ($matches) {
             return '%' . strtoupper($matches['encoded']);
         }, $requestURI);
         $requestURL = parse_url($requestURI);
         $redirect = false;
         if ($canoncialURL['path'] != $requestURL['path']) {
             $redirect = true;
         } else {
             if (isset($canoncialURL['query'])) {
                 if (!isset($requestURL['query'])) {
                     $redirect = true;
                 } else {
                     parse_str($canoncialURL['query'], $cQueryString);
                     parse_str($requestURL['query'], $rQueryString);
                     foreach ($cQueryString as $key => $value) {
                         if (!isset($rQueryString[$key]) || $rQueryString[$key] != $value) {
                             $redirect = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($redirect) {
             $redirectURL = $this->canonicalURL;
             if (!empty($requestURL['query'])) {
                 $queryString = $requestURL['query'];
                 parse_str($requestURL['query'], $rQueryString);
                 if (!empty($canoncialURL['query'])) {
                     parse_str($canoncialURL['query'], $cQueryString);
                     // clean query string
                     foreach ($cQueryString as $key => $value) {
                         if (isset($rQueryString[$key])) {
                             unset($rQueryString[$key]);
                         }
                     }
                 }
                 // drop route data from query
                 if (!URL_LEGACY_MODE) {
                     foreach ($rQueryString as $key => $value) {
                         if ($value === '') {
                             unset($rQueryString[$key]);
                         }
                     }
                 }
                 if (!empty($rQueryString)) {
                     $redirectURL .= (mb_strpos($redirectURL, '?') === false ? '?' : '&') . http_build_query($rQueryString, '', '&');
                 }
             }
             // force a permanent redirect as recommended by Google
             // https://support.google.com/webmasters/answer/6033086?hl=en#a_note_about_redirects
             @header('HTTP/1.0 301 Moved Permanently');
             HeaderUtil::redirect($redirectURL, false);
             exit;
         }
     }
     // sets the active menu item
     $this->setActiveMenuItem();
     // check modules
     $this->checkModules();
     // check permission
     $this->checkPermissions();
     // read data
     $this->readData();
     // assign variables
     $this->assignVariables();
     // call show event
     EventHandler::getInstance()->fireAction($this, 'show');
     // try to guess template name
     $classParts = explode('\\', get_class($this));
     if (empty($this->templateName)) {
         $className = preg_replace('~(Form|Page)$~', '', array_pop($classParts));
         // check if this an *Edit page and use the add-template instead
         if (substr($className, -4) == 'Edit') {
             $className = substr($className, 0, -4) . 'Add';
         }
         $this->templateName = lcfirst($className);
         // assign guessed template name
         WCF::getTPL()->assign('templateName', $this->templateName);
     }
     if (empty($this->templateNameApplication)) {
         $this->templateNameApplication = array_shift($classParts);
         // assign guessed template application
         WCF::getTPL()->assign('templateNameApplication', $this->templateNameApplication);
     }
     if ($this->useTemplate) {
         // show template
         WCF::getTPL()->display($this->templateName, $this->templateNameApplication);
     }
 }
Beispiel #23
0
 /**
  * logout
  *
  * @return  Boolean  return true when logout success.
  */
 public function logout()
 {
     //ref wcf\action\LogoutAction::execute()
     // do logout
     WCF::getSession()->delete();
     // remove cookies
     if (isset($_COOKIE[COOKIE_PREFIX . 'userID'])) {
         HeaderUtil::setCookie('userID', 0);
     }
     if (isset($_COOKIE[COOKIE_PREFIX . 'password'])) {
         HeaderUtil::setCookie('password', '');
     }
     return true;
 }
 /**
  * @see    \wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save entry
     $data = array_merge($this->additionalFields, array('languageID' => $this->languageID, 'teaser' => $this->teaser, 'subject' => $this->subject, 'message' => $this->text, 'website' => $this->website, 'lastChangeTime' => TIME_NOW));
     $entryData = array('data' => $data, 'categoryIDs' => $this->categoryIDs, 'attachmentHandler' => $this->attachmentHandler);
     if (MODULE_TAGGING) {
         $entryData['tags'] = $this->tags;
     }
     $this->objectAction = new EntryAction(array($this->entry), 'update', $entryData);
     $this->objectAction->executeAction();
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Entry', array('application' => 'linklist', 'object' => $this->entry)));
     exit;
 }
	/**
	 * Opens the package installation queue and
	 * starts the installation, update or uninstallation of the first entry.
	 * 
	 * @param	integer		$parentQueueID
	 * @param	integer		$processNo
	 */
	public static function openQueue($parentQueueID = 0, $processNo = 0) {
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("userID = ?", array(WCF::getUser()->userID));
		$conditions->add("parentQueueID = ?", array($parentQueueID));
		if ($processNo != 0) $conditions->add("processNo = ?", array($processNo));
		$conditions->add("done = ?", array(0));
		
		$sql = "SELECT		*
			FROM		wcf".WCF_N."_package_installation_queue
			".$conditions."
			ORDER BY	queueID ASC";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		$packageInstallation = $statement->fetchArray();
		
		if (!isset($packageInstallation['queueID'])) {
			$url = LinkHandler::getInstance()->getLink('PackageList');
			HeaderUtil::redirect($url);
			exit;
		}
		else {
			$url = LinkHandler::getInstance()->getLink('PackageInstallationConfirm', array(), 'action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID']);
			HeaderUtil::redirect($url);
			exit;
		}
	}
Beispiel #26
0
 /**
  * @see	\wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // user accepted the connection
     if (isset($_GET['code'])) {
         try {
             // fetch access_token
             $request = new HTTPRequest('https://github.com/login/oauth/access_token', array(), array('client_id' => StringUtil::trim(GITHUB_PUBLIC_KEY), 'client_secret' => StringUtil::trim(GITHUB_PRIVATE_KEY), 'code' => $_GET['code']));
             $request->execute();
             $reply = $request->getReply();
             $content = $reply['body'];
         } catch (SystemException $e) {
             // force logging
             $e->getExceptionID();
             throw new IllegalLinkException();
         }
         // validate state, validation of state is executed after fetching the access_token to invalidate 'code'
         if (!isset($_GET['state']) || $_GET['state'] != WCF::getSession()->getVar('__githubInit')) {
             throw new IllegalLinkException();
         }
         WCF::getSession()->unregister('__githubInit');
         parse_str($content, $data);
         // check whether the token is okay
         if (isset($data['error'])) {
             throw new IllegalLinkException();
         }
         // check whether a user is connected to this github account
         $user = $this->getUser($data['access_token']);
         if ($user->userID) {
             // a user is already connected, but we are logged in, break
             if (WCF::getUser()->userID) {
                 throw new NamedUserException(WCF::getLanguage()->get('wcf.user.3rdparty.github.connect.error.inuse'));
             } else {
                 if (UserAuthenticationFactory::getInstance()->getUserAuthentication()->supportsPersistentLogins()) {
                     $password = StringUtil::getRandomID();
                     $userEditor = new UserEditor($user);
                     $userEditor->update(array('password' => $password));
                     // reload user to retrieve salt
                     $user = new User($user->userID);
                     UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $user->username, $password);
                 }
                 WCF::getSession()->changeUser($user);
                 WCF::getSession()->update();
                 HeaderUtil::redirect(LinkHandler::getInstance()->getLink());
             }
         } else {
             try {
                 // fetch userdata
                 $request = new HTTPRequest('https://api.github.com/user?access_token=' . $data['access_token']);
                 $request->execute();
                 $reply = $request->getReply();
                 $userData = JSON::decode(StringUtil::trim($reply['body']));
             } catch (SystemException $e) {
                 // force logging
                 $e->getExceptionID();
                 throw new IllegalLinkException();
             }
             WCF::getSession()->register('__3rdPartyProvider', 'github');
             // save data for connection
             if (WCF::getUser()->userID) {
                 WCF::getSession()->register('__githubUsername', $userData['login']);
                 WCF::getSession()->register('__githubToken', $data['access_token']);
                 HeaderUtil::redirect(LinkHandler::getInstance()->getLink('AccountManagement') . '#3rdParty');
             } else {
                 WCF::getSession()->register('__githubData', $userData);
                 WCF::getSession()->register('__username', $userData['login']);
                 // check whether user has entered a public email
                 if (isset($userData) && isset($userData['email']) && $userData['email'] !== null) {
                     WCF::getSession()->register('__email', $userData['email']);
                 } else {
                     try {
                         $request = new HTTPRequest('https://api.github.com/user/emails?access_token=' . $data['access_token']);
                         $request->execute();
                         $reply = $request->getReply();
                         $emails = JSON::decode(StringUtil::trim($reply['body']));
                         // handle future response as well a current response (see. http://developer.github.com/v3/users/emails/)
                         if (is_string($emails[0])) {
                             $email = $emails[0];
                         } else {
                             $email = $emails[0]['email'];
                             foreach ($emails as $tmp) {
                                 if ($tmp['primary']) {
                                     $email = $tmp['email'];
                                 }
                                 break;
                             }
                         }
                         WCF::getSession()->register('__email', $email);
                     } catch (SystemException $e) {
                     }
                 }
                 WCF::getSession()->register('__githubToken', $data['access_token']);
                 // we assume that bots won't register on github first
                 // thus no need for a captcha
                 if (REGISTER_USE_CAPTCHA) {
                     WCF::getSession()->register('noRegistrationCaptcha', true);
                 }
                 WCF::getSession()->update();
                 HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Register'));
             }
         }
         $this->executed();
         exit;
     }
     // user declined or any other error that may occur
     if (isset($_GET['error'])) {
         throw new NamedUserException(WCF::getLanguage()->get('wcf.user.3rdparty.github.login.error.' . $_GET['error']));
     }
     // start auth by redirecting to github
     $token = StringUtil::getRandomID();
     WCF::getSession()->register('__githubInit', $token);
     HeaderUtil::redirect("https://github.com/login/oauth/authorize?client_id=" . rawurlencode(StringUtil::trim(GITHUB_PUBLIC_KEY)) . "&scope=" . rawurlencode('user:email') . "&state=" . $token);
     $this->executed();
     exit;
 }
Beispiel #27
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $data = array('title' => $this->title, 'pageID' => $this->pageID, 'parentID' => $this->parentID ?: null, 'cssClasses' => $this->cssClasses, 'showOrder' => $this->showOrder, 'position' => $this->position, 'contentData' => $this->contentData, 'contentTypeID' => $this->objectType->objectTypeID);
     $this->objectAction = new ContentAction(array(), 'create', array('data' => $data));
     $returnValues = $this->objectAction->executeAction();
     $contentID = $returnValues['returnValues']->contentID;
     $contentData = $returnValues['returnValues']->contentData;
     $update = array();
     // save polls
     if ($this->objectType->objectType == 'de.codequake.cms.content.type.poll') {
         $pollID = PollManager::getInstance()->save($returnValues['returnValues']->contentID);
         if ($pollID) {
             $contentData['pollID'] = $pollID;
         }
     }
     if (!I18nHandler::getInstance()->isPlainValue('title')) {
         I18nHandler::getInstance()->save('title', 'cms.content.title' . $contentID, 'cms.content', PACKAGE_ID);
         $update['title'] = 'cms.content.title' . $contentID;
     }
     foreach ($this->objectType->getProcessor()->multilingualFields as $field) {
         if (!I18nHandler::getInstance()->isPlainValue($field)) {
             I18nHandler::getInstance()->save($field, 'cms.content.' . $field . $contentID, 'cms.content', PACKAGE_ID);
             $contentData[$field] = 'cms.content.' . $field . $contentID;
         }
     }
     $update['contentData'] = serialize($contentData);
     if (!empty($update)) {
         $editor = new ContentEditor($returnValues['returnValues']);
         $editor->update($update);
     }
     // create revision
     $objectAction = new PageAction(array($this->pageID), 'createRevision', array('action' => 'content.create'));
     $objectAction->executeAction();
     // update search index
     $objectAction = new PageAction(array($returnValues['returnValues']->pageID), 'refreshSearchIndex');
     $objectAction->executeAction();
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('ContentList', array('application' => 'cms', 'pageID' => $this->pageID)));
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // save file
     $data = array_merge($this->additionalFields, array('entryID' => $this->entryID, 'uploadTime' => TIME_NOW, 'subject' => $this->subject, 'description' => $this->text, 'isDisabled' => WCF::getSession()->getPermission('user.filebase.canAddEntryWithoutModeration') ? 0 : 1));
     $fileData = array('data' => $data, 'entry' => $this->entry, 'fileUpload' => $this->fileUpload);
     $this->objectAction = new EntryFileAction(array(), 'create', $fileData);
     $resultValues = $this->objectAction->executeAction();
     $this->saved();
     if ($resultValues['returnValues']->isDisabled) {
         HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink('FilebaseOverview', array('application' => 'filebase')), WCF::getLanguage()->get('filebase.entry.file.moderation.redirect'), 30);
     } else {
         HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Entry', array('application' => 'filebase', 'object' => $this->entry)));
     }
     exit;
 }
 public function save()
 {
     parent::save();
     if ($this->time != '') {
         $dateTime = \DateTime::createFromFormat("Y-m-d H:i", $this->time, WCF::getUser()->getTimeZone());
     }
     $data = array('languageID' => $this->languageID, 'subject' => $this->subject, 'time' => $this->time != '' ? $dateTime->getTimestamp() : TIME_NOW, 'teaser' => $this->teaser, 'message' => $this->text, 'userID' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, 'isDisabled' => $this->time != '' && $dateTime->getTimestamp() > TIME_NOW ? 1 : 0, 'enableBBCodes' => $this->enableBBCodes, 'showSignature' => $this->showSignature, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'imageID' => $this->imageID ?: null, 'lastChangeTime' => TIME_NOW);
     $newsData = array('data' => $data, 'tags' => array(), 'attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs);
     $newsData['tags'] = $this->tags;
     $action = new NewsAction(array(), 'create', $newsData);
     $resultValues = $action->executeAction();
     // save polls
     if (WCF::getSession()->getPermission('user.cms.news.canStartPoll') && MODULE_POLL) {
         $pollID = PollManager::getInstance()->save($resultValues['returnValues']->newsID);
         if ($pollID) {
             $editor = new NewsEditor($resultValues['returnValues']);
             $editor->update(array('pollID' => $pollID));
         }
     }
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('News', array('application' => 'cms', 'object' => $resultValues['returnValues'])));
     exit;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $success = array();
     $updateParameters = array();
     // quit
     if (WCF::getSession()->getPermission('user.profile.canQuit')) {
         if (!WCF::getUser()->quitStarted && $this->quit == 1) {
             $updateParameters['quitStarted'] = TIME_NOW;
             $this->quitStarted = TIME_NOW;
             $success[] = 'wcf.user.quit.success';
         } else {
             if (WCF::getUser()->quitStarted && $this->cancelQuit == 1) {
                 $updateParameters['quitStarted'] = 0;
                 $this->quitStarted = 0;
                 $success[] = 'wcf.user.quit.cancel.success';
             }
         }
     }
     // user name
     if (WCF::getSession()->getPermission('user.profile.canRename') && $this->username != WCF::getUser()->username) {
         if (mb_strtolower($this->username) != mb_strtolower(WCF::getUser()->username)) {
             $updateParameters['lastUsernameChange'] = TIME_NOW;
             $updateParameters['oldUsername'] = WCF::getUser()->username;
         }
         $updateParameters['username'] = $this->username;
         $success[] = 'wcf.user.changeUsername.success';
     }
     // email
     if (WCF::getSession()->getPermission('user.profile.canChangeEmail') && $this->email != WCF::getUser()->email && $this->email != WCF::getUser()->newEmail) {
         if (REGISTER_ACTIVATION_METHOD == 0 || REGISTER_ACTIVATION_METHOD == 2 || mb_strtolower($this->email) == mb_strtolower(WCF::getUser()->email)) {
             // update email
             $updateParameters['email'] = $this->email;
             $success[] = 'wcf.user.changeEmail.success';
         } else {
             if (REGISTER_ACTIVATION_METHOD == 1) {
                 // get reactivation code
                 $activationCode = UserRegistrationUtil::getActivationCode();
                 // save as new email
                 $updateParameters['reactivationCode'] = $activationCode;
                 $updateParameters['newEmail'] = $this->email;
                 $messageData = array('username' => WCF::getUser()->username, 'userID' => WCF::getUser()->userID, 'activationCode' => $activationCode);
                 $mail = new Mail(array(WCF::getUser()->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.changeEmail.needReactivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.changeEmail.needReactivation.mail', $messageData));
                 $mail->send();
                 $success[] = 'wcf.user.changeEmail.needReactivation';
             }
         }
     }
     // password
     if (!WCF::getUser()->authData) {
         if (!empty($this->newPassword) || !empty($this->confirmNewPassword)) {
             $updateParameters['password'] = $this->newPassword;
             $success[] = 'wcf.user.changePassword.success';
         }
     }
     // 3rdParty
     if (GITHUB_PUBLIC_KEY !== '' && GITHUB_PRIVATE_KEY !== '') {
         if ($this->githubConnect && WCF::getSession()->getVar('__githubToken')) {
             $updateParameters['authData'] = 'github:' . WCF::getSession()->getVar('__githubToken');
             $success[] = 'wcf.user.3rdparty.github.connect.success';
             WCF::getSession()->unregister('__githubToken');
             WCF::getSession()->unregister('__githubUsername');
         }
     }
     if ($this->githubDisconnect && StringUtil::startsWith(WCF::getUser()->authData, 'github:')) {
         $updateParameters['authData'] = '';
         $success[] = 'wcf.user.3rdparty.github.disconnect.success';
     }
     if (TWITTER_PUBLIC_KEY !== '' && TWITTER_PRIVATE_KEY !== '') {
         if ($this->twitterConnect && WCF::getSession()->getVar('__twitterData')) {
             $twitterData = WCF::getSession()->getVar('__twitterData');
             $updateParameters['authData'] = 'twitter:' . $twitterData['user_id'];
             $success[] = 'wcf.user.3rdparty.twitter.connect.success';
             WCF::getSession()->unregister('__twitterData');
             WCF::getSession()->unregister('__twitterUsername');
         }
     }
     if ($this->twitterDisconnect && StringUtil::startsWith(WCF::getUser()->authData, 'twitter:')) {
         $updateParameters['authData'] = '';
         $success[] = 'wcf.user.3rdparty.twitter.disconnect.success';
     }
     if (FACEBOOK_PUBLIC_KEY !== '' && FACEBOOK_PRIVATE_KEY !== '') {
         if ($this->facebookConnect && WCF::getSession()->getVar('__facebookData')) {
             $facebookData = WCF::getSession()->getVar('__facebookData');
             $updateParameters['authData'] = 'facebook:' . $facebookData['id'];
             $success[] = 'wcf.user.3rdparty.facebook.connect.success';
             WCF::getSession()->unregister('__facebookData');
             WCF::getSession()->unregister('__facebookUsername');
         }
     }
     if ($this->facebookDisconnect && StringUtil::startsWith(WCF::getUser()->authData, 'facebook:')) {
         $updateParameters['authData'] = '';
         $success[] = 'wcf.user.3rdparty.facebook.disconnect.success';
     }
     if (GOOGLE_PUBLIC_KEY !== '' && GOOGLE_PRIVATE_KEY !== '') {
         if ($this->googleConnect && WCF::getSession()->getVar('__googleData')) {
             $googleData = WCF::getSession()->getVar('__googleData');
             $updateParameters['authData'] = 'google:' . $googleData['id'];
             $success[] = 'wcf.user.3rdparty.google.connect.success';
             WCF::getSession()->unregister('__googleData');
             WCF::getSession()->unregister('__googleUsername');
         }
     }
     if ($this->googleDisconnect && StringUtil::startsWith(WCF::getUser()->authData, 'google:')) {
         $updateParameters['authData'] = '';
         $success[] = 'wcf.user.3rdparty.google.disconnect.success';
     }
     $data = array();
     if (!empty($updateParameters) || !empty($this->additionalFields)) {
         $data['data'] = array_merge($this->additionalFields, $updateParameters);
     }
     $this->objectAction = new UserAction(array(WCF::getUser()), 'update', $data);
     $this->objectAction->executeAction();
     // update cookie
     if (isset($_COOKIE[COOKIE_PREFIX . 'password']) && isset($updateParameters['password'])) {
         // reload user
         $user = new User(WCF::getUser()->userID);
         HeaderUtil::setCookie('password', PasswordUtil::getSaltedHash($updateParameters['password'], $user->password), TIME_NOW + 365 * 24 * 3600);
     }
     $this->saved();
     $success = array_merge($success, WCF::getTPL()->get('success') ?: array());
     // show success message
     WCF::getTPL()->assign('success', $success);
     // reset password
     $this->password = '';
     $this->newPassword = $this->confirmNewPassword = '';
 }