UserPwAction.class.php (1584B)
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\model\User; 7 use language\Messages; 8 use security\Password; 9 use util\exception\ValidationException; 10 use util\mail\Mail; 11 12 13 class UserPwAction extends UserAction implements Method { 14 15 public function view() { 16 $this->setTemplateVar('enabled',$this->user->type == User::AUTH_TYPE_INTERNAL ); 17 $this->setTemplateVar('mail' ,(boolean) $this->user->mail ); 18 19 $this->setTemplateVar('password_proposal', Password::createPassword() ); 20 } 21 22 23 public function post() { 24 $password = $this->request->getText('password'); 25 26 if ( !$password ) 27 $password = $this->request->getText('password_proposal'); 28 29 if ( strlen($password) < Configuration::subset(['security','password'])->get('min_length',8) ) 30 throw new ValidationException('password',Messages::PASSWORD_MINLENGTH ); 31 32 $this->user->setPassword($password,!$this->request->isTrue('timeout') ); // Kennwort setzen 33 34 // E-Mail mit dem neuen Kennwort an Benutzer senden 35 if ( $this->request->isTrue('email') && 36 $this->user->mail && // user has an e-mail. 37 Configuration::subset('mail')->is('enabled',true) 38 ) { 39 $eMail = new Mail($this->user->mail, Messages::MAIL_SUBJECT_PASSWORD_NEW,Messages::MAIL_TEXT_PASSWORD_NEW); 40 $eMail->setVar('name' ,$this->user->getName()); 41 $eMail->setVar('password',$password ); 42 $eMail->send(); 43 $this->addNoticeFor( $this->user, Messages::MAIL_SENT); 44 } 45 46 $this->addNoticeFor($this->user, Messages::SAVED); 47 48 } 49 }