/**
  * Logs in a user.
  *
  * @param string $username
  * @param string $password
  * @return true if login is successful
  */
 public function loginUser($username, $password)
 {
     global $databaseURI;
     global $logicURI;
     // check if logged in in studip
     $studip = $this->checkUserInStudip($this->uid, $this->sid);
     $studipStatus = null;
     if ($studip == true) {
         ///Logger::Log("inStudip", LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         $url = "{$databaseURI}/user/user/{$username}";
         $message = null;
         $this->userData = http_get($url, false, $message);
         ///Logger::Log("ostepuUser_url: ".$url, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         ///Logger::Log("ostepuUser_message: ".$message, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         ///Logger::Log("ostepuUser_data: ".$this->userData, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         $this->userData = json_decode($this->userData, true);
         // check if user exists in our system
         if ($message != "404" && empty($this->userData) == false) {
             // save logged in uid
             $_SESSION['UID'] = $this->userData['id'];
             // refresh Session in UI and DB
             $refresh = $this->refreshSession();
             if (isset($_GET['vid']) && (!isset($_GET['cid']) || $this->cid === null)) {
                 // convert vid to cid
                 // create course if does not exist
                 $this->cid = $this->convertVidToCid($_GET['vid']);
                 ///Logger::Log("cid: ".$this->cid , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                 if ($this->cid === null) {
                     // create course
                     $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid);
                     if ($studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) {
                         ///Logger::Log("createCourse>>".$_GET['vid'] , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                         $courseObject = $this->getCourseInStudip($this->vid);
                         if ($courseObject !== null) {
                             $url = "{$logicURI}/course";
                             $courseObject = http_post_data($url, Course::encodeCourse($courseObject), false, $message);
                             if ($message === 201) {
                                 // new course was created
                                 $courseObject = Course::decodeCourse($courseObject);
                                 if ($courseObject !== null) {
                                     $this->cid = $courseObject->getId();
                                     $url = "{$databaseURI}/externalid";
                                     $externalId = ExternalId::createExternalId('S_' . $_GET['vid'], $this->cid);
                                     $externalId = http_post_data($url, ExternalId::encodeExternalId($externalId), false, $message);
                                     if ($message !== 201) {
                                         // create externalId fails, remove course
                                         $url = "{$logicURI}/course/course/" . $this->cid;
                                         http_delete($url, false, $message);
                                         $this->cid = null;
                                     }
                                     if ($this->cid !== null && $studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) {
                                         // redirect user to course settings
                                         /// ???
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!isset($this->cid) || $this->cid === null) {
                 set_error("unbekannte Veranstaltung!!!");
                 exit;
             }
             // get the courseStatus for given course
             $this->courseStatus = $this->findCourseStatus();
             ///Logger::Log("courseStatus: ".$this->courseStatus , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
             // if user has no status in course create it
             if (!isset($this->courseStatus)) {
                 if ($studipStatus === null) {
                     $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid);
                 }
                 if ($studipStatus !== null) {
                     ///Logger::Log("createCourseStatus" , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                     // check whether an registration is allowed
                     $courseData = $this->getCourseData($this->cid);
                     if ($courseData === null) {
                         // no course data
                         set_error("Keine Veranstaltung gefunden!");
                         exit;
                     }
                     if ($courseData->getSettings() !== null) {
                         $end = Course::containsSetting($courseData, 'RegistrationPeriodEnd');
                         if ($end !== null && $end != 0 && $end < time()) {
                             // no registration allowed
                             set_error("Eine Anmeldung ist nicht möglich!!! Ablaufdatum: " . date('d.m.Y - H:i', $end));
                             exit;
                         }
                     }
                     $CourseStatusResponse = $this->createCourseStatus($this->userData['id'], $this->cid, $studipStatus);
                     // set courseStatus to studipStatus only if status is created in DB successfully
                     if ($CourseStatusResponse == true) {
                         $this->courseStatus = $studipStatus;
                     }
                 }
             }
             return $refresh;
         } else {
             // get new user from studIP
             $newUser = $this->getUserInStudip($username);
             // if user is a valid user
             if ($newUser != "not found") {
                 ///Logger::Log("creatUser: "******"");
                 }
             }
         }
     }
     return false;
 }
Example #2
0
 public static function ExtractCourseStatus($data, $singleResult = false, $UserExtension = '', $CourseStatusExtension = '', $CourseExtension = '', $isResult = true)
 {
     // generates an assoc array of a user by using a defined list of its
     // attributes
     $user = DBJson::getObjectsByAttributes($data, User::getDBPrimaryKey(), User::getDBConvert(), $UserExtension);
     // generates an assoc array of course stats by using a defined list of
     // its attributes
     $courseStatus = DBJson::getObjectsByAttributes($data, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert(), $CourseStatusExtension);
     // generates an assoc array of courses by using a defined list of
     // its attributes
     $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension);
     // concatenates the course stats and the associated courses
     $res = DBJson::concatObjectListsSingleResult($data, $courseStatus, CourseStatus::getDBPrimaryKey(), CourseStatus::getDBConvert()['CS_course'], $courses, Course::getDBPrimaryKey(), $CourseExtension, $CourseStatusExtension);
     // concatenates the users and the associated course stats
     $res = DBJson::concatResultObjectLists($data, $user, User::getDBPrimaryKey(), User::getDBConvert()['U_courses'], $res, CourseStatus::getDBPrimaryKey(), $CourseStatusExtension, $UserExtension);
     if ($isResult) {
         // to reindex
         // $res = array_merge($res);
         $res = CourseStatus::decodeCourseStatus($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Example #3
0
 /**
  * @todo Receive the names from the database instead of defining it here.
  */
 public function getStatusName($courseStatus)
 {
     $statusNames = CourseStatus::getStatusDefinition();
     return $statusNames[$courseStatus];
 }