Ejemplo n.º 1
0
 /**
  * sets the proper $_SESSION var of userObj and redirects to user home page
  * 
  * @param ADALoggableUser $userObj user object to be used to set $_SESSION vars
  * @param boolean $remindMe true if remindme check box has been checked
  * @param string $language lang selection at login form: language to be set
  * @param Object $loginProviderObj login provider class used, null if none used 
  */
 public static function setSessionAndRedirect($userObj, $remindMe, $language, $loginProviderObj = null, $redirectURL = null)
 {
     if ($userObj->getStatus() == ADA_STATUS_REGISTERED) {
         /**
          * @author giorgio 12/dic/2013
          * when a user sucessfully logs in, regenerate her session id.
          * this fixes a quite big problem in the 'history_nodi' table
          */
         if (isset($remindMe) && intval($remindMe) > 0) {
             ini_set('session.cookie_lifetime', 60 * 60 * 24 * ADA_SESSION_LIFE_TIME);
             // day cookie lifetime
         }
         session_regenerate_id(true);
         $user_default_tester = $userObj->getDefaultTester();
         if (!MULTIPROVIDER && $userObj->getType() != AMA_TYPE_ADMIN) {
             if ($user_default_tester != $GLOBALS['user_provider']) {
                 // if the user is trying to login in a provider
                 // that is not his/her own,
                 // redirect to his/her own provider home page
                 $redirectURL = preg_replace("/(http[s]?:\\/\\/)(\\w+)[.]{1}(\\w+)/", "\$1" . $user_default_tester . ".\$3", $userObj->getHomePage());
                 header('Location:' . $redirectURL);
                 exit;
             }
         }
         // user is a ADAuser with status set to 0 OR
         // user is admin, author or switcher whose status is by default = 0
         $_SESSION['sess_user_language'] = $language;
         $_SESSION['sess_id_user'] = $userObj->getId();
         $GLOBALS['sess_id_user'] = $userObj->getId();
         $_SESSION['sess_id_user_type'] = $userObj->getType();
         $GLOBALS['sess_id_user_type'] = $userObj->getType();
         $_SESSION['sess_userObj'] = $userObj;
         /* unset $_SESSION['service_level'] to allow the correct label translatation according to user language */
         unset($_SESSION['service_level']);
         if ($user_default_tester !== NULL) {
             $_SESSION['sess_selected_tester'] = $user_default_tester;
             // sets var for non multiprovider environment
             $GLOBALS['user_provider'] = $user_default_tester;
         }
         if (!is_null($loginProviderObj)) {
             $_SESSION['sess_loginProviderArr']['className'] = get_class($loginProviderObj);
             $_SESSION['sess_loginProviderArr']['id'] = $loginProviderObj->getID();
             $loginProviderObj->addLoginToHistory($userObj->getId());
         }
         if (is_null($redirectURL)) {
             $redirectURL = $userObj->getHomePage();
         }
         header('Location:' . $redirectURL);
         exit;
     }
     return false;
 }
Ejemplo n.º 2
0
 public static function create(ADALoggableUser $userObj)
 {
     $user_types_Ar = array(AMA_TYPE_ADMIN => array(AMA_TYPE_TUTOR, AMA_TYPE_AUTHOR, AMA_TYPE_SWITCHER), AMA_TYPE_SWITCHER => array(AMA_TYPE_TUTOR, AMA_TYPE_STUDENT), AMA_TYPE_AUTHOR => array(), AMA_TYPE_TUTOR => array(AMA_TYPE_SWITCHER, AMA_TYPE_STUDENT), AMA_TYPE_STUDENT => array(AMA_TYPE_SWITCHER, AMA_TYPE_TUTOR));
     /**
      * @author giorgio 13/apr/2015
      * 
      * if userObj is a superTutor, add AMA_TYPE_TUTOR to the addressbook
      */
     if ($userObj->getType() == AMA_TYPE_TUTOR && $userObj->isSuper()) {
         $user_types_Ar[AMA_TYPE_TUTOR][] = AMA_TYPE_TUTOR;
     }
     $users_Ar = parent::fillAddressBook($userObj, $user_types_Ar);
     if ($users_Ar == FALSE) {
         return new CText('');
     }
     return parent::getAddressBook($userObj, $user_types_Ar, $users_Ar);
 }
Ejemplo n.º 3
0
 /**
  * Updates an existing user
  *
  * @param  ADAGenericUser $userObj
  * @param  $testers array
  * @return boolean
  */
 public static function setUser(ADALoggableUser $userObj, $new_testers = array(), $update_user_data = FALSE, $extraTableName = false)
 {
     $user_id = $userObj->getId();
     $testers = $userObj->getTesters();
     $testers_to_add = array();
     if (!is_array($testers)) {
         $testers = array();
     }
     if ($user_id == 0) {
         return FALSE;
     }
     $common_dh = AMA_Common_DataHandler::instance();
     $user_dataAr = $userObj->toArray();
     if ($update_user_data) {
         $result = $common_dh->set_user($user_id, $user_dataAr);
         if (AMA_Common_DataHandler::isError($result)) {
             //return ADA_SET_USER_ERROR;
         }
     }
     if ($update_user_data) {
         $idFromPublicTester = 0;
         foreach ($testers as $tester) {
             $tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester));
             //
             switch ($userObj->getType()) {
                 case AMA_TYPE_STUDENT:
                     /**
                      * @author giorgio
                      * if it's an extraTable I need set_student to return me the id of the inserted
                      * record in the table on DEFAULT that will be used as an id for all other providers
                      */
                     $result = $tester_dh->set_student($user_id, $user_dataAr, $extraTableName, $userObj, $idFromPublicTester);
                     break;
                 case AMA_TYPE_AUTHOR:
                     $result = $tester_dh->set_author($user_id, $user_dataAr);
                     break;
                 case AMA_TYPE_SUPERTUTOR:
                 case AMA_TYPE_TUTOR:
                     $result = $tester_dh->set_tutor($user_id, $user_dataAr);
                     break;
                 case AMA_TYPE_SWITCHER:
                     $result = $tester_dh->set_user($user_id, $user_dataAr);
                     break;
                 case AMA_TYPE_ADMIN:
                     $result = $tester_dh->set_user($user_id, $user_dataAr);
                     break;
             }
             if (AMA_DataHandler::isError($result)) {
                 if ($result->code == AMA_ERR_NOT_FOUND) {
                     $testers_to_add[] = $tester;
                 }
                 //return ADA_SET_USER_ERROR_TESTER;
             }
         }
     }
     // se sono qui, verifico se in new_testers ci sono dei tester nuovi e li associo all'utente
     $testers_to_add = array_merge($testers_to_add, array_diff($new_testers, $testers));
     $pwd = $common_dh->_get_user_pwd($user_id);
     if (AMA_DataHandler::isError($pwd)) {
         // if there is an error, we MUST insert a fake password in provider DB
         $pwd = sha1($user_id);
     }
     $user_dataAr['password'] = $pwd;
     foreach ($testers_to_add as $tester_to_add) {
         // aggiungi utente nella tabella utente del tester
         $tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($tester_to_add));
         // we have to use different functions for different user types
         switch ($userObj->getType()) {
             case AMA_TYPE_STUDENT:
                 $result = $tester_dh->add_student($user_dataAr);
                 $result = $tester_dh->set_student($user_id, $user_dataAr, $extraTableName, $userObj);
                 if ($userObj->hasExtra()) {
                     if (method_exists('ADAUser', 'getExtraTableName')) {
                         $tableName = ADAUser::getExtraTableName();
                         if (strlen($tableName) > 0) {
                             $tester_dh->set_student($user_id, $user_dataAr, $tableName, $userObj);
                         }
                     }
                     if (method_exists('ADAUser', 'getLinkedTables')) {
                         $linkedTables = ADAUser::getLinkedTables();
                         if (is_array($linkedTables) && count($linkedTables) > 0) {
                             foreach ($linkedTables as $tableName) {
                                 // force the record to be saved in the provider we're adding the user
                                 if (isset($user_dataAr[$tableName]) && is_array($user_dataAr[$tableName])) {
                                     foreach ($user_dataAr[$tableName] as $i => $notused) {
                                         $storedID = $user_dataAr[$tableName][$i][$tableName::getKeyProperty()];
                                         $user_dataAr[$tableName][$i][$tableName::getKeyProperty()] = 0;
                                         $user_dataAr[$tableName][$i]['_isSaved'] = 0;
                                         $result = $tester_dh->set_student($user_id, $user_dataAr, $tableName, $userObj, $storedID);
                                         if (!AMA_DB::isError($result)) {
                                             $user_dataAr[$tableName][$i]['_isSaved'] = 1;
                                         }
                                     }
                                     //$result = $tester_dh->set_student($user_id,$user_dataAr, $tableName, $userObj, $storedID);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case AMA_TYPE_AUTHOR:
                 $result = $tester_dh->add_author($user_dataAr);
                 break;
             case AMA_TYPE_SUPERTUTOR:
             case AMA_TYPE_TUTOR:
                 $result = $tester_dh->add_tutor($user_dataAr);
                 break;
             case AMA_TYPE_SWITCHER:
                 $result = $tester_dh->add_user($user_dataAr);
                 break;
             case AMA_TYPE_ADMIN:
                 $result = $tester_dh->add_user($user_dataAr);
                 break;
         }
         if (AMA_DataHandler::isError($result)) {
             //return ADA_SET_USER_ERROR_TESTER_ASSOCIATION;
         }
     }
     /*
      * If the user has subscribed to at least one tester, add the user
      * to the utente_tester table in common database.
      */
     foreach ($testers_to_add as $tester_to_add) {
         $testerHa = $common_dh->get_tester_info_from_pointer($tester_to_add);
         $tester_id = $testerHa[0];
         $res = $common_dh->add_user_to_tester($user_id, $tester_id);
         if (AMA_DataHandler::isError($res)) {
             if ($res->code != AMA_ERR_ADD and $res->code != AMA_ERR_UNIQUE_KEY) {
                 //return ADA_SET_USER_ERROR_TESTER;
                 return false;
             }
         } else {
             $userObj->addTester($tester_to_add);
         }
     }
     if (isset($result)) {
         return $result;
     }
 }