Exemplo n.º 1
0
 public static function authenticate($username, $password)
 {
     if (!empty($username) && ($authSource = AuthUserTable::getAuthSource($username))) {
         Console::debug("Found authentication source {$authSource} for {$username}");
         $driverList = array(AuthDriverManager::getDriver($authSource));
     } else {
         // avoid issues with session collision when many users connect from
         // the same computer at the same time with the same browser session !
         if (AuthUserTable::userExists($username)) {
             self::setFailureMessage(get_lang("There is already an account with this username."));
             return false;
         }
         $authSource = null;
         $driverList = AuthDriverManager::getRegisteredDrivers();
     }
     foreach ($driverList as $driver) {
         $driver->setAuthenticationParams($username, $password);
         if ($driver->authenticate()) {
             $uid = AuthUserTable::registered($username, $driver->getAuthSource());
             if ($uid) {
                 if ($driver->userUpdateAllowed()) {
                     $userAttrList = $driver->getFilteredUserData();
                     if (isset($userAttrList['loginName'])) {
                         $newUserName = $userAttrList['loginName'];
                         if (!get_conf('claro_authUsernameCaseSensitive', true)) {
                             $newUsername = strtolower($newUserName);
                             $username = strtolower($username);
                         }
                         // avoid session collisions !
                         if ($username != $newUserName) {
                             Console::error("EXTAUTH ERROR : try to overwrite an existing user {$username} with another one" . var_export($userAttrList, true));
                         } else {
                             AuthUserTable::updateUser($uid, $userAttrList);
                             Console::info("EXTAUTH INFO : update user {$uid} {$username} with " . var_export($userAttrList, true));
                         }
                     } else {
                         Console::error("EXTAUTH ERROR : no loginName given for user {$username} by authSource " . $driver->getAuthSource());
                     }
                 }
                 return Claro_CurrentUser::getInstance($uid, true);
             } elseif ($driver->userRegistrationAllowed()) {
                 // duplicate code here to avoid issue with multiple requests on a busy server !
                 if (AuthUserTable::userExists($username)) {
                     self::setFailureMessage(get_lang("There is already an account with this username."));
                     return false;
                 }
                 $uid = AuthUserTable::createUser($driver->getUserData());
                 return Claro_CurrentUser::getInstance($uid, true);
             }
         } elseif ($authSource) {
             self::setFailureMessage($driver->getFailureMessage());
         }
     }
     // authentication failed
     return false;
 }
 /**
  * Start publishing.
  *
  */
 public function publish()
 {
     if ($this->options->all) {
         $this->console->info('Loading all application files...');
         $this->publishAllFiles();
     } else {
         $this->publishFiles();
         $this->checkRequiredFolders();
         $this->publishRootFiles();
     }
     $this->console->info('Publishing Complete!');
 }
Exemplo n.º 3
0
 /**
  * Create the admin superuser.
  *
  * @return void
  */
 protected function createUser($options = array())
 {
     try {
         if (!is_null($options) && in_array('first', $options) && in_array('last', $options) && in_array('email', $options) && in_array('password', $options)) {
             User::create(['first_name' => $options['first'], 'last_name' => $options['last'], 'email' => $options['email'], 'password' => $options['password'], 'is_superuser' => true, 'key' => str_random(32)]);
         } else {
             $this->console->info('=====LETS CREATE AN ADMIN SUPERUSER=====');
             $firstName = $this->console->ask('What is the admin\'s first name?');
             $lastName = $this->console->ask('What is the admin\'s last name?');
             $email = $this->console->ask('What is the admin\'s email address?');
             $password = $this->console->secret('Choose a password, and make it strong.');
             User::create(['first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'password' => $password, 'is_superuser' => true, 'key' => str_random(21)]);
             $this->console->info('=====ADMIN SUPERUSER CREATED=====');
             $this->console->info('Nice! You can now login to your application with the superuser email and password.');
         }
     } catch (Exception $e) {
         $this->console->error('Whoops! Something went wrong trying to create your user.');
         $this->console->error('=====EXCEPTION START=====');
         $this->console->error($e);
         $this->console->error('=====EXCEPTION END=====');
     }
 }
Exemplo n.º 4
0
 /**
  * Disable the accounts for the given user list
  * @param array $userIdList
  * @return int
  */
 public function disableUserList($userIdList)
 {
     if (!count($userIdList)) {
         return false;
     }
     $affectedRows = $this->database->exec("\n            UPDATE\n                `{$this->tables['user']}`\n            SET\n                `authSource` = 'disabled'\n            WHERE\n                `user_id` IN (" . implode(',', $userIdList) . ")\n        ");
     Console::info("Disabled {$affectedRows} users : " . implode(',', $userIdList));
     return $affectedRows;
 }
Exemplo n.º 5
0
 public function compile()
 {
     @unlink($this->pharfile);
     $this->phar = new \Phar($this->pharfile);
     $fileIter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->basedir, \FileSystemIterator::SKIP_DOTS));
     $files = iterator_to_array($fileIter);
     foreach ($this->excludePrefixes as $prefix) {
         $files = $this->prunePrefix($files, $this->basedir . $prefix);
     }
     foreach ($this->excludeSuffixes as $suffix) {
         $files = $this->pruneSuffix($files, $suffix);
     }
     $this->phar->startBuffering();
     foreach ($files as $file) {
         $name = substr($file, strlen($this->basedir) + 1);
         Console::info("Adding {$name} ...");
         if (substr($file, -3) === 'php') {
             $this->phar[$name] = $this->{$this->squash}(file_get_contents($file));
         } else {
             $this->phar[$name] = file_get_contents($file);
         }
     }
     $this->addGITinfo();
     $this->addStub();
     $this->phar->stopBuffering();
     $this->setExecutableBit();
 }
Exemplo n.º 6
0
if ($is_allowedToSubmit) {
    /*--------------------------------------------------------------------
                          SUBMIT A WORK
      --------------------------------------------------------------------*/
    /*-----------------------------------
            STEP 2 : check & quey
      -------------------------------------*/
    if ($cmd == "exSubWrk") {
        if (isset($formCorrectlySent) && $formCorrectlySent) {
            if ($assignment->getAssignmentType() != 'GROUP' && claro_is_allowed_to_edit() && $authId) {
                $posterId = $authId;
            } else {
                $posterId = claro_get_current_user_id();
            }
            if ($posterId != claro_get_current_user_id()) {
                Console::info("CLWORK: user #" . claro_get_current_user_id() . " posted a submission in assigment #{$assignmentId} in course " . claro_get_current_course_id() . " in place of user #{$authId}");
            }
            $submission->setAssignmentId($assignmentId);
            $submission->setUserId($posterId);
            $submission->setTitle($wrkForm['wrkTitle']);
            $submission->setAuthor($wrkForm['wrkAuthors']);
            $submission->setVisibility($assignment->getDefaultSubmissionVisibility());
            $submission->setSubmittedText($wrkForm['wrkTxt']);
            $submission->setSubmittedFilename($wrkForm['filename']);
            if ($assignment->getAssignmentType() == 'GROUP' && isset($wrkForm['wrkGroup'])) {
                $submission->setGroupId($wrkForm['wrkGroup']);
            }
            $submission->save();
            $dialogBox->success(get_lang('Work added'));
            // notify eventmanager that a new submission has been posted
            $eventNotifier->notifyCourseEvent("work_submission_posted", claro_get_current_course_id(), claro_get_current_tool_id(), $assignmentId, '0', '0');