Beispiel #1
0
 public function POSTlogin($request)
 {
     $pin = $request->post('pin') ?: 0;
     $uid = $request->post('uid') ?: false;
     try {
         if ($uid && $pin) {
             // authenticate user based on password
             (new \models\instructor(\models\Data::ID($uid)))->authenticate($pin);
             \bloc\Application::instance()->session('COLUM', ['id' => $uid]);
             \bloc\router::redirect('/records/courses');
         } else {
             // user must be in database based on oasis id, find them: ;
             $user = \models\Data::ID(\models\Student::BLEAR($pin));
             // if found, generate token with sha1 of $email address and token
             $token = \bloc\types\token::generate($user['@email'], getenv('EMAIL_TOKEN'));
             // set the token on the user field
             if ($user->hasAttribute('token') && $user->getAttribute('token') === $token) {
                 throw new \InvalidArgumentException("Token Already Requested", 2);
             } else {
                 $user->setAttribute('token', $token);
                 \models\Data::instance()->storage->save();
                 // email the user a link.
                 $template = new \bloc\View('views/layouts/email.html');
                 $template->content = 'views/layouts/forms/transaction.html';
                 $output = ['link' => DOMAIN . "/records/token/{$user['@id']}/{$token}", 'title' => $user['@name'], 'message' => 'login to course site'];
                 \models\Message::TRANSACTION('login', $user['@email'], (string) $template->render($output));
             }
         }
     } catch (\InvalidArgumentException $e) {
         $type = $e->getCode() == 1 ? 'invalid' : 'duplicate';
         $path = sprintf('/%s/login/%s/', $this->template, $type);
         \bloc\router::redirect($path);
     }
     $view = new \bloc\View(self::layout);
     $view->content = 'views/layouts/forms/transaction.html';
     return $view->render(['link' => 'http://www.colum.edu/loopmail', 'title' => 'Email Sent', 'message' => 'check your email']);
 }
Beispiel #2
0
 public function CLIenroll($semester, $course, $section, $id = null, $name = null, $email = null, $year = null, $major = null)
 {
     $doc = new Document("data/{$semester}");
     $section = (new \DomXpath($doc))->query("//courses/section[@id='{$section}' and @course='{$course}']");
     if ($section->length < 1) {
         throw new \RuntimeException("No section {$section} for {$course} in {$semester}", 1);
     }
     $student = $section->item(0)->appendChild($doc->createElement('student'));
     if ($name === null) {
         echo "\nName: ";
         $name = trim(fgets(STDIN));
     }
     if ($id === null) {
         echo "\nOasis ID: ";
         $id = trim(fgets(STDIN));
     }
     if ($email === null) {
         echo "\nEmail: ";
         $email = trim(fgets(STDIN));
     }
     if ($year === null) {
         echo "\nYear: ";
         $year = trim(fgets(STDIN));
     }
     if ($major === null) {
         echo "\nMajor: ";
         $major = trim(fgets(STDIN));
     }
     $student->setAttribute('name', $name);
     $student->setAttribute('email', $email);
     $key = substr($email, 0, strpos($email, '@'));
     $student->setAttribute('url', "http://iam.colum.edu/students/{$key}/{$course}");
     $student->setAttribute('id', \models\Student::BLEAR($id));
     $student->setAttribute('year', $year);
     $student->setAttribute('major', $major);
     echo $student->write() . "\nCreate Account (Y/n): ";
     if (strtoupper(trim(fgets(STDIN))) === 'Y') {
         return $this->save($doc);
     }
 }