openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ProfilePwAction.class.php (1922B)


      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\model\User;
      7 use language\Messages;
      8 use util\exception\ValidationException;
      9 use util\mail\Mail;
     10 
     11 class ProfilePwAction extends ProfileAction implements Method {
     12     public function view() {
     13 		// Kennwortänderung funktioniert natürlich nur in der internen Datenbank.
     14 		//
     15 		// Hier wird festgestellt, ob der Benutzer sich über die interne Datenbank angemeldet hat.
     16 		// Nur dann kann man auch sein Kennwort ändern.
     17 		$user             = $this->currentUser;
     18 		$pwchangePossible = $user->type == User::AUTH_TYPE_INTERNAL;
     19 		$this->setTemplateVar('pwchange_enabled', $pwchangePossible);
     20     }
     21 
     22 
     23 
     24     public function post() {
     25 
     26 		$pwMinLength = Configuration::subset(['security','password'])->get('min_length',10);
     27 
     28 		if	( $this->user->type != User::AUTH_TYPE_INTERNAL )
     29 			throw new \LogicException('password change only possible for internal users.');
     30 
     31 		if	( ! $this->user->checkPassword( $this->request->getText('act_password') ) )
     32 			throw new ValidationException('act_password');
     33 
     34 		if	( $this->request->getText('password1') == '' )
     35 			throw new ValidationException('password1');
     36 
     37 		if ( $this->request->getText('password1') != $this->request->getText('password2') )
     38 			throw new ValidationException('password2', Messages::PASSWORDS_DO_NOT_MATCH);
     39 
     40 		if ( strlen($this->request->getText('password1'))<$pwMinLength )
     41 			throw new ValidationException('password1',Messages::PASSWORD_MINLENGTH,array('minlength'=> $pwMinLength));
     42 
     43 		$this->user->setPassword( $this->request->getText('password1') );
     44 		$this->addNoticeFor( $this->user,Messages::SAVED);
     45 
     46 		// Send mail to user to inform about the new password.
     47 		if   ( $this->user->mail ) {
     48 			$mail = new Mail( $this->user->mail,Messages::MAIL_PASSWORD_CHANGE_SUCCESS_SUBJECT,Messages::MAIL_PASSWORD_CHANGE_SUCCESS);
     49 			$mail->send();
     50 		}
     51     }
     52 }