File modules/cms/ui/action/index/IndexShowAction.class.php

Last commit: Fri Apr 15 14:51:22 2022 +0200	dankert	Refactoring: User,Config and Database info is now stored in the Request, because so there is no session required for clients which are using Basic Authorization.
1 <?php 2 namespace cms\ui\action\index; 3 use cms\action\Method; 4 use cms\model\User; 5 use cms\ui\action\IndexAction; 6 use cms\ui\themes\ThemeStyle; 7 use language\Messages; 8 use util\Html; 9 use util\Session; 10 use util\UIUtils; 11 use cms\base\Configuration as C; 12 use cms\action\RequestParams; 13 use cms\auth\Auth; 14 use cms\auth\AuthRunner; 15 use cms\base\Configuration; 16 use cms\base\Startup; 17 use cms\model\BaseObject; 18 use cms\model\Project; 19 use cms\model\Value; 20 use cms\ui\themes\Theme; 21 use Exception; 22 use util\json\JSON; 23 use logger\Logger; 24 use util\Less; 25 use \util\exception\ObjectNotFoundException; 26 class IndexShowAction extends IndexAction implements Method { 27 28 public function view() { 29 30 $this->addContentSecurityPolicy(); 31 32 $user = $this->currentUser; 33 34 // Is a user logged in? 35 if ( !is_object($user) ) 36 { 37 // Lets try an auto login. 38 $this->tryAutoLogin(); 39 40 $user = $this->currentUser; 41 } 42 43 $configLastModificationTime = C::subset('config')->get('last_modification_time', 0); 44 45 if ( $user ) 46 $this->lastModified( max( $user->loginDate, $configLastModificationTime) ); 47 else 48 $this->lastModified( $configLastModificationTime ); 49 50 // Theme für den angemeldeten Benuter ermitteln 51 $style = $this->getUserStyle($user); 52 53 $this->setTemplateVar('style',$style ); 54 55 $this->setTemplateVar('scriptLink', $this->getScriptLink() ); 56 $this->setTemplateVar('scriptModuleLink',$this->getScriptModuleLink() ); 57 $this->setTemplateVar('jsExt' ,(PRODUCTION?'.min.js':'.js') ); 58 $this->setTemplateVar('styleLink' , $this->getStyleLink() ); 59 60 $this->setTemplateVar('themeStyleLink', Html::url('index','themestyle',0,['style'=>$style]) ); 61 $this->setTemplateVar('manifestLink' , Html::url('index','manifest',0,['output'=>'json'] ) ); 62 63 $themeStyle = new ThemeStyle( Configuration::subset('style')->get($style,[]) ); // user style config 64 65 // Theme base color for smartphones colorizing their status bar. 66 $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($themeStyle->getThemeColor())); 67 68 $messageOfTheDay = C::subset('login')->get('motd',''); 69 70 if ( $messageOfTheDay ) 71 $this->addInfoFor( new User(),Messages::MOTD,array('motd' => $messageOfTheDay) ); 72 73 if ( DEVELOPMENT ) 74 $this->addInfoFor( new User(),Messages::DEVELOPMENT_MODE ); 75 76 $this->setTemplateVar('favicon_url', C::subset('theme')->get('favicon','modules/cms/ui/themes/default/images/openrat-logo.ico') ); 77 78 $vars = $this->getResponse()->getOutputData(); 79 $this->setTemplateVar( 'notices',$vars['notices'] ); // will be extracted in the included template file. 80 $this->setTemplateVar( 'charset','UTF-8' ); 81 82 $app = C::subset('application'); 83 $appName = $app->get('name' ); 84 $appOperator = $app->get('operator'); 85 $this->setTemplateVar( 'defaultTitle', $appName.(($appOperator!=$appName)?' - '.$appOperator:'')); 86 87 $this->setTemplateVar('language',C::subset('language')->get('language_code') ); 88 } 89 90 91 public function post() { 92 } 93 94 95 /** 96 * Gets CSS file for displaying the UI. 97 * 98 * @return string 99 */ 100 protected function getStyleLink() 101 { 102 // Ok, for now there is only 1 CSS file, which contains all UI styles. 103 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::STYLE_MINIFIED_FILENAME:Theme::STYLE_FILENAME); 104 } 105 106 107 108 /** 109 * Gets JS file for displaying the UI. 110 * 111 * @return string 112 * @deprecated 113 */ 114 protected function getScriptLink() 115 { 116 return Startup::THEMES_DIR . 'default/'.(PRODUCTION?Theme::SCRIPT_MINIFIED_FILENAME:Theme::SCRIPT_FILENAME); 117 } 118 119 /** 120 * Gets JS file for displaying the UI. 121 * 122 * @return string 123 */ 124 protected function getScriptModuleLink() 125 { 126 return Startup::THEMES_DIR . 'default/script/openrat/init.'.(PRODUCTION?'min.':'').'js'; 127 } 128 129 130 131 132 protected function tryAutoLogin() 133 { 134 $username = AuthRunner::getUsername('autologin'); 135 136 if ( $username ) 137 { 138 try 139 { 140 $user = User::loadWithName( $username,User::AUTH_TYPE_INTERNAL ); 141 $user->setCurrent(); 142 // Do not update the login timestamp, because this is a readonly request. 143 Logger::info('auto-login for user '.$username); 144 } 145 catch( ObjectNotFoundException $e ) 146 { 147 Logger::warn('Username for autologin does not exist: '.$username); 148 } 149 } 150 } 151 152 153 }
Download modules/cms/ui/action/index/IndexShowAction.class.php
History Fri, 15 Apr 2022 14:51:22 +0200 dankert Refactoring: User,Config and Database info is now stored in the Request, because so there is no session required for clients which are using Basic Authorization. Sat, 19 Mar 2022 00:09:47 +0100 dankert Refactoring: Outputs are setting their content-type themself. Sun, 13 Feb 2022 23:35:26 +0100 dankert Refactoring: New class "Response" which stores all output information. Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments. Sat, 27 Mar 2021 10:40:59 +0100 Jan Dankert Only generate the actual necessary theme style. Wed, 17 Mar 2021 22:27:33 +0100 Jan Dankert Refactoring: Using ES6-Modules (experimental) Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Wed, 10 Feb 2021 22:04:26 +0100 Jan Dankert Provide the theme configuration through a class. Mon, 8 Feb 2021 23:04:22 +0100 Jan Dankert New: A sidebar with sticky buttons as a shortcut to some methods. Wed, 18 Nov 2020 20:23:57 +0100 Jan Dankert Cleaning up the UI actions. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.