/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { // check file location if (!@file_exists($additionalData['fileLocation'])) { return 0; } // get image size $imageData = @getimagesize($additionalData['fileLocation']); if ($imageData === false) { return 0; } $data['width'] = $imageData[0]; $data['height'] = $imageData[1]; // check min size if ($data['width'] < 48 || $data['height'] < 48) { return 0; } // check image type if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) { return 0; } // get file hash if (empty($data['fileHash'])) { $data['fileHash'] = sha1_file($additionalData['fileLocation']); } // get user id $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']); if (!$data['userID']) { return 0; } // save avatar $avatar = UserAvatarEditor::create($data); // check avatar directory // and create subdirectory if necessary $dir = dirname($avatar->getLocation()); if (!@file_exists($dir)) { FileUtil::makePath($dir, 0777); } // copy file try { if (!copy($additionalData['fileLocation'], $avatar->getLocation())) { throw new SystemException(); } // create thumbnails $action = new UserAvatarAction(array($avatar), 'generateThumbnails'); $action->executeAction(); // update owner $sql = "UPDATE\twcf" . WCF_N . "_user\n\t\t\t\tSET\tavatarID = ?\n\t\t\t\tWHERE\tuserID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($avatar->avatarID, $data['userID'])); return $avatar->avatarID; } catch (SystemException $e) { // copy failed; delete avatar $editor = new UserAvatarEditor($avatar); $editor->delete(); } return 0; }
/** * @see \wcf\data\IDeleteAction::delete() */ public function delete() { if (empty($this->objects)) { $this->readObjects(); } // delete avatars $avatarIDs = array(); foreach ($this->objects as $user) { if ($user->avatarID) { $avatarIDs[] = $user->avatarID; } } if (!empty($avatarIDs)) { $action = new UserAvatarAction($avatarIDs, 'delete'); $action->executeAction(); } // delete profile comments if (!empty($this->objectIDs)) { CommentHandler::getInstance()->deleteObjects('com.woltlab.wcf.user.profileComment', $this->objectIDs); } $returnValue = parent::delete(); return $returnValue; }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); if ($this->avatarType != 'custom') { // delete custom avatar if (WCF::getUser()->avatarID) { $action = new UserAvatarAction(array(WCF::getUser()->avatarID), 'delete'); $action->executeAction(); } } // update user switch ($this->avatarType) { case 'none': $data = array('avatarID' => null, 'enableGravatar' => 0); break; case 'custom': $data = array('enableGravatar' => 0); break; case 'gravatar': $data = array('avatarID' => null, 'enableGravatar' => 1); break; } $this->objectAction = new UserAction(array(WCF::getUser()), 'update', array('data' => array_merge($this->additionalFields, $data))); $this->objectAction->executeAction(); // check if the user will be automatically added to new user groups // because of the changed avatar UserGroupAssignmentHandler::getInstance()->checkUsers(array(WCF::getUser()->userID)); // reset gravatar cache if ($this->avatarType == 'gravatar') { $pattern = WCF_DIR . sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower(WCF::getUser()->email)), '*', '*'); $files = glob($pattern); if (!empty($files)) { foreach ($files as $file) { @unlink($file); } } } UserProfileHandler::getInstance()->reloadUserProfile(); $this->saved(); WCF::getTPL()->assign('success', true); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // handle avatar if ($this->avatarType != 'custom') { // delete custom avatar if ($this->user->avatarID) { $action = new UserAvatarAction(array($this->user->avatarID), 'delete'); $action->executeAction(); } } switch ($this->avatarType) { case 'none': $avatarData = array('avatarID' => null, 'enableGravatar' => 0); break; case 'custom': $avatarData = array('enableGravatar' => 0); break; case 'gravatar': $avatarData = array('avatarID' => null, 'enableGravatar' => 1); break; } $this->additionalFields = array_merge($this->additionalFields, $avatarData); // add default groups $defaultGroups = UserGroup::getAccessibleGroups(array(UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS)); $oldGroupIDs = $this->user->getGroupIDs(); foreach ($oldGroupIDs as $oldGroupID) { if (isset($defaultGroups[$oldGroupID])) { $this->groupIDs[] = $oldGroupID; } } $this->groupIDs = array_unique($this->groupIDs); // save user $saveOptions = $this->optionHandler->save(); $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password, 'languageID' => $this->languageID, 'userTitle' => $this->userTitle, 'signature' => $this->signature, 'signatureEnableBBCodes' => $this->signatureEnableBBCodes, 'signatureEnableSmilies' => $this->signatureEnableSmilies, 'signatureEnableHtml' => $this->signatureEnableHtml)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions); // handle ban if (WCF::getSession()->getPermission('admin.user.canBanUser')) { if ($this->banExpires) { $this->banExpires = strtotime($this->banExpires); } else { $this->banExpires = 0; } $data['data']['banned'] = $this->banned; $data['data']['banReason'] = $this->banReason; $data['data']['banExpires'] = $this->banExpires; } // handle disabled signature if (WCF::getSession()->getPermission('admin.user.canDisableSignature')) { if ($this->disableSignatureExpires) { $this->disableSignatureExpires = strtotime($this->disableSignatureExpires); } else { $this->disableSignatureExpires = 0; } $data['data']['disableSignature'] = $this->disableSignature; $data['data']['disableSignatureReason'] = $this->disableSignatureReason; $data['data']['disableSignatureExpires'] = $this->disableSignatureExpires; } // handle disabled avatar if (WCF::getSession()->getPermission('admin.user.canDisableAvatar')) { if ($this->disableAvatarExpires) { $this->disableAvatarExpires = strtotime($this->disableAvatarExpires); } else { $this->disableAvatarExpires = 0; } $data['data']['disableAvatar'] = $this->disableAvatar; $data['data']['disableAvatarReason'] = $this->disableAvatarReason; $data['data']['disableAvatarExpires'] = $this->disableAvatarExpires; } $this->objectAction = new UserAction(array($this->userID), 'update', $data); $this->objectAction->executeAction(); // update user rank $editor = new UserEditor(new User($this->userID)); if (MODULE_USER_RANK) { $action = new UserProfileAction(array($editor), 'updateUserRank'); $action->executeAction(); } if (MODULE_USERS_ONLINE) { $action = new UserProfileAction(array($editor), 'updateUserOnlineMarking'); $action->executeAction(); } // remove assignments $sql = "DELETE FROM\twcf" . WCF_N . "_moderation_queue_to_user\n\t\t\tWHERE\t\tuserID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->user->userID)); // reset moderation count ModerationQueueManager::getInstance()->resetModerationCount($this->user->userID); $this->saved(); // reset password $this->password = $this->confirmPassword = ''; // show success message WCF::getTPL()->assign('success', true); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // get options $saveOptions = $this->optionHandler->save(); $registerVia3rdParty = true; $avatarURL = ''; if (isset($this->ttid_profile['avatar_url']) && !empty($this->ttid_profile['avatar_url'])) { $avatarURL = $this->ttid_profile['avatar_url']; } $this->additionalFields['languageID'] = $this->languageID; if (LOG_IP_ADDRESS) { $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress; } // generate activation code $addDefaultGroups = true; if ($this->verified !== true && REGISTER_ACTIVATION_METHOD != 0 || $this->verified === true && REGISTER_ACTIVATION_METHOD == 2 && !WBB_TAPATALK_REG_AUTO_APPROVAL) { $activationCode = UserRegistrationUtil::getActivationCode(); $this->additionalFields['activationCode'] = $activationCode; $addDefaultGroups = false; $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS)); } // check gravatar support if (MODULE_GRAVATAR && Gravatar::test($this->email)) { $this->additionalFields['enableGravatar'] = 1; } // create user $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups); $this->objectAction = new UserAction(array(), 'create', $data); $result = $this->objectAction->executeAction(); $user = $result['returnValues']; $userEditor = new UserEditor($user); // set avatar if provided if (!empty($avatarURL)) { $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor)); $userAvatarAction->executeAction(); } // update session WCF::getSession()->changeUser($user); // activation management if (REGISTER_ACTIVATION_METHOD == 0) { $this->message = 'wcf.user.register.success'; } else { if (REGISTER_ACTIVATION_METHOD == 1) { // registering via 3rdParty leads to instant activation if ($registerVia3rdParty && $this->verified) { $this->message = 'wcf.user.register.success'; } else { $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user))); $mail->send(); $this->message = 'wcf.user.register.needActivation'; } } else { if (REGISTER_ACTIVATION_METHOD == 2 && (!$this->verified || $this->verified && !WBB_TAPATALK_REG_AUTO_APPROVAL)) { $this->message = 'wcf.user.register.awaitActivation'; } } } // notify admin if (REGISTER_ADMIN_NOTIFICATION) { // get default language $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID()); // send mail $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user))); $mail->setLanguage($language); $mail->send(); } if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } if (WCF::getSession()->getVar('noRegistrationCaptcha')) { WCF::getSession()->unregister('noRegistrationCaptcha'); } // login user UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password); WCF::getSession()->unregister('registrationStartTime'); $this->saved(); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // get options $saveOptions = $this->optionHandler->save(); $registerVia3rdParty = false; $avatarURL = ''; if ($this->isExternalAuthentication) { switch (WCF::getSession()->getVar('__3rdPartyProvider')) { case 'github': // GitHub if (WCF::getSession()->getVar('__githubData')) { $githubData = WCF::getSession()->getVar('__githubData'); $this->additionalFields['authData'] = 'github:' . WCF::getSession()->getVar('__githubToken'); WCF::getSession()->unregister('__githubData'); WCF::getSession()->unregister('__githubToken'); if (WCF::getSession()->getVar('__email') && WCF::getSession()->getVar('__email') == $this->email) { $registerVia3rdParty = true; } if (isset($githubData['bio']) && User::getUserOptionID('aboutMe') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $githubData['bio']; } if (isset($githubData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $githubData['location']; } } break; case 'twitter': // Twitter if (WCF::getSession()->getVar('__twitterData')) { $twitterData = WCF::getSession()->getVar('__twitterData'); $this->additionalFields['authData'] = 'twitter:' . $twitterData['user_id']; WCF::getSession()->unregister('__twitterData'); if (isset($twitterData['description']) && User::getUserOptionID('aboutMe') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $twitterData['description']; } if (isset($twitterData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $twitterData['location']; } } break; case 'facebook': // Facebook if (WCF::getSession()->getVar('__facebookData')) { $facebookData = WCF::getSession()->getVar('__facebookData'); $this->additionalFields['authData'] = 'facebook:' . $facebookData['id']; WCF::getSession()->unregister('__facebookData'); if (isset($facebookData['email']) && $facebookData['email'] == $this->email) { $registerVia3rdParty = true; } if (isset($facebookData['gender']) && User::getUserOptionID('gender') !== null) { $saveOptions[User::getUserOptionID('gender')] = $facebookData['gender'] == 'male' ? UserProfile::GENDER_MALE : UserProfile::GENDER_FEMALE; } if (isset($facebookData['birthday']) && User::getUserOptionID('birthday') !== null) { list($month, $day, $year) = explode('/', $facebookData['birthday']); $saveOptions[User::getUserOptionID('birthday')] = $year . '-' . $month . '-' . $day; } if (isset($facebookData['bio']) && User::getUserOptionID('bio') !== null) { $saveOptions[User::getUserOptionID('aboutMe')] = $facebookData['bio']; } if (isset($facebookData['location']) && User::getUserOptionID('location') !== null) { $saveOptions[User::getUserOptionID('location')] = $facebookData['location']['name']; } if (isset($facebookData['website']) && User::getUserOptionID('website') !== null) { $urls = preg_split('/[\\s,;]/', $facebookData['website'], -1, PREG_SPLIT_NO_EMPTY); if (!empty($urls)) { if (!Regex::compile('^https?://')->match($urls[0])) { $urls[0] = 'http://' . $urls[0]; } $saveOptions[User::getUserOptionID('homepage')] = $urls[0]; } } // avatar if (isset($facebookData['picture']) && !$facebookData['picture']['data']['is_silhouette']) { $avatarURL = $facebookData['picture']['data']['url']; } } break; case 'google': // Google Plus if (WCF::getSession()->getVar('__googleData')) { $googleData = WCF::getSession()->getVar('__googleData'); $this->additionalFields['authData'] = 'google:' . $googleData['id']; WCF::getSession()->unregister('__googleData'); if (isset($googleData['emails'][0]['value']) && $googleData['emails'][0]['value'] == $this->email) { $registerVia3rdParty = true; } if (isset($googleData['gender']) && User::getUserOptionID('gender') !== null) { switch ($googleData['gender']) { case 'male': $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_MALE; break; case 'female': $saveOptions[User::getUserOptionID('gender')] = UserProfile::GENDER_FEMALE; break; } } if (isset($googleData['birthday']) && User::getUserOptionID('birthday') !== null) { $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday']; } if (isset($googleData['placesLived']) && User::getUserOptionID('location') !== null) { // save primary location $saveOptions[User::getUserOptionID('location')] = current(array_map(function ($element) { return $element['value']; }, array_filter($googleData['placesLived'], function ($element) { return isset($element['primary']) && $element['primary']; }))); } // avatar if (isset($googleData['image']['url'])) { $avatarURL = $googleData['image']['url']; } } break; } // create fake password $this->password = StringUtil::getRandomID(); } $this->additionalFields['languageID'] = $this->languageID; if (LOG_IP_ADDRESS) { $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress; } // generate activation code $addDefaultGroups = true; if (REGISTER_ACTIVATION_METHOD == 1 && !$registerVia3rdParty || REGISTER_ACTIVATION_METHOD == 2) { $activationCode = UserRegistrationUtil::getActivationCode(); $this->additionalFields['activationCode'] = $activationCode; $addDefaultGroups = false; $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS)); } // check gravatar support if (MODULE_GRAVATAR && Gravatar::test($this->email)) { $this->additionalFields['enableGravatar'] = 1; } // create user $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups); $this->objectAction = new UserAction(array(), 'create', $data); $result = $this->objectAction->executeAction(); $user = $result['returnValues']; $userEditor = new UserEditor($user); // update session WCF::getSession()->changeUser($user); // set avatar if provided if (!empty($avatarURL)) { $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor)); $userAvatarAction->executeAction(); } // activation management if (REGISTER_ACTIVATION_METHOD == 0) { $this->message = 'wcf.user.register.success'; } else { if (REGISTER_ACTIVATION_METHOD == 1) { // registering via 3rdParty leads to instant activation if ($registerVia3rdParty) { $this->message = 'wcf.user.register.success'; } else { $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user))); $mail->send(); $this->message = 'wcf.user.register.needActivation'; } } else { if (REGISTER_ACTIVATION_METHOD == 2) { $this->message = 'wcf.user.register.awaitActivation'; } } } // notify admin if (REGISTER_ADMIN_NOTIFICATION) { // get default language $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID()); // send mail $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user))); $mail->setLanguage($language); $mail->send(); } if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } if (WCF::getSession()->getVar('noRegistrationCaptcha')) { WCF::getSession()->unregister('noRegistrationCaptcha'); } // login user UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password); WCF::getSession()->unregister('registrationRandomFieldNames'); WCF::getSession()->unregister('registrationStartTime'); $this->saved(); // forward to index page HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable($this->message, array('user' => $user)), 15); exit; }
/** * Fetches an avatar from a remote server and sets it for given user. */ public function fetchRemoteAvatar() { $avatarID = 0; $filename = ''; // fetch avatar from URL try { $request = new HTTPRequest($this->parameters['url']); $request->execute(); $reply = $request->getReply(); $filename = FileUtil::getTemporaryFilename('avatar_'); file_put_contents($filename, $reply['body']); $imageData = getimagesize($filename); if ($imageData === false) { throw new SystemException('Downloaded file is not an image'); } } catch (\Exception $e) { if (!empty($filename)) { @unlink($filename); } return; } // rescale avatar if required try { $newFilename = $this->enforceDimensions($filename); if ($newFilename !== $filename) { @unlink($filename); } $filename = $newFilename; $imageData = getimagesize($filename); if ($imageData === false) { throw new SystemException('Rescaled file is not an image'); } } catch (\Exception $e) { @unlink($filename); return; } $tmp = parse_url($this->parameters['url']); if (!isset($tmp['path'])) { @unlink($filename); return; } $tmp = pathinfo($tmp['path']); if (!isset($tmp['basename']) || !isset($tmp['extension'])) { @unlink($filename); return; } $data = array('avatarName' => $tmp['basename'], 'avatarExtension' => $tmp['extension'], 'width' => $imageData[0], 'height' => $imageData[1], 'userID' => $this->parameters['userEditor']->userID, 'fileHash' => sha1_file($filename)); // create avatar $avatar = UserAvatarEditor::create($data); // check avatar directory // and create subdirectory if necessary $dir = dirname($avatar->getLocation()); if (!@file_exists($dir)) { FileUtil::makePath($dir, 0777); } // move uploaded file if (@copy($filename, $avatar->getLocation())) { @unlink($filename); // create thumbnails $action = new UserAvatarAction(array($avatar), 'generateThumbnails'); $action->executeAction(); $avatarID = $avatar->avatarID; } else { @unlink($filename); // moving failed; delete avatar $editor = new UserAvatarEditor($avatar); $editor->delete(); } // update user if ($avatarID) { $this->parameters['userEditor']->update(array('avatarID' => $avatarID, 'enableGravatar' => 0)); // delete old avatar if ($this->parameters['userEditor']->avatarID) { $action = new UserAvatarAction(array($this->parameters['userEditor']->avatarID), 'delete'); $action->executeAction(); } } // reset user storage UserStorageHandler::getInstance()->reset(array($this->parameters['userEditor']->userID), 'avatar'); }