File modules/cms/action/user/UserAddtokenAction.class.php
Last commit: Mon Jan 6 22:48:11 2025 +0100 Jan Dankert New: Now it is possible to remove and create new login/api token for a user; new API authorization with the authorization scheme "api".
1 <?php 2 namespace cms\action\user; 3 use cms\action\Method; 4 use cms\action\UserAction; 5 use cms\base\Configuration; 6 use cms\base\Startup; 7 use language\Messages; 8 use security\Base2n; 9 use security\Password; 10 use util\Browser; 11 use util\exception\UIException; 12 use util\exception\ValidationException; 13 use util\Session; 14 15 /** 16 * Shows the login tokens of this user. 17 * 18 * @package cms\action\user 19 */ 20 class UserAddtokenAction extends UserAction implements Method { 21 22 public function view() { 23 24 // Creating a new random API token 25 $newToken = 26 // Token: Selector+Token 27 Password::randomHexString(24). 28 '.'. 29 Password::randomHexString(24); 30 31 32 $this->setTemplateVar('apitoken',$newToken ); 33 $this->setTemplateVar('apitokenHeader','Authorization: API '.$newToken ); 34 35 $browser = new Browser(); 36 $this->setTemplateVar('platform',$browser->platform); 37 $this->setTemplateVar('name' ,$browser->name ); 38 // Default: expires in 30 days 39 $this->setTemplateVar('expires' ,date('Y-m-d',time()+(30*24*60*60)) ); 40 } 41 42 public function post() { 43 44 $newToken = $this->request->getRequiredText('apitoken'); 45 $name = $this->request->getText('name' ); 46 $platform = $this->request->getText('platform'); 47 $expires = strtotime($this->request->getText('expires' )); 48 49 list($selector,$token)=explode('.',$newToken); 50 51 $this->user->addApiToken( $selector,$token,$platform,$name,$expires ); 52 $this->addNoticeFor($this->user,Messages::ADDED); 53 } 54 }
Downloadmodules/cms/action/user/UserAddtokenAction.class.php
History Mon, 6 Jan 2025 22:48:11 +0100 Jan Dankert New: Now it is possible to remove and create new login/api token for a user; new API authorization with the authorization scheme "api".