Example #1
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 #2
0
 /**
  * Create a User
  * 
  * @param Request $request  [optional] create user from current Request
  */
 public function __construct(Request $request = null)
 {
     self::$request = $request;
     $this->registry = Registry::getInstance();
     if ($request != "") {
         // user attributes
         $this->username = $request->getSessionData("username");
         $this->role = $request->getSessionData("role");
         $this->ip_address = $request->getClientIp();
         $this->admin = $request->getSessionData('user_admin');
         // local ip range from config
         $this->ip_range = $this->registry->getConfig("LOCAL_IP_RANGE", false, null);
         // temporarily authenticate users
         if ($this->username == "") {
             // on campus
             if ($this->isInLocalIpRange() == true) {
                 $this->username = self::genRandomUsername(self::LOCAL);
                 $this->role = self::LOCAL;
             } else {
                 $this->username = self::genRandomUsername(self::GUEST);
                 $this->role = self::GUEST;
             }
             $request->setSessionData("username", $this->username);
             $request->setSessionData("role", $this->role);
         }
     }
 }