Ejemplo n.º 1
0
 /**
  * The method of the request was set to get in the constructor
  *
  * @depends	testConstructorNoParams
  * @return	null
  */
 public function testIsGetPostCli()
 {
     $this->assertTrue($this->input->isGet());
     $this->assertFalse($this->input->isPost());
     $this->assertFalse($this->input->isCli());
     $this->assertEquals('get', $this->input->getMethod());
     $input = new AppInput('post');
     $this->assertTrue($input->isPost());
     $this->assertFalse($input->isGet());
     $this->assertFalse($input->isCli());
     $this->assertEquals('post', $input->getMethod());
     $input = new AppInput('cli');
     $this->assertTrue($input->isCli());
     $this->assertFalse($input->isGet());
     $this->assertFalse($input->isPost());
     $this->assertEquals('cli', $input->getMethod());
     /* prove not case sensitive */
     $input = new AppInput('GET');
     $this->assertTrue($input->isGet());
     $this->assertFalse($input->isPost());
     $this->assertFalse($input->isCli());
     $this->assertEquals('get', $input->getMethod());
     $input = new AppInput('POST');
     $this->assertTrue($input->isPost());
     $this->assertFalse($input->isGet());
     $this->assertFalse($input->isCli());
     $this->assertEquals('post', $input->getMethod());
     $input = new AppInput('CLI');
     $this->assertTrue($input->isCli());
     $this->assertFalse($input->isGet());
     $this->assertFalse($input->isPost());
     $this->assertEquals('cli', $input->getMethod());
 }
Ejemplo n.º 2
0
 public function testPost()
 {
     $req = new Request();
     $_POST['test'] = 1;
     $this->assertEquals($_POST['test'], $req->test);
     $this->assertTrue(isset($req->test));
     $this->assertFalse($req->isPost());
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $this->assertTrue($req->isPost());
     $this->assertEquals($_SERVER['REQUEST_METHOD'], $req->server('REQUEST_METHOD'));
 }
Ejemplo n.º 3
0
 public static function instance($className, $args = array())
 {
     global $root;
     settype($className, 'string');
     settype($args, 'array');
     $fileName = str_replace('_', DIRECTORY_SEPARATOR, $className);
     if (!is_readable("{$root}/bin/{$fileName}.php")) {
         return false;
     }
     include_once "{$root}/bin/{$fileName}.php";
     if (!class_exists($className, false)) {
         return false;
     }
     $reflection = new ReflectionClass($className);
     if ($reflection->getParentClass()->getName() != 'WebBase') {
         return false;
     }
     if (null === self::$match) {
         self::$match = $className;
     }
     $controller = call_user_func(array(&$reflection, 'newInstance'), $args);
     if ($controller->type && !empty($controller->type) && Response::canSendHeaders()) {
         Response::setHeader('Content-Type', $controller->type, true);
     }
     if (Request::isPost() && method_exists($controller, 'submit')) {
         $controller->submit();
     }
     if (Response::canSendHeaders()) {
         Response::sendResponse();
     }
     if (method_exists($controller, 'dispatch')) {
         $controller->dispatch();
     }
     return true;
 }
Ejemplo n.º 4
0
 public function trigger_automaticupdate_action($class)
 {
     $output = array();
     if (Request::isPost()) {
         $plugin = PluginManager::getInstance()->getPluginInfo($class);
         $low_cost_secret = md5($GLOBALS['STUDIP_INSTALLATION_ID'] . $plugin['id']);
         if ($plugin['automatic_update_url'] && $low_cost_secret === \Request::option("s")) {
             if ($plugin['automatic_update_secret'] && !$this->verify_secret($plugin['automatic_update_secret'])) {
                 $output['error'] = "Incorrect payload.";
             } else {
                 //everything fine, we can download and install the plugin
                 $update_url = $plugin['automatic_update_url'];
                 require_once 'app/models/plugin_administration.php';
                 $plugin_admin = new PluginAdministration();
                 try {
                     $plugin_admin->installPluginFromURL($update_url);
                 } catch (Exception $e) {
                     $output['exception'] = $e->getMessage();
                 }
             }
         } else {
             $output['error'] = "Wrong URL.";
         }
         if (!count($output)) {
             $output['message'] = "ok";
         }
     } else {
         $output['error'] = "Only POST requests allowed.";
     }
     $this->render_json($output);
 }
Ejemplo n.º 5
0
 public function display($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.register.display');
     if (!User::get()->is_guest) {
         return Router::redirect(Router::pathFor('home'));
     }
     // Antispam feature
     $lang_antispam_questions = (require ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/antispam.php');
     $index_questions = rand(0, count($lang_antispam_questions) - 1);
     // Display an error message if new registrations are disabled
     // If $_REQUEST['username'] or $_REQUEST['password'] are filled, we are facing a bot
     if (ForumSettings::get('o_regs_allow') == '0' || Input::post('username') || Input::post('password')) {
         throw new Error(__('No new regs'), 403);
     }
     $user['timezone'] = isset($user['timezone']) ? $user['timezone'] : ForumSettings::get('o_default_timezone');
     $user['dst'] = isset($user['dst']) ? $user['dst'] : ForumSettings::get('o_default_dst');
     $user['email_setting'] = isset($user['email_setting']) ? $user['email_setting'] : ForumSettings::get('o_default_email_setting');
     $user['errors'] = '';
     if (Request::isPost()) {
         $user = $this->model->check_for_errors();
         // Did everything go according to plan? Insert the user
         if (empty($user['errors'])) {
             return $this->model->insert_user($user);
         }
     }
     View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Register')), 'focus_element' => array('register', 'req_user'), 'required_fields' => array('req_user' => __('Username'), 'req_password1' => __('Password'), 'req_password2' => __('Confirm pass'), 'req_email1' => __('Email'), 'req_email2' => __('Email') . ' 2', 'captcha' => __('Robot title')), 'active_page' => 'register', 'is_indexed' => true, 'errors' => $user['errors'], 'index_questions' => $index_questions, 'languages' => \FeatherBB\Core\Lister::getLangs(), 'question' => array_keys($lang_antispam_questions), 'qencoded' => md5(array_keys($lang_antispam_questions)[$index_questions])))->addTemplate('register/form.php')->display();
 }
Ejemplo n.º 6
0
 /**
  * This method edits existing holidays or creates new holidays
  *
  * @param mixed $id Id of the holiday or null to create one
  */
 public function edit_action($id = null)
 {
     $this->holiday = new SemesterHoliday($id);
     PageLayout::setTitle($this->holiday->isNew() ? _('Ferien anlegen') : _('Ferien bearbeiten'));
     if (Request::isPost()) {
         CSRFProtection::verifyUnsafeRequest();
         $this->holiday->name = Request::get('name');
         $this->holiday->description = Request::get('description');
         $this->holiday->beginn = $this->getTimeStamp('beginn');
         $this->holiday->ende = $this->getTimeStamp('ende', '23:59:59');
         $errors = array();
         if (!$this->holiday->name) {
             $errors[] = _('Bitte geben Sie einen Namen ein.');
         }
         if (!$this->holiday->beginn) {
             $errors[] = _('Bitte geben Sie einen Ferienbeginn ein.');
         }
         if (!$this->holiday->ende) {
             $errors[] = _('Bitte geben Sie ein Ferienende ein.');
         }
         if ($this->holiday->beginn > $this->holiday->ende) {
             $errors[] = _('Das Ferienende liegt vor dem Beginn.');
         }
         if (!empty($errors)) {
             PageLayout::postMessage(MessageBox::error(_('Ihre eingegebenen Daten sind ungültig.'), $errors));
         } elseif ($this->holiday->isDirty() && !$this->holiday->store()) {
             PageLayout::postMessage(MessageBox::error(_('Die Ferien konnten nicht gespeichert werden.')));
         } else {
             PageLayout::postMessage(MessageBox::success(_('Die Ferien wurden erfolgreich gespeichert.')));
             $this->relocate('admin/holidays');
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * This method edits an existing semester or creates a new semester.
  *
  * @param mixed $id Id of the semester or null to create a semester.
  */
 public function edit_action($id = null)
 {
     $this->semester = new Semester($id);
     PageLayout::setTitle($this->semester->isNew() ? _('Semester anlegen') : _('Semester bearbeiten'));
     if (Request::isPost()) {
         CSRFProtection::verifyUnsafeRequest();
         // Extract values
         $this->semester->name = Request::get('name');
         $this->semester->description = Request::get('description');
         $this->semester->semester_token = Request::get('token');
         $this->semester->beginn = $this->getTimeStamp('beginn');
         $this->semester->ende = $this->getTimeStamp('ende', '23:59:59');
         $this->semester->vorles_beginn = $this->getTimeStamp('vorles_beginn');
         $this->semester->vorles_ende = $this->getTimeStamp('vorles_ende', '23:59:59');
         // Validate
         $errors = $this->validateSemester($this->semester);
         // If valid, try to store the semester
         if (empty($errors) && $this->semester->isDirty() && !$this->semester->store()) {
             $errors[] = _('Fehler bei der Speicherung Ihrer Daten. Bitte überprüfen Sie Ihre Angaben.');
         }
         // Output potential errors or show success message and relocate
         if (count($errors) === 1) {
             $error = reset($errors);
             PageLayout::postMessage(MessageBox::error($error));
         } elseif (!empty($errors)) {
             $message = _('Ihre eingegebenen Daten sind ungültig.');
             PageLayout::postMessage(MessageBox::error($message, $errors));
         } else {
             $message = _('Das Semester wurde erfolgreich gespeichert.');
             PageLayout::postMessage(MessageBox::success($message));
             $this->relocate('admin/semester');
         }
         $this->errors = $errors;
     }
 }
Ejemplo n.º 8
0
 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     // Lock context to user id
     $this->owner = $GLOBALS['user'];
     $this->context_id = $this->owner->id;
     $this->full_access = true;
     if (Config::get()->PERSONALDOCUMENT_OPEN_ACCESS) {
         $username = Request::username('username', $GLOBALS['user']->username);
         $user = User::findByUsername($username);
         if ($user && $user->id !== $GLOBALS['user']->id) {
             $this->owner = $user;
             $this->context_id = $user->id;
             $this->full_access = Config::get()->PERSONALDOCUMENT_OPEN_ACCESS_ROOT_PRIVILEDGED && $GLOBALS['user']->perms === 'root';
             URLHelper::bindLinkParam('username', $username);
         }
     }
     $this->limit = $GLOBALS['user']->cfg->PERSONAL_FILES_ENTRIES_PER_PAGE ?: Config::get()->ENTRIES_PER_PAGE;
     $this->userConfig = DocUsergroupConfig::getUserConfig($GLOBALS['user']->id);
     if ($this->userConfig['area_close'] == 1) {
         $this->redirect('document/closed/index');
     }
     if (Request::isPost()) {
         CSRFProtection::verifySecurityToken();
     }
     if (($ticket = Request::get('studip-ticket')) && !check_ticket($ticket)) {
         $message = _('Bei der Verarbeitung Ihrer Anfrage ist ein Fehler aufgetreten.') . "\n" . _('Bitte versuchen Sie es erneut.');
         PageLayout::postMessage(MessageBox::error($message));
         $this->redirect('document/files/index');
     }
 }
Ejemplo n.º 9
0
function profile_main()
{
    global $template;
    // open template
    $template->setFile('profile.tmpl');
    // connect to login db
    if (!($db_login = DbConnect(Config::DB_LOGIN_HOST, Config::DB_LOGIN_USER, Config::DB_LOGIN_PWD, Config::DB_LOGIN_NAME))) {
        $template->throwError('Datenbankverbindungsfehler. Bitte wende dich an einen Administrator.');
        return;
    }
    $action = Request::getVar('action', '');
    switch ($action) {
        /****************************************************************************************************
        *
        * Profil aktualisieren
        *
        ****************************************************************************************************/
        case 'change':
            // proccess form data
            $message = profile_update($db_login);
            // update player's data
            page_refreshUserData();
            break;
            /****************************************************************************************************
            *
            * Account "löschen"
            *
            ****************************************************************************************************/
        /****************************************************************************************************
        *
        * Account "löschen"
        *
        ****************************************************************************************************/
        case 'delete':
            if (Request::isPost('postConfirm')) {
                if (profile_processDeleteAccount($db_login, $_SESSION['player']->playerID)) {
                    session_destroy();
                    die(json_encode(array('mode' => 'finish', 'title' => 'Account gelöscht', 'msg' => _('Ihr Account wurde zur Löschung vorgemerkt. Sie sind jetzt ausgeloggt und können das Fenster schließen.'))));
                } else {
                    $message = array('type' => 'error', 'message' => _('Das löschen Ihres Accounts ist fehlgeschlagen. Bitte wenden Sie sich an das Support Team.'));
                }
            } else {
                $template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'delete', 'confirm_id' => $_SESSION['player']->playerID, 'confirm_mode' => USER_PROFILE, 'confirm_msg' => _('Möchtest du deinen Account wirklich löschen?')));
            }
            break;
    }
    // get login data
    $playerData = profile_getPlayerData($db_login);
    if (!$playerData) {
        $template->throwError('Datenbankfehler. Bitte wende dich an einen Administrator');
        return;
    }
    /****************************************************************************************************
    *
    * Übergeben ans Template
    *
    ****************************************************************************************************/
    $template->addVars(array('status_msg' => isset($message) && !empty($message) ? $message : '', 'player' => $playerData['game'], 'language' => LanguageNames::getLanguageNames(), 'template' => Config::$template_paths));
}
Ejemplo n.º 10
0
 public function display($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.admin.options.display');
     if (Request::isPost()) {
         return $this->model->update_options();
     }
     AdminUtils::generateAdminMenu('options');
     View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Options')), 'active_page' => 'admin', 'admin_console' => true, 'languages' => $this->model->get_langs(), 'styles' => $this->model->get_styles(), 'times' => $this->model->get_times()))->addTemplate('admin/options.php')->display();
 }
Ejemplo n.º 11
0
 public function index()
 {
     if (Request::isPost()) {
         var_dump(Input::get());
     }
     App::collection('items')->create(array('name' => "Item " . rand()));
     $items = App::collection('items');
     return $this->view('index', array('item' => $items->first(), 'items' => $items->paginate()));
 }
Ejemplo n.º 12
0
 public function display($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.admin.permissions.display');
     // Update permissions
     if (Request::isPost()) {
         return $this->model->update_permissions();
     }
     AdminUtils::generateAdminMenu('permissions');
     return View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Permissions')), 'active_page' => 'admin', 'admin_console' => true))->addTemplate('admin/permissions.php')->display();
 }
Ejemplo n.º 13
0
 public function listAction()
 {
     if (Request::isAjax() && Request::isPost()) {
         $user = UsersPDO::get(AuthModel::getUserName());
         $receiverId = $_POST['receiverId'];
         $model = new ChatModel($user['Id']);
         $result = $model->getChat($receiverId);
         $this->renderJSON($result);
     }
 }
Ejemplo n.º 14
0
 public function display($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.admin.groups.display');
     $groups = $this->model->fetch_groups();
     // Set default group
     if (Request::isPost()) {
         return $this->model->set_default_group($groups);
     }
     AdminUtils::generateAdminMenu('groups');
     View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('User groups')), 'active_page' => 'admin', 'admin_console' => true, 'groups' => $groups, 'cur_index' => 5))->addTemplate('admin/groups/admin_groups.php')->display();
 }
Ejemplo n.º 15
0
 public function display($req, $res, $args)
 {
     Container::get('hooks')->fire('controller.admin.reports.display');
     // Zap a report
     if (Request::isPost()) {
         $zap_id = intval(key(Input::post('zap_id')));
         $this->model->zap_report($zap_id);
         return Router::redirect(Router::pathFor('adminReports'), __('Report zapped redirect'));
     }
     AdminUtils::generateAdminMenu('reports');
     return View::setPageInfo(array('title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Reports')), 'active_page' => 'admin', 'admin_console' => true, 'report_data' => $this->model->get_reports(), 'report_zapped_data' => $this->model->get_zapped_reports()))->addTemplate('admin/reports.php')->display();
 }
Ejemplo n.º 16
0
 public function validateRequest(array $requiredParams)
 {
     $objUtilResponse = new Response();
     $objUtilRequest = new Request();
     if ($objUtilRequest->isPost()) {
         $accessKeyId = $objUtilRequest->getPost('access_key', false);
         $signature = trim($objUtilRequest->getPost('signature', false));
         $timestamp = $objUtilRequest->getPost('timestamp', false);
         // Required to generate variable signature
         $parameters = array('timestamp' => $timestamp);
         $allParamsPresent = true;
         foreach ($requiredParams as $paramName) {
             $paramValue = $objUtilRequest->getPost($paramName, false);
             if ($paramName) {
                 $parameters[$paramName] = $paramValue;
             } else {
                 $allParamsPresent = false;
                 break;
             }
         }
         if ($accessKeyId && $signature && $timestamp) {
             // Okay we have all required parameters
             // Let's identify user
             $requestParams = $objUtilRequest->getRequest();
             $objServerHelper = new ServerInfo();
             $url = $objServerHelper->serverUrl(true);
             $userSyncRestMdl = new \api\Server($parameters, $accessKeyId, null, $url);
             $isValidTimestamp = $userSyncRestMdl->isValidTimestamp($timestamp);
             if (!$isValidTimestamp) {
                 $objUtilResponse->renderJson(array('status' => 403, 'message' => 'Invalid Timestamp'), 403);
             }
             $userProductMdl = new \models\ApiProducts();
             $apiProductDetails = $userProductMdl->isValidAccessKey($accessKeyId);
             if ($apiProductDetails) {
                 // Valid access key
                 $userSyncRestMdl->setSecretKey($apiProductDetails->secret_key);
                 $isValidSignature = $userSyncRestMdl->isValidSignature($signature);
                 if ($isValidSignature === true) {
                     return $apiProductDetails;
                 } else {
                     $objUtilResponse->renderJson(array('status' => 403, 'message' => 'Invalid Signature'), 403);
                 }
             } else {
                 $objUtilResponse->renderJson(array('status' => 403, 'message' => 'Invalid access key.'), 403);
             }
         } else {
             $objUtilResponse->renderJson(array('status' => 403, 'message' => 'Required parameters are missing.'), 403);
         }
     } else {
         $objUtilResponse->renderJson(array('status' => 403, 'message' => 'Only post requests are accepted'), 403);
     }
 }
 /**
  * действие для странички с контактной формой - Contact
  *
  * @param Request $request
  * @return int
  */
 public function contactAction(Request $request)
 {
     $form = new ContactForm($request);
     if ($request->isPost()) {
         if ($form->isValid()) {
             Session::setFlash('Message sent!');
             header('Location: /contact');
             die;
         } else {
             Session::setFlash('Fail');
         }
     }
     $args = array('form' => $form);
     return $this->render('contact', $args);
 }
 /**
  * Get the HTML contents for this block.
  */
 function getContents(&$templateMgr)
 {
     $templateMgr->assign('isPostRequest', Request::isPost());
     if (!defined('SESSION_DISABLE_INIT')) {
         $site =& Request::getSite();
         $locales =& $site->getSupportedLocaleNames();
     } else {
         $locales =& Locale::getAllLocales();
         $templateMgr->assign('languageToggleNoUser', true);
     }
     if (isset($locales) && count($locales) > 1) {
         $templateMgr->assign('enableLanguageToggle', true);
         $templateMgr->assign('languageToggleLocales', $locales);
     }
     return parent::getContents($templateMgr);
 }
Ejemplo n.º 19
0
 public function testMethods()
 {
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $Request = new Request();
     $this->assertTrue($Request->isPost());
     $this->assertFalse($Request->isGet());
     $this->assertEqual($Request->method(), 'POST');
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $Request = new Request();
     $this->assertFalse($Request->isPost());
     $this->assertTrue($Request->isGet());
     $this->assertEqual($Request->method(), 'GET');
     $this->assertFalse($Request->isAjax());
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
     $this->assertTrue($Request->isAjax());
 }
Ejemplo n.º 20
0
 public function infoAction()
 {
     $model = new UserModel(AuthModel::getUserName());
     if (Request::isPost()) {
         $firstName = $_POST['firstName'];
         $lastName = $_POST['lastName'];
         $birthDate = $_POST['birthDate'];
         try {
             $model->setPersonalInfo($firstName, $lastName, $birthDate);
         } catch (SiteException $ex) {
             $this->errors = $ex->getErrors();
         }
     }
     $this->personalInfo = $model->getPersonalInfo();
     $this->view('personal_info');
 }
Ejemplo n.º 21
0
/**
 * This function delegates the task at issue to the respective function.
 */
function profile_main()
{
    global $template;
    // connect to login db
    if (!($db_login = DbConnect(Config::DB_LOGIN_HOST, Config::DB_LOGIN_USER, Config::DB_LOGIN_PWD, Config::DB_LOGIN_NAME))) {
        $template->throwError('Datenbankverbindungsfehler. Bitte wende dich an einen Administrator.');
        return;
    }
    $action = Request::getVar('action', '');
    switch ($action) {
        // change cave page
        case 'change':
            // proccess form data
            $message = profile_update($db_login);
            // update player's data
            page_refreshUserData();
            break;
            // change cave page
        // change cave page
        case 'delete':
            if (Request::isPost('cancelOrderConfirm')) {
                if (profile_processDeleteAccount($db_login, $_SESSION['player']->playerID)) {
                    session_destroy();
                    $message = array('type' => 'success', 'message' => _('Ihr Account wurde zur Löschung vorgemerkt. Sie sind jetzt ausgeloggt und können das Fenster schließen.'));
                } else {
                    $message = array('type' => 'error', 'message' => _('Das löschen Ihres Accounts ist fehlgeschlagen. Bitte wenden Sie sich an das Support Team.'));
                }
            } else {
                $template->addVars(array('cancelOrder_box' => true, 'confirm_action' => 'delete', 'confirm_id' => $_SESSION['player']->playerID, 'confirm_mode' => USER_PROFILE, 'confirm_msg' => _('Möchtest du deinen Account wirklich löschen?')));
            }
            break;
    }
    // open template
    $template->setFile('profile.tmpl');
    // get login data
    $playerData = profile_getPlayerData($db_login);
    if (!$playerData) {
        $template->throwError('Datenbankfehler. Bitte wende dich an einen Administrator');
        return;
    }
    // show message
    if (isset($message) && !empty($message)) {
        $template->addVar('status_msg', $message);
    }
    // show the profile's data
    profile_fillUserData($template, $playerData);
}
Ejemplo n.º 22
0
 public function edit_action($process_id = null)
 {
     $this->process = new FleximportProcess($process_id);
     if (Request::isPost()) {
         if (Request::submitted("delete_process")) {
             $this->process->delete();
             PageLayout::postMessage(MessageBox::success(_("Prozess wurde gelöscht.")));
             $processes = FleximportProcess::findBySQL("1=1 ORDER BY name ASC");
             $this->redirect("import/overview" . (count($processes) ? "/" . $processes[0]['process_id'] : ""));
         } else {
             $this->process->setData(Request::getArray("data"));
             $this->process->store();
             PageLayout::postMessage(MessageBox::success(_("Prozess wurde gespeichert")));
             $this->redirect("import/overview/" . $this->process->getId());
         }
     }
 }
 public function create($req, $res, $args)
 {
     // Ensure user is logged
     $user = $req->getAttribute('user');
     if ($user->is_guest) {
         return Router::redirect(Router::pathFor('login'), 'You must be logged in to submit a new theme');
     }
     // Prepare base data to send to view
     $data = ['active_nav' => 'themes'];
     if (Request::isPost()) {
         $theme = ['homepage' => Input::post('homepage'), 'name' => Input::post('name'), 'author' => $user->username];
         ThemeModel::create($theme);
         return Router::redirect(Router::pathFor('themes.create'), 'Theme submitted');
     }
     // Display view
     return View::setPageInfo($data)->addBreadcrumb([Router::pathFor('themes') => 'Themes', 'Submit new theme'])->addTemplate('themes/create.php')->display();
 }
Ejemplo n.º 24
0
 public function loginAction()
 {
     if (Request::isPost()) {
         $userName = $_POST['userName'];
         $password = $_POST['password'];
         $errors = [];
         if (AuthModel::login($userName, $password)) {
             header("Location: /");
             return;
         } else {
             $errors[] = 'Login failed';
         }
         $this->errors = $errors;
     }
     $this->title = 'Login page';
     $this->view("login");
 }
Ejemplo n.º 25
0
 /**
  * действие для странички с контактной формой - Contact
  *
  * @param Request $request
  * @return int
  */
 public function contactAction(Request $request)
 {
     $form = new ContactForm($request);
     if ($request->isPost()) {
         if ($form->isValid()) {
             // todo: email + insert into DB table via MessageModel
             Session::setFlash('Booya! Message sent!');
             // todo: добавить в базовый класс метод redirect($route). Тогда тут будет $this->redirect('contact')
             header('Location: /contact');
             die;
         } else {
             Session::setFlash('Fail');
         }
     }
     $args = array('form' => $form);
     return $this->render('contact', $args);
 }
 public function searchAction()
 {
     $page_data = $this->index('basic_page');
     $request = new Request();
     if ($request->isPost()) {
         $search = new SearchModel($request);
         if (!$search->isSmall()) {
             if (!$search->isLarge()) {
                 $search_data = $search->search();
             } else {
                 Session::setFlash(__t('long_inquiry'));
             }
         } else {
             Session::setFlash(__t('short_inquiry'));
         }
     }
     $search_array = array();
     if (isset($search_data)) {
         foreach ($search_data as $material_type) {
             foreach ($material_type as $val) {
                 $search_array[] = $val;
             }
         }
     }
     $items_count = count($search_array);
     $items_per_page = Config::get('search_per_page');
     $request = new Request();
     $currentPage = $request->get('page') ? (int) $request->get('page') : 1;
     $data_pagination = self::getPagination($items_count, $items_per_page, $currentPage);
     if ($items_count) {
         $data_search_page = array_chunk($search_array, $items_per_page, true);
         if (isset($data_search_page[$currentPage - 1])) {
             $data_search_page = $data_search_page[$currentPage - 1];
         } else {
             throw new Exception('Page (' . Router::getUri() . ') not found', 404);
         }
     } else {
         $data_search_page = null;
     }
     $data_url = explode('?', Router::getUri());
     $lang = Router::getLanguage() == Config::get('default_language') ? '' : Router::getLanguage() . '/';
     //    $search_request = $search->getSearchRequest();
     $args = array('page_data' => $page_data, 'data_search' => $data_search_page, 'data_pagination' => $data_pagination, 'data_url' => $data_url[0], 'lang' => $lang, 'items_count' => $items_count, 'img' => $page_data['img']);
     return $this->render($args);
 }
Ejemplo n.º 27
0
 public function edit_action()
 {
     if (Request::isPost()) {
         $configs = Request::getArray("configs");
         foreach ($configs as $name => $data) {
             if ($name !== $data['name'] || !$data['value']) {
                 FleximportConfig::delete($name);
             }
             if ($data['name'] && $data['value']) {
                 FleximportConfig::set($data['name'], $data['value']);
             }
         }
         if (Request::get("new_name") && Request::get("new_value")) {
             FleximportConfig::set(Request::get("new_name"), Request::get("new_value"));
         }
     }
     $this->redirect("config/overview");
 }
Ejemplo n.º 28
0
 public static function dispatch($class)
 {
     if (!class_exists($class)) {
         include_once 'controllers/' . str_replace('_', '/', $class) . '.php';
     }
     $instance = new $class();
     $params = array_slice(func_get_args(), 1);
     $return = true;
     if (method_exists($instance, 'init')) {
         $return = call_user_func_array(array($instance, 'init'), $params);
     }
     if (!(true === $return)) {
         if (is_string($return) || $return instanceof Url) {
             Url::redirect($return);
         }
         return false;
     }
     $errors = array();
     if (Request::isPost()) {
         $validation = new Validate();
         if ($rules = $instance->validation()) {
             $validation->add($rules);
             $validation->validate();
         }
         if ($validation->valid()) {
             $return = $instance->post();
             if (!(false === $return)) {
                 if (is_string($return) || $return instanceof Url) {
                     Url::redirect($return);
                 }
                 return true;
             }
         }
         $errors = $validation->errors();
     }
     $return = $instance->get();
     if (!(false === $return)) {
         $return['errors'] = $errors;
         $view = new View($class, $return);
         $viewContent = $view->dispatch();
         return $viewContent;
     }
     return false;
 }
Ejemplo n.º 29
0
 public function forget($req, $res, $args)
 {
     if (!User::get()->is_guest) {
         return Router::redirect(Router::pathFor('home'), 'Already logged in');
     }
     if (Request::isPost()) {
         // Validate the email address
         $email = strtolower(Utils::trim(Input::post('req_email')));
         if (!Container::get('email')->is_valid_email($email)) {
             throw new Error(__('Invalid email'), 400);
         }
         $user = ModelAuth::get_user_from_email($email);
         if ($user) {
             // Load the "activate password" template
             $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/activate_password.tpl'));
             $mail_tpl = Container::get('hooks')->fire('controller.mail_tpl_password_forgotten', $mail_tpl);
             // The first row contains the subject
             $first_crlf = strpos($mail_tpl, "\n");
             $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8));
             $mail_message = trim(substr($mail_tpl, $first_crlf));
             // Do the generic replacements first (they apply to all emails sent out here)
             $mail_message = str_replace('<base_url>', Url::base() . '/', $mail_message);
             $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
             $mail_message = Container::get('hooks')->fire('controller.mail_message_password_forgotten', $mail_message);
             if ($user->last_email_sent != '' && time() - $user->last_email_sent < 3600 && time() - $user->last_email_sent >= 0) {
                 throw new Error(sprintf(__('Email flood'), intval((3600 - (time() - $user->last_email_sent)) / 60)), 429);
             }
             // Generate a new password and a new password activation code
             $new_password = Random::pass(12);
             $new_password_key = Random::pass(8);
             ModelAuth::set_new_password($new_password, $new_password_key, $user->id);
             // Do the user specific replacements to the template
             $cur_mail_message = str_replace('<username>', $user->username, $mail_message);
             $cur_mail_message = str_replace('<activation_url>', Url::base() . Router::pathFor('profileAction', ['id' => $user->id, 'action' => 'change_pass'], ['key' => $new_password_key]), $cur_mail_message);
             $cur_mail_message = str_replace('<new_password>', $new_password, $cur_mail_message);
             $cur_mail_message = Container::get('hooks')->fire('controller.cur_mail_message_password_forgotten', $cur_mail_message);
             Container::get('email')->feather_mail($email, $mail_subject, $cur_mail_message);
             return Router::redirect(Router::pathFor('home'), __('Forget mail') . ' <a href="mailto:' . Utils::escape(ForumSettings::get('o_admin_email')) . '">' . Utils::escape(ForumSettings::get('o_admin_email')) . '</a>.', 200);
         } else {
             throw new Error(__('No email match') . ' ' . Utils::escape($email) . '.', 400);
         }
     }
     View::setPageInfo(array('active_page' => 'login', 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Request pass')), 'required_fields' => array('req_email' => __('Email')), 'focus_element' => array('request_pass', 'req_email')))->addTemplate('login/password_forgotten.php')->display();
 }
Ejemplo n.º 30
0
 public function tablemapping_action($table_id)
 {
     PageLayout::setTitle(_("Datenmapping einstellen"));
     $this->table = new FleximportTable($table_id);
     Navigation::activateItem("/fleximport/process_" . $this->table['process_id']);
     if (Request::isPost()) {
         $tabledata = Request::getArray("tabledata");
         $tabledata = array_merge($this->table['tabledata'], $tabledata);
         $this->table['tabledata'] = $tabledata;
         $this->table->store();
         PageLayout::postMessage(MessageBox::success(_("Daten wurden gespeichert.")));
     }
     $datafield_object_types = array('User' => "user", 'Course' => "sem", 'CourseMember' => "usersemdata");
     $this->datafields = Datafield::findBySQL("object_type = :object_type", array('object_type' => $datafield_object_types[$this->table['import_type']]));
     if (Request::isAjax() && Request::isPost()) {
         $output = array('func' => "STUDIP.Fleximport.updateTable", 'payload' => array('table_id' => $table_id, 'name' => $this->table['name'], 'html' => $this->render_template_as_string("import/_table.php")));
         $this->response->add_header("X-Dialog-Execute", json_encode(studip_utf8encode($output)));
     }
 }