File modules/cms/action/profile/ProfileEditAction.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\action\profile; 3 use cms\action\Method; 4 use cms\action\ProfileAction; 5 use cms\base\Configuration; 6 use cms\base\Startup; 7 use language\Language; 8 use language\Messages; 9 use security\Base2n; 10 use util\Request; 11 use util\Session; 12 13 class ProfileEditAction extends ProfileAction implements Method { 14 public function view() { 15 $issuer = urlencode(Configuration::subset('application')->get('operator',Startup::TITLE)); 16 $account = $this->user->name.'@'.$_SERVER['SERVER_NAME']; 17 18 $base32 = new Base2n(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', FALSE, TRUE, TRUE); 19 $secret = $base32->encode(hex2bin($this->user->otpSecret)); 20 $counter = $this->user->hotpCount; 21 22 $this->setTemplateVars( $this->user->getProperties() ); 23 24 $this->setTemplateVar( 'allstyles',$this->user->getAvailableStyles() ); 25 26 $this->setTemplateVar('timezone_list',array_combine(timezone_identifiers_list(),timezone_identifiers_list()) ); 27 28 $languageList = []; 29 30 foreach( Messages::$AVAILABLE_LANGUAGES as $languageIsoCode) 31 { 32 $language = (new Language)->getLanguage($languageIsoCode); 33 $label = $language[ Messages::SELF_NAME ]; 34 $languageList[ $languageIsoCode ] = $label; 35 } 36 $this->setTemplateVar('language_list',$languageList ); 37 38 $this->setTemplateVars( 39 $this->user->getProperties() + 40 array('totpSecretUrl' => "otpauth://totp/{$issuer}:{$account}?secret={$secret}&issuer={$issuer}", 41 'hotpSecretUrl' => "otpauth://hotp/{$issuer}:{$account}?secret={$secret}&issuer={$issuer}&counter={$counter}" 42 ) 43 ); 44 45 46 } 47 48 49 /** 50 * Saving the user profile. 51 * 52 * @return void 53 */ 54 public function post() { 55 56 $this->request->handleText('fullname',function($value) { 57 $this->user->fullname = $value; 58 }); 59 60 $this->request->handleText('tel',function($value) { 61 $this->user->tel = $value; 62 }); 63 64 $this->request->handleText('desc',function($value) { 65 $this->user->desc = $value; 66 }); 67 68 $this->request->handleText('style',function($value) { 69 $this->user->style = $value; 70 }); 71 72 $this->request->handleText('language',function($value) { 73 $this->user->language = $value; 74 $this->setLanguage($value); // Change language immediately 75 }); 76 77 $this->request->handleText('timezone',function($value) { 78 $this->user->timezone = $value; 79 }); 80 81 $this->request->handleBool('hotp',function($value) { 82 $this->user->hotp = $value; 83 }); 84 85 $this->request->handleBool('totp',function($value) { 86 $this->user->totp = $value; 87 }); 88 89 // Overwrite user in session with new settings. 90 Request::setUser( $this->user ); 91 92 $this->user->persist(); 93 $this->addNoticeFor( $this->user,Messages::SAVED); 94 } 95 }
Downloadmodules/cms/action/profile/ProfileEditAction.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. Wed, 9 Mar 2022 13:28:52 +0100 dankert Refactoring: Checkbox values are always sent to the server. In the actions we must test the value with 'isTrue()' Wed, 9 Mar 2022 02:12:03 +0100 dankert New: Only save a property if it is send by the client. This is useful using a API, so not sent properties will not be deleted. Wed, 9 Mar 2022 01:57:45 +0100 dankert Fix: Do not write the language to a cookie. Wed, 9 Mar 2022 00:53:10 +0100 dankert Fix: Setting the correct timezone from the user property. Sun, 14 Mar 2021 23:51:49 +0100 Jan Dankert Refactoring: Using the ValidationException where possible. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.