[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/user/ -> forgotpassword.php (source)

   1  <?php
   2  //
   3  // Created on: <13-íÁÒ-2003 13:06:18 sp>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  /*! \file forgotpassword.php
  28  */
  29  
  30  include_once ( "lib/ezutils/classes/ezhttptool.php" );
  31  include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
  32  include_once ( "kernel/classes/datatypes/ezuser/ezforgotpassword.php" );
  33  
  34  
  35  include_once ( "kernel/common/template.php" );
  36  $tpl =& templateInit();
  37  $tpl->setVariable( 'generated', false );
  38  $tpl->setVariable( 'wrong_email', false );
  39  $tpl->setVariable( 'link', false );
  40  $tpl->setVariable( 'wrong_key', false );
  41  
  42  $http =& eZHTTPTool::instance();
  43  $module =& $Params["Module"];
  44  $hashKey =& $Params["HashKey"];
  45  $ini =& eZINI::instance();
  46  
  47  if ( strlen( $hashKey ) == 32 )
  48  {
  49      $forgotPasswdObj = eZForgotPassword::fetchByKey( $hashKey );
  50      if ( $forgotPasswdObj )
  51      {
  52          $user = eZUser::fetch( $forgotPasswdObj->attribute( 'user_id' ) );
  53          $email = $user->attribute( 'email' );
  54  
  55          $ini =& eZINI::instance();
  56          $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" );
  57          $password = eZUser::createPassword( $passwordLength );
  58          $passwordConfirm = $password;
  59  
  60          $userToSendEmail =& $user;
  61          $user->setInformation( $user->id(), $user->attribute( 'login' ), $email, $password, $passwordConfirm );
  62  
  63          $db =& eZDB::instance();
  64          $db->begin();
  65  
  66          $user->store();
  67  
  68          include_once ( "kernel/common/template.php" );
  69          include_once ( 'lib/ezutils/classes/ezmail.php' );
  70          include_once ( 'lib/ezutils/classes/ezmailtransport.php' );
  71  
  72          $receiver = $email;
  73          $mail = new eZMail();
  74          if ( !$mail->validate( $receiver ) )
  75          {
  76          }
  77          $tpl =& templateInit();
  78  
  79          $tpl->setVariable( 'user', $userToSendEmail );
  80          $tpl->setVariable( 'object', $userToSendEmail->attribute( 'contentobject' ) );
  81          $tpl->setVariable( 'password', $password );
  82  
  83          eZDebug::writeDebug( $password, "New Password" );
  84          $templateResult =& $tpl->fetch( 'design:user/forgotpasswordmail.tpl' );
  85          $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
  86          if ( !$emailSender )
  87              $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );
  88          $mail->setSender( $emailSender );
  89          $mail->setReceiver( $receiver );
  90          $subject = ezi18n( 'kernel/user/register', 'Registration info' );
  91          if ( $tpl->hasVariable( 'subject' ) )
  92              $subject = $tpl->variable( 'subject' );
  93          $mail->setSubject( $subject );
  94          $mail->setBody( $templateResult );
  95          $mailResult = eZMailTransport::send( $mail );
  96          $tpl->setVariable( 'generated', true );
  97          $tpl->setVariable( 'email', $email );
  98          $forgotPasswdObj->remove();
  99          $db->commit();
 100      }
 101      else
 102      {
 103          $tpl->setVariable( 'wrong_key', true );
 104      }
 105  }
 106  else if ( strlen( $hashKey ) > 4 )
 107  {
 108      $tpl->setVariable( 'wrong_key', true );
 109  }
 110  
 111  if ( $module->isCurrentAction( "Generate" ) )
 112  {
 113      $ini =& eZINI::instance();
 114      $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" );
 115      $password = eZUser::createPassword( $passwordLength );
 116      $passwordConfirm = $password;
 117      eZDebug::writeDebug( $password, "New Password" );
 118  
 119  //    $http->setSessionVariable( "GeneratedPassword", $password );
 120  
 121      if ( $module->hasActionParameter( "Email" ) )
 122      {
 123          $email = $module->actionParameter( "Email" );
 124          if ( trim( $email ) != "" )
 125          {
 126              $users = eZPersistentObject::fetchObjectList( eZUser::definition(),
 127                                                         null,
 128                                                         array( 'email' => $email ),
 129                                                         null,
 130                                                         null,
 131                                                         true );
 132          }
 133          if ( count($users) > 0 )
 134          {
 135              $user =& $users[0];
 136              $time = time();
 137              $hashKey = md5( $time . ":" . mt_rand() );
 138              $forgotPasswdObj = eZForgotPassword::createNew( $user->id(), $hashKey, $time );
 139              $forgotPasswdObj->store();
 140  
 141              $userToSendEmail =& $user;
 142              include_once ( "kernel/common/template.php" );
 143              include_once ( 'lib/ezutils/classes/ezmail.php' );
 144              include_once ( 'lib/ezutils/classes/ezmailtransport.php' );
 145              $receiver = $email;
 146  
 147              $mail = new eZMail();
 148              if ( !$mail->validate( $receiver ) )
 149              {
 150              }
 151              $tpl =& templateInit();
 152              $tpl->setVariable( 'user', $userToSendEmail );
 153              $tpl->setVariable( 'object', $userToSendEmail->attribute( 'contentobject' ) );
 154              $tpl->setVariable( 'password', $password );
 155              $tpl->setVariable( 'link', true );
 156              $tpl->setVariable( 'hash_key', $hashKey );
 157              eZDebug::writeDebug( $password, "New Password" );
 158              include_once ( 'lib/ezutils/classes/ezhttptool.php' );
 159              $http =& eZHTTPTool::instance();
 160              $http->UseFullUrl = true;
 161              $templateResult =& $tpl->fetch( 'design:user/forgotpasswordmail.tpl' );
 162              $http->UseFullUrl = false;
 163              $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
 164              if ( !$emailSender )
 165                  $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );
 166              $mail->setSender( $emailSender );
 167              $mail->setReceiver( $receiver );
 168              $subject = ezi18n( 'kernel/user/register', 'Registration info' );
 169              if ( $tpl->hasVariable( 'subject' ) )
 170                  $subject = $tpl->variable( 'subject' );
 171              $mail->setSubject( $subject );
 172              $mail->setBody( $templateResult );
 173              $mailResult = eZMailTransport::send( $mail );
 174              $tpl->setVariable( 'email', $email );
 175  
 176          }
 177          else
 178          {
 179              $tpl->setVariable( 'wrong_email', $email );
 180          }
 181      }
 182  }
 183  
 184  $Result = array();
 185  $Result['content'] =& $tpl->fetch( 'design:user/forgotpassword.tpl' );
 186  $Result['path'] = array( array( 'text' => ezi18n( 'kernel/user', 'User' ),
 187                                  'url' => false ),
 188                           array( 'text' => ezi18n( 'kernel/user', 'Forgot password' ),
 189                                  'url' => false ) );
 190  
 191  if ( $ini->variable( 'SiteSettings', 'LoginPage' ) == 'custom' )
 192  {
 193      $Result['pagelayout'] = 'loginpagelayout.tpl';
 194  }
 195  
 196  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7