openrat-cms

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

ProfileMailAction.class.php (1438B)


      1 <?php
      2 namespace cms\action\profile;
      3 use cms\action\Method;
      4 use cms\action\ProfileAction;
      5 use language\Messages;
      6 use logger\Logger;
      7 use util\exception\ValidationException;
      8 use util\mail\Mail;
      9 use util\Session;
     10 use util\text\TextMessage;
     11 
     12 class ProfileMailAction extends ProfileAction implements Method {
     13 
     14     public function view() {
     15     }
     16 
     17     public function post() {
     18 		srand ((double)microtime()*1000003);
     19 		$code = rand(); // Zufalls-Freischaltcode erzeugen
     20 		$newMail = $this->request->getText('mail');
     21 
     22 		if	( !$newMail )
     23 		{
     24 			// Keine E-Mail-Adresse eingegeben.
     25 			throw new ValidationException('mail');
     26 		}
     27 		else
     28 		{
     29 			// Der Freischaltcode wird in der Sitzung gespeichert.
     30 			Session::set( Session::KEY_MAIL_CHANGE_CODE,$code   );
     31 			Session::set( Session::KEY_MAIL_CHANGE_MAIL,$newMail);
     32 			
     33 			// E-Mail an die neue Adresse senden.
     34 			$mail = new Mail($newMail, Messages::MAIL_SUBJECT_MAIL_CHANGE_CODE,Messages::MAIL_TEXT_MAIL_CHANGE_CODE);
     35 			$mail->setVar('code',$code                 );
     36 			$mail->setVar('name',$this->user->getName());
     37 
     38 			try {
     39 				$mail->send();
     40 				$this->addNoticeFor( $this->user, Messages::MAIL_SENT);
     41 			} catch( \Exception $e ) {
     42 				Logger::warn( new \Exception( TextMessage::create('Mail could not be sent for user ${name} with the new email adress ${mail} ',['name'=>$this->user->name,'mail'=>$newMail]),0,$e) );
     43 				$this->addErrorFor($this->user, Messages::MAIL_NOT_SENT );
     44 			}
     45 		}
     46     }
     47 }