<?php require_once '../../vendor/autoload.php'; require_once '../class/autoload.php'; require_once '../amember4/library/Am/Lite.php'; $user = \PTA\User::getInstance(); if ($user->isLoggedIn() && $user->isMembershipValid()) { $user_id = $user->getUserId(); } else { // FIXME: Implement proper error handling for expired session die; } // $image->name (string) // $image->type (string) // $image->size (integer; available only in upload_start) // $image->path (string) // $image->url (string) // $image->width (integer) // $image->height (integer) // $image->versions (array; available only in upload_complete and crop_complete) $options = ['upload_dir' => '/var/cache/avatar/', 'upload_url' => '/img/avatar/', 'mkdir_mode' => 0755, 'versions' => ['bg' => ['max_width' => 1920, 'max_height' => 1080]], 'load' => function ($instance) { // FIXME: How does autload work exactly? // return 'avatar.jpg'; }, 'delete' => function ($filename, $instance) { return false; }, 'upload_start' => function ($image, $instance) use($user_id) { $fn = sprintf('%s.%s', "incoming_{$user_id}", $image->type); $image->name = $fn; syslog(LOG_DEBUG, 'upload_start'); syslog(LOG_DEBUG, "path = " . $image->path); syslog(LOG_DEBUG, "name = " . $image->name);
public static function validateNonce($user_id, $value, $ip, $class = 'undefined') { # Given an explicit user id, the constructor will not call upon aMember $user = new User($user_id); return $user->verifyNonce($value, $ip, $class, $user_id); }
}); $app->post('/level/:level/:lesson/result-exam/statements/', function ($level, $lesson) use($app) { $request_body = file_get_contents('php://input'); parse_str(urldecode($request_body), $data); if (isset($data['content'])) { $result = json_decode($data['content']); } else { die; } $verb = $result->verb->id; $verb = str_replace('http://adlnet.gov/expapi/verbs/', '', $verb); $user_id = $data['user']; $authKey = $data['Authorization']; if (in_array($verb, array('completed', 'passed', 'failed'))) { if (\PTA\User::validateNonce($user_id, $authKey, $_SERVER['REMOTE_ADDR'], 'exam')) { $user = \PTA\User::getInstance($user_id); $oldlevel = $user->getLevel(); if (isset($result->result->completion) == true) { die; } $score = $result->result->score->scaled * 100; $passingScore = 70; if ($verb == "failed") { if ($score > $passingScore) { $passingScore = $score + 10; } } else { if ($verb == "passed") { if ($score < $passingScore) { $passingScore = $score + 10; }