File modules/cms/action/login/LoginRegistercodeAction.class.php
Last commit: Sun Mar 14 23:51:49 2021 +0100 Jan Dankert Refactoring: Using the ValidationException where possible.
1 <?php 2 namespace cms\action\login; 3 use cms\action\LoginAction; 4 use cms\action\Method; 5 use cms\base\Configuration; 6 use cms\base\DB; 7 use cms\model\User; 8 use language\Messages; 9 use util\exception\ValidationException; 10 use util\Session; 11 12 13 class LoginRegistercodeAction extends LoginAction implements Method { 14 public function view() { 15 $conf = Configuration::rawConfig(); 16 17 $this->setTemplateVar( 'dbids',$this->getSelectableDatabases() ); 18 19 $db = DB::get(); 20 if ( $db ) 21 $this->setTemplateVar('actdbid',$db->id); 22 else 23 $this->setTemplateVar('actdbid',$conf['database-defaults']['default-id']); 24 25 26 27 } 28 29 30 31 public function post() { 32 $conf = Configuration::rawConfig(); 33 34 $origRegisterCode = Session::get( Session::KEY_REGISTER_CODE ); 35 $inputRegisterCode = $this->request->getText('code'); 36 37 if ( $origRegisterCode != $inputRegisterCode ) 38 throw new ValidationException('code', Messages::CODE_NOT_MATCH ); // Validation code does not match. 39 40 // Best?tigungscode stimmt ?berein. 41 // Neuen Benutzer anlegen. 42 43 $user = User::loadWithName( $this->request->getRequiredText('username'),User::AUTH_TYPE_INTERNAL ); 44 if ( $user ) 45 throw new ValidationException('username',Messages::USER_ALREADY_IN_DATABASE ); 46 47 if ( strlen($this->request->getText('password')) < $conf['security']['password']['min_length'] ) 48 throw new ValidationException('password', Messages::PASSWORD_MINLENGTH/*,[ 49 'minlength'=>$conf['security']['password']['min_length'] 50 ]*/); 51 52 $newUser = new User(); 53 $newUser->name = $this->request->getText('username'); 54 $newUser->fullname = $newUser->name; 55 $newUser->mail = Session::get( Session::KEY_REGISTER_MAIL ); 56 57 $newUser->persist(); 58 59 $newUser->setPassword( $this->request->getText('password'),true ); 60 61 $this->addNoticeFor( $newUser,Messages::USER_ADDED); 62 } 63 }
Downloadmodules/cms/action/login/LoginRegistercodeAction.class.php
History 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. Thu, 19 Nov 2020 14:49:58 +0100 Jan Dankert Fix: Action::addNotice() is replaced by Action::addNoticeFor() 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.