/**
  * (non-PHPdoc)
  * @see Application\Controller.SearchController::init()
  */
 public function init()
 {
     // inital oauth request
     // @todo: this needs to be folded into the authentication framework or something?
     if ($this->request->getParam("oauth_consumer_key")) {
         $key = $this->registry->getConfig('BLTI_KEY', true);
         $secret = $this->registry->getConfig('BLTI_SECRET', true);
         $lti = new Lti\Basic($key, $secret);
         // extract course id
         $this->course_id = $lti->getID();
         $this->request->setParam('course_id', $this->course_id);
         // save in session for subsequent actions
         $this->request->setSessionData('course_id', $this->course_id);
         $this->request->setSessionObject("lti_" . $this->course_id, $lti);
         $user = $this->request->getUser();
         // this is the first time user has come during this session
         if ($this->request->getSessionData('reading_list_user') == null) {
             $datamap = new Users();
             $user_id = $lti->getUserID();
             // the lms user id
             $username = $datamap->getUserFromLti($user_id);
             // see if user is already in our database
             // we don't know this user
             if ($username == "") {
                 // and they have not logged in
                 if (!$user->isAuthenticated()) {
                     return $this->redirectToLogin();
                     // send them to login
                 } else {
                     $datamap->associateUserWithLti($user->username, $user_id);
                     // register them for next time
                 }
             } else {
                 // swap username
                 $user->username = $username;
                 // register them in session and such for single sign on
                 $auth_factory = new AuthenticationFactory();
                 $auth_factory->getAuthenticationObject($this->request)->register($user);
             }
             // and make sure we keep track of that here for subsequent requests
             $this->request->setSessionData('reading_list_user', $user_id);
         }
     }
     // subsequent requests with course_id in URL
     $course_id = $this->request->getParam('course_id');
     if ($course_id != "") {
         $this->course_id = $course_id;
         // add value from saved lti session @todo make this universal or something
         $session_id = 'lti_' . $course_id;
         if ($this->request->existsInSessionData($session_id)) {
             $lti = $this->request->getSessionObject($session_id);
             $this->response->setVariable('resource_link_title', $lti->getParam('resource_link_title'));
             $this->response->setVariable('resource_link_description', $lti->getParam('resource_link_description'));
         }
     }
     // save lti in the response
     $lti = $this->request->getSessionObject("lti_" . $this->course_id);
     $this->response->setVariable('lti', $lti);
     parent::init();
     // display helpers
     $this->helper = new ListHelper($this->event, $this->id, $this->engine);
     $this->response->setVariable('course_nav', $this->helper->getNavigation());
 }
Example #2
0
 /**
  * Register the user in session and with the user tables in the database
  * and then forwards them to the return url
  * 
  * @param User $user  [optional] user object
  */
 public function register(User $user = null)
 {
     // if passed in externally
     if ($user != null) {
         $this->user = $user;
     }
     // data map
     $datamap_users = new Users();
     $datamap_records = new SavedRecords();
     // if the user was previously active under a local username
     // then reassign any saved records to the new username
     $old_username = $this->request->getSessionData("username");
     $old_role = $this->request->getSessionData("role");
     if ($old_role == "local") {
         $datamap_records->reassignRecords($old_username, $this->user->username);
     }
     // add or update user in the database
     // get any values in the db not specified here and populates user
     $this->user = $datamap_users->touchUser($this->user);
     // @todo: reconcile this code with User code
     // should we just save user object in session?
     // set main properties in session
     $admins = explode(',', $this->registry->getConfig('ADMIN_USERS'));
     if (in_array($this->user->username, $admins)) {
         $this->request->setSessionData("user_admin", true);
     }
     $this->request->setSessionData("username", $this->user->username);
     $this->request->setSessionData("role", $this->role);
     // store user's additional properties in session, so they can be used by
     // controller, and included in xml for views.
     $this->request->setSessionData("user_properties", $this->user->properties());
     // groups too empty array not null please.
     $this->request->setSessionData("user_groups", $this->user->usergroups);
     // set this object's id in session
     $this->request->setSessionData("auth", $this->id);
     // now forward them to the return url
     return $this->redirectTo($this->return_url);
 }
Example #3
0
 /**
  * Registers the user in session and with the user tables in the database
  * and then forwards them to the return url
  */
 public function register()
 {
     // data map
     $datamap_users = new Users();
     $datamap_records = new SavedRecords();
     // if the user was previously active under a local username
     // then reassign any saved records to the new username
     $old_username = $this->request->getSessionData("username");
     $old_role = $this->request->getSessionData("role");
     if ($old_role == "local") {
         $datamap_records->reassignRecords($old_username, $this->user->username);
     }
     // add or update user in the database
     // get any values in the db not specified here and populates user
     $this->user = $datamap_users->touchUser($this->user);
     // @todo: should we just save user object in session?
     // set main properties in session
     $this->request->setSessionData("username", $this->user->username);
     $this->request->setSessionData("role", $this->role);
     // store user's additional properties in session, so they can be used by
     // controller, and included in xml for views.
     $this->request->setSessionData("user_properties", $this->user->properties());
     // groups too empty array not null please.
     $this->request->setSessionData("user_groups", $this->user->usergroups);
     // set this object's id in session
     $this->request->setSessionData("auth", $this->id);
     // now forward them to the return url
     $this->setRedirect($this->return_url);
     return self::SUCCESS;
 }