/**
  * (non-PHPdoc)
  * @see Xerxes\Mvc.ActionController::init()
  */
 public function init()
 {
     $factory = new AuthenticationFactory();
     $this->authentication = $factory->getAuthenticationObject($this->request);
 }
Esempio n. 2
0
 public function init(MvcEvent $e)
 {
     $this->registry = Registry::getInstance();
     $factory = new AuthenticationFactory();
     $this->authentication = $factory->getAuthenticationObject($e->getRequest());
 }
 /**
  * (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());
 }