/** * Takes over after a user has been activated. * * @param UserModel $user */ private function _onAfterActivateUser(UserModel $user) { // Should we log them in? $loggedIn = false; if (craft()->config->get('autoLoginAfterAccountActivation')) { $loggedIn = craft()->userSession->loginByUserId($user->id, false, true); } // Can they access the CP? if ($user->can('accessCp')) { $postCpLoginRedirect = craft()->config->get('postCpLoginRedirect'); $url = UrlHelper::getCpUrl($postCpLoginRedirect); } else { $activateAccountSuccessPath = craft()->config->getLocalized('activateAccountSuccessPath'); $url = UrlHelper::getSiteUrl($activateAccountSuccessPath); } $this->redirect($url); }
/** * Sets a new verification code on a user, and returns their new Password Reset URL. * * @param UserModel $user The user that should get the new Password Reset URL * * @return string The new Password Reset URL. */ public function getPasswordResetUrl(UserModel $user) { $userRecord = $this->_getUserRecordById($user->id); $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord); $userRecord->save(); if ($user->can('accessCp')) { $url = UrlHelper::getActionUrl('users/setpassword', array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http'); } else { // We want to hide the CP trigger if they don't have access to the CP. $path = craft()->config->get('actionTrigger') . '/users/setpassword'; $url = UrlHelper::getSiteUrl($path, array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http'); } return $url; }
/** * Sets a new verification code on a user, and returns their new Password Reset URL. * * @param UserModel $user The user that should get the new Password Reset URL * * @return string The new Password Reset URL. */ public function getPasswordResetUrl(UserModel $user) { $userRecord = $this->_getUserRecordById($user->id); $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord); $userRecord->save(); $path = craft()->config->get('actionTrigger') . '/users/setpassword'; $params = array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid); $scheme = UrlHelper::getProtocolForTokenizedUrl(); if ($user->can('accessCp')) { return UrlHelper::getCpUrl($path, $params, $scheme); } else { $locale = $user->preferredLocale ?: craft()->i18n->getPrimarySiteLocaleId(); return UrlHelper::getSiteUrl($path, $params, $scheme, $locale); } }
/** * Returns a user’s Set Password path with a given activation code and user’s UID. * * @param string $code The activation code. * @param string $uid The user’s UID. * @param UserModel $user The user. * @param bool $full Whether a full URL should be returned. Defaults to `false`. * * @return string The Set Password path. * * @internal This is a little awkward in that the method is called getActivateAccount**Path**, but it's also capable * of returning a full **URL**. And it requires you pass in both a user’s UID *and* the UserModel - presumably we * could get away with just the UserModel and get the UID from that. * * @todo Create a new getSetPasswordUrl() method (probably elsewhere, such as UrlHelper) which handles * everything that setting $full to `true` currently does here. The function should not accetp a UID since that's * already covered by the UserModel. Let this function continue working as a wrapper for getSetPasswordUrl() for the * time being, with deprecation logs. */ public function getSetPasswordPath($code, $uid, $user, $full = false) { if ($user->can('accessCp')) { $url = $this->getCpSetPasswordPath(); if ($full) { if (craft()->request->isSecureConnection()) { $url = UrlHelper::getCpUrl($url, array('code' => $code, 'id' => $uid), 'https'); } else { $url = UrlHelper::getCpUrl($url, array('code' => $code, 'id' => $uid)); } } } else { $url = $this->getLocalized('setPasswordPath'); if ($full) { if (craft()->request->isSecureConnection()) { $url = UrlHelper::getUrl($url, array('code' => $code, 'id' => $uid), 'https'); } else { $url = UrlHelper::getUrl($url, array('code' => $code, 'id' => $uid)); } } } return $url; }
/** * Sets a new verification code on a user, and returns their new Password Reset URL. * * @param UserModel $user The user that should get the new Password Reset URL * * @return string The new Password Reset URL. */ public function getPasswordResetUrl(UserModel $user) { $userRecord = $this->_getUserRecordById($user->id); $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord); $userRecord->save(); $path = craft()->config->get('actionTrigger') . '/users/setpassword'; $params = array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid); $scheme = craft()->request->isSecureConnection() ? 'https' : 'http'; if ($user->can('accessCp')) { return UrlHelper::getCpUrl($path, $params, $scheme); } else { return UrlHelper::getSiteUrl($path, $params, $scheme); } }
/** * Redirect the browser after a user’s account has been activated. * * @param UserModel $user The user that was just activated * * @return void */ private function _redirectUserAfterAccountActivation(UserModel $user) { // Can they access the CP? if ($user->can('accessCp')) { $postCpLoginRedirect = craft()->config->get('postCpLoginRedirect'); $url = UrlHelper::getCpUrl($postCpLoginRedirect); } else { $activateAccountSuccessPath = craft()->config->getLocalized('activateAccountSuccessPath'); $url = UrlHelper::getSiteUrl($activateAccountSuccessPath); } $this->redirect($url); }
/** * @codeCoverageIgnore * * @param array $settings * @param string $backup * @param UserModel $currentUser * * @return string Backup filename */ protected function saveBackup($settings, $backup, $currentUser) { if ($currentUser->can('backup') && $settings['backup'] && IOHelper::fileExists($backup)) { $destZip = craft()->path->getTempPath() . IOHelper::getFileName($backup, false) . '.zip'; if (IOHelper::fileExists($destZip)) { IOHelper::deleteFile($destZip, true); } IOHelper::createFile($destZip); if (Zip::add($destZip, $backup, craft()->path->getDbBackupPath())) { $backup = $destZip; } } return $backup; }