Example #1
0
 /**
  * Registers the preLogin hook to catch wether or not the user accepted the
  * disclaimer
  *
  * @param string $appName   The app's name
  */
 public function register($appName)
 {
     $callback = function ($user, $password) {
         $app = new Application();
         $appName = $app->getAppName();
         $config = $app->getConfig();
         $isDav = strpos($this->request->getScriptName(), '/remote.php') !== false;
         $disclaimerChecked = isset($_POST[$appName . 'Checkbox']);
         if (!$isDav && !$disclaimerChecked) {
             //If the "agree" checkbox wasn't checked, then an throw an
             //exception
             if ($config->getUseCookie()) {
                 //In case that the agree disclaimer cookies was set, expires
                 //it. This means that the user either unchecked the
                 //disclaimer or he hasn't checked it yet
                 $config->expireCheckedCookie();
             }
             $message = $this->l10n->t('Please read and ' . 'agree the disclaimer before proceeding');
             throw new LoginException($message);
         } else {
             if ($config->getUseCookie()) {
                 $config->setLastVisitCookie();
                 $config->setCheckedCookie();
             }
         }
     };
     $this->userManager->listen('\\OC\\User', 'preLogin', $callback);
 }
Example #2
0
/**
 * ownCloud - agreedisclaimer
 *
 * This file is licensed under the MIT License. See the LICENSE file.
 *
 * @author Josef Meile <*****@*****.**>
 * @copyright Josef Meile 2015
 */
namespace OCA\AgreeDisclaimer;

use OCP\AppFramework\Http\TemplateResponse;
use OCA\AgreeDisclaimer\AppInfo\Application;
/**
 * Renders the app settings on the admin page
 *
 * @return string   The template rendered as html
 */
$app = new Application();
$appName = $app->getAppName();
$container = $app->getContainer();
$config = $app->getConfig();
$utils = $app->getUtils();
$defaultLang = $config->getDefaultLang();
$localeInfo = $utils->getAvailableLanguages($defaultLang);
//Fix it: I'm not sure if there is a better way of getting l10n from this
//script, ie: something like in the templates: $l->...
$l10n = $app->getContainer()->getServer()->getL10N($appName);
$userLang = $l10n->getLanguageCode();
$data = ['appName' => $appName, 'filePreffix' => $container->query('filePreffix'), 'datepickerAppFormat' => $config->getDatepickerDateFormat(), 'cookieData' => $config->getCookieData(true), 'txtFileData' => $config->getTxtFileData(false, true), 'pdfFileData' => $config->getPdfFileData(false, true), 'disclaimerType' => $config->getDisclaimerType(), 'disclaimerTypes' => $config->getDisclaimerTypes(true), 'disclaimerLayout' => $config->getDisclaimerLayout(), 'disclaimerLayouts' => $config->getDisclaimerLayouts(), 'userLang' => $userLang, 'currentLang' => $localeInfo['activelanguage'], 'commonLanguages' => $localeInfo['commonlanguages'], 'availableLanguages' => $localeInfo['languages']];
$templateResponse = new TemplateResponse($appName, 'admin', $data, 'blank');
return $templateResponse->render();
Example #3
0
 /**
  * Gets the absolute path of the pdf files with the disclaimer text
  *
  * @return string   The absolute path to the 'pdf' folder
  *
  * @remarks: This files are located on a folder called: 'pdf' inside the
  *           application's absolute path
  */
 public static function getPdfFilesPath()
 {
     $appPath = Application::getAppPath() . DIRECTORY_SEPARATOR;
     return $appPath . 'pdf';
 }
 /**
  * Get the file information for the txt and pdf files
  *
  * @param   bool    $isAdminForm    Whether or not is called from the admin
  *          form. This is used because the method can be also called from
  *          the login page. Here the differences:
  *          - When called from the admin form, no fall back languages will
  *            be used 
  *          - When called from the login form, fall back languages will be
  *            used 
  * @param   string  $defaultLang    Default language for which the file will
  *          be recovered in case that it doesn't exist for the current
  *          language. In case that it is null, then the default language of
  *          the application will be used.
  *
  * @return array   Array with the file information for the txt and pdf
  *         files. It has this format:
  *          [
  *              '<appId>TxtFile'        => [
  *                  'value'    => <true_or_false>,
  *                  'basePath' => <absolute_path_of_txt_file>,
  *                  'file'     => [
  *                      'exists'  => <does_the_file_exist>,
  *                      'lang'    => <file_language_code>,
  *                      'name'    => <file_name>,
  *                      'path'    => <file_location_in_the_file_system>,
  *                      'url'     => <url_to_file_in_web_browser>,
  *                      'content' => <contents_txt_file>,
  *                      'error'   => <error_message>,
  *                  ],
  *              ],
  *              '<appId>PdfFile'        => [
  *                  'value'    => <true_or_false>,
  *                  'basePath' => <absolute_path_of_pdf_file>,
  *                  'file'     => [
  *                      'exists'  => <does_the_file_exist>,
  *                      'lang'    => <file_language_code>,
  *                      'name'    => <file_name>,
  *                      'path'    => <file_location_in_the_file_system>,
  *                      'url'     => <url_to_file_in_web_browser>,
  *                      'error'   => <error_message>,
  *                  ],
  *              ]
  *          ]
  */
 function getFiles($isAdminForm = false, $defaultLang = null)
 {
     $data = array();
     $appId = Application::APP_ID;
     $appConfig = \OC::$server->getAppConfig();
     if ($defaultLang === null) {
         $defaultLangProp = $appId . 'DefaultLang';
         $defaultLang = self::getSetting($defaultLangProp, 'en', $appConfig);
     }
     if (!$isAdminForm) {
         $userLang = Utils::getUserLang();
         $getFallbackLang = true;
     } else {
         $userLang = $defaultLang;
         $getFallbackLang = false;
     }
     $maxTxtFileSizeProp = $appId . 'MaxTxtFileSize';
     $maxTxtFileSize = self::getSetting($maxTxtFileSizeProp, '1', $appConfig);
     $txtFileBasePath = Application::getTxtFilesPath();
     $pdfFileBasePath = Application::getPdfFilesPath();
     $fileInfo = self::getFile($userLang, $defaultLang, $txtFileBasePath, 'txt', true, $maxTxtFileSize, $getFallbackLang);
     $data['txtFile'] = $fileInfo;
     $fileInfo = self::getFile($userLang, $defaultLang, $pdfFileBasePath, 'pdf', false, 2, $getFallbackLang);
     $data['pdfFile'] = $fileInfo;
     return $data;
 }
Example #5
0
if ($adminSettings[$pdfFileProp]['file']['error'] === '') {
    //If there isn't any error with the pdf file, then a link to it will be
    //shown
    $pdfLink = $adminSettings[$pdfFileProp]['file']['url'];
    $pdfLink = '<a href="' . $pdfLink . '" target="_blank">' . $adminSettings[$pdfFileProp]['file']['name'] . '</a>';
} else {
    //Otherwise, an error will be displayed
    $pdfLink = $adminSettings[$pdfFileProp]['file']['error'];
}
$maxTxtFileSizeProp = $appId . 'MaxTxtFileSize';
$defaultLangProp = $appId . 'DefaultLang';
$maxFileSizeLimitProp = $appId . 'MaxFileSizeLimit';
$maxFileSizeLimit = Application::FILE_SIZE_LIMIT;
//The current administrator's language and the ownCloud supported language will
//be retreived
$localeInfo = Application::getAvailableLanguages($adminSettings[$defaultLangProp]['value']);
$currentLanguage = $localeInfo['activelanguage'];
$commonLanguages = $localeInfo['commonlanguages'];
$availableLanguages = $localeInfo['languages'];
/**
 * Adds the admin.js file to the settings page
 */
script($appId, 'admin');
/**
 * Adds the style sheets file to the settings page
 */
style($appId, 'admin');
?>

<div class="section" id="<?php 
p($appId);