public function saveUserInfo()
 {
     if (!isset($_SESSION)) {
         session_start();
     }
     $code = \Input::get('code');
     $lti = \Input::get('lti');
     $instanceFromDB = LtiConfigurations::find($lti);
     $clientId = $instanceFromDB['DeveloperId'];
     $developerSecret = $instanceFromDB['DeveloperSecret'];
     $opts = array('http' => array('method' => 'POST'));
     $context = stream_context_create($opts);
     $url = "https://{$_SESSION['domain']}/login/oauth2/token?client_id={$clientId}&client_secret={$developerSecret}&code={$code}";
     $userTokenJSON = file_get_contents($url, false, $context, -1, 40000);
     $userToken = json_decode($userTokenJSON);
     $actualToken = $userToken->access_token;
     $encryptedToken = \Crypt::encrypt($actualToken);
     $_SESSION['userToken'] = $encryptedToken;
     //store encrypted token in the database
     $courseId = $_SESSION['courseID'];
     $userId = $_SESSION['userID'];
     //make sure we have the user stored in the user table and in the userCourse table.
     $roots = new Roots();
     //when we get the user from the LMS it gets stored in the DB.
     $roots->getUser($userId);
     $dbHelper = new DbHelper();
     $role = $dbHelper->getRole('Approver');
     $userCourse = UserCourse::firstOrNew(array('user_id' => $userId, 'course_id' => $courseId));
     $userCourse->user_id = $userId;
     $userCourse->course_id = $courseId;
     $userCourse->role = $role->id;
     $userCourse->encrypted_token = $encryptedToken;
     $userCourse->save();
     echo "App has been approved. Please reload this page";
 }
 private function processStudentsInCourse($data, $courseId)
 {
     //first add them the User table
     //then add them to the user_course table.
     $arr = array();
     $role = Role::where('role_name', '=', 'Learner')->first();
     foreach ($data as $row) {
         $this->saveUser($row->id, $row->name, $row->sortable_name);
         $userCourse = UserCourse::firstOrNew(array('user_id' => $row->id, 'course_id' => $courseId));
         $userCourse->user_id = $row->id;
         $userCourse->course_id = $courseId;
         $userCourse->role = $role->id;
         $userCourse->save();
         $arr[] = $userCourse;
     }
     return $arr;
 }
Example #3
0
 public function deleteUserFromRole($courseId, $userId, $role_name)
 {
     $role = Role::where('role_name', '=', $role_name)->first();
     $user = UserCourse::where(array('role' => $role->id, 'course_id' => $courseId, 'user_id' => $userId))->first();
     $user->delete();
 }