[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/Webservices/Custom/ -> ChangePassword.php (source)

   1  <?php
   2  
   3  /*+*******************************************************************************
   4   *   The contents of this file are subject to the vtiger CRM Public License Version 1.0
   5   *   ("License"); You may not use this file except in compliance with the License
   6   *   The Original Code is:  vtiger CRM Open Source
   7   *   The Initial Developer of the Original Code is vtiger.
   8   *   Portions created by vtiger are Copyright (C) vtiger.
   9   *   All Rights Reserved.
  10   * 
  11   *********************************************************************************/
  12  
  13  /**
  14   * @author Musavir Ahmed Khan<musavir at vtiger.com>
  15   */
  16  
  17  /**
  18   *
  19   * @param WebserviceId $id
  20   * @param String $oldPassword
  21   * @param String $newPassword
  22   * @param String $confirmPassword
  23   * @param Users $user 
  24   * 
  25   */
  26  function vtws_changePassword($id, $oldPassword, $newPassword, $confirmPassword, $user) {
  27      vtws_preserveGlobal('current_user',$user);
  28      $idComponents = vtws_getIdComponents($id);
  29      if($idComponents[1] == $user->id || is_admin($user)) {
  30          $newUser = new Users();
  31          $newUser->retrieve_entity_info($idComponents[1], 'Users');
  32          if(!is_admin($user)) {
  33              if(empty($oldPassword)) {
  34                  throw new WebServiceException(WebServiceErrorCode::$INVALIDOLDPASSWORD, 
  35                      vtws_getWebserviceTranslatedString('LBL_'.
  36                              WebServiceErrorCode::$INVALIDOLDPASSWORD));
  37              }
  38              if(!$user->verifyPassword($oldPassword)) {
  39                  throw new WebServiceException(WebServiceErrorCode::$INVALIDOLDPASSWORD, 
  40                      vtws_getWebserviceTranslatedString('LBL_'.
  41                              WebServiceErrorCode::$INVALIDOLDPASSWORD));
  42              }
  43          }
  44          if(strcmp($newPassword, $confirmPassword) === 0) {
  45              $db = PearDatabase::getInstance();
  46              $db->dieOnError = true;
  47              $db->startTransaction();
  48              $success = $newUser->change_password($oldPassword, $newPassword, false);
  49              $error = $db->hasFailedTransaction();
  50              $db->completeTransaction();
  51              if($error) {
  52                  throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, 
  53                      vtws_getWebserviceTranslatedString('LBL_'.
  54                              WebServiceErrorCode::$DATABASEQUERYERROR));
  55              }
  56              if(!$success) {
  57                  throw new WebServiceException(WebServiceErrorCode::$CHANGEPASSWORDFAILURE, 
  58                      vtws_getWebserviceTranslatedString('LBL_'.
  59                              WebServiceErrorCode::$CHANGEPASSWORDFAILURE));
  60              }
  61          } else {
  62              throw new WebServiceException(WebServiceErrorCode::$CHANGEPASSWORDFAILURE, 
  63                      vtws_getWebserviceTranslatedString('LBL_'.
  64                              WebServiceErrorCode::$CHANGEPASSWORDFAILURE));
  65          }
  66          VTWS_PreserveGlobal::flush();
  67          return array('message' => 'Changed password successfully');
  68      }
  69  }
  70  
  71  
  72  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1