Пример #1
0
 static function create($groupname, $description)
 {
     $g = new UserGroup();
     $g->groupname = $groupname;
     $g->uuid = uuid::v4();
     $g->description = $description;
     return $g;
 }
Пример #2
0
 function __construct($structure = null)
 {
     $path = expandpath('app:' . $structure);
     if (file_exists($path) && $structure) {
         $strx = domdocument::load($path);
         $domx = new DOMXpath($strx);
         $cfgs = $domx->query('/configurationschema/config');
         foreach ($cfgs as $item) {
             $key = $item->getAttribute('key');
             if ($item->hasAttribute('type')) {
                 $vartype = $item->getAttribute('type');
             } else {
                 $vartype = 'string';
             }
             $description = null;
             $default = null;
             if ($item->childNodes->length > 0) {
                 foreach ($item->childNodes as $item) {
                     switch ($item->nodeName) {
                         case 'default':
                             $value = $item->getAttribute('value');
                             $type = $item->getAttribute('type');
                             if ($type == 'string') {
                                 $value = str_replace('${servername}', request::getDomain(), $value);
                                 $default = $value;
                             }
                             if ($type == 'integer') {
                                 $value = intval($value);
                                 $default = $value;
                             }
                             if ($type == 'float') {
                                 $value = floatval($value);
                                 $default = $value;
                             }
                             if ($type == 'generate') {
                                 if ($value == 'uuid') {
                                     $default = uuid::v4();
                                 } else {
                                     $default = '<unknown>';
                                 }
                             }
                             break;
                         case 'description':
                             $description = $item->nodeValue;
                             break;
                     }
                 }
             }
             if (!arr::hasKey($this->data, $key)) {
                 $this->data[$key] = $default;
             }
             $this->defs[$key] = array('description' => $description, 'vartype' => $vartype);
         }
         $this->flush();
     }
 }
Пример #3
0
 public function preSave()
 {
     if ($this->getValue() == '') {
         $this->setValue(uuid::v4());
     }
 }
Пример #4
0
 public function save()
 {
     if (!$this->uuid) {
         $this->uuid = uuid::v4();
     }
     if (count($this->modified) > 0) {
         // Get a database reference
         $db = new DatabaseConnection();
         // Determine what needs to be updated.
         $mtable = array('user' => false, 'userdata' => false, 'ambient' => false, 'credentials' => false);
         foreach ($this->modified as $mod) {
             switch ($mod) {
                 case 'ambient':
                     $mtable['ambient'] = true;
                     break;
                 case 'username':
                     $mtable['user'] = true;
                     break;
                 case 'password':
                     $mtable['credentials'] = true;
                     break;
                 case 'email':
                     $mtable['user'] = true;
                     break;
                 case 'uuid':
                     $mtable['user'] = true;
                     break;
                 case 'active':
                     $mtable['user'] = true;
                     break;
                 case 'displayname':
                     $mtable['userdata'] = true;
                     break;
                 case 'firstname':
                     $mtable['userdata'] = true;
                     break;
                 case 'lastname':
                     $mtable['userdata'] = true;
                     break;
                 case 'sex':
                     $mtable['userdata'] = true;
                     break;
                 case 'country':
                     $mtable['userdata'] = true;
                     break;
                 case 'flags':
                     $mtable['user'] = true;
                     break;
                 case 'userid':
                     break;
                 default:
                     throw new BadArgumentException("Unknown field modified: {$mod}");
             }
         }
         $this->modified = array();
         if (!$this->userid) {
             // Check to see if the username already exists
             if (user::find($this->username)) {
                 throw new UserException("User already exists!");
             }
             // Insert
             $ambient = serialize($this->ambient);
             $this->userid = $db->insertRow("INSERT INTO " . LEPTON_DB_PREFIX . "users (username,email,uuid,flags,active,registered) VALUES " . "(%s,%s,%s,%s,%d,NOW())", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0);
             $db->updateRow("INSERT INTO " . LEPTON_DB_PREFIX . "userdata (displayname,firstname,lastname,sex,country,ambient,id) VALUES " . "(%s,%s,%s,%s,%s,%s,%d)", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid);
             // Update credentials
             $backend = User::getAuthenticationBackend();
             $backend->assignCredentials($this);
         } else {
             // Update
             if ($mtable['ambient'] && $mtable['userdata']) {
                 // Update complete userdata table
                 $ambient = serialize($this->ambient);
                 $db->updateRow("Update " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s,ambient=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $ambient, $this->userid);
             } elseif ($mtable['ambient']) {
                 // Update the ambient column
                 $ambient = serialize($this->ambient);
                 $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET ambient=%s WHERE id=%d ", $ambient, $this->userid);
             } elseif ($mtable['userdata']) {
                 // Update the userdata columns
                 $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "userdata SET displayname=%s,firstname=%s,lastname=%s,sex=%s,country=%s WHERE id=%d", $this->displayname, $this->firstname, $this->lastname, $this->sex, $this->country, $this->userid);
             }
             if ($mtable['user']) {
                 // Update users table
                 $db->updateRow("UPDATE " . LEPTON_DB_PREFIX . "users SET username=%s,email=%s,uuid=%s,flags=%s,active=%s WHERE id=%d", $this->username, $this->email, $this->uuid, $this->flags, $this->active ? 1 : 0, $this->userid);
             }
             if ($mtable['credentials']) {
                 // Update credentials
                 $backend = User::getAuthenticationBackend();
                 $backend->assignCredentials($this);
             }
         }
     }
     return true;
 }
Пример #5
0
 /**
  * Constructor, must be chained from the worker class using parent::__construct() or
  * things will fail.
  *
  */
 public function __construct()
 {
     $this->setState(self::STATE_QUEUED);
     $this->setProgress("Job queued");
     $this->_id = uuid::v4();
 }
Пример #6
0
 /**
  * @description Generate UUID V4
  */
 function uuid_v4()
 {
     $uuid = uuid::v4();
     $this->assertEquals(strlen($uuid), uuid::LENGTH);
 }
Пример #7
0
 /**
  * Add a message to the message store.
  *
  * @param MailMessage $message The message
  */
 function addMessage(MailMessage $message)
 {
     $msgel = $this->mbox->createElement('message');
     $message->msgid = uuid::v4();
     $msgel->setAttribute('read', $message->read);
     $msgel->setAttribute('subject', $message->subject);
     $msgel->setAttribute('msgid', $message->msgid);
     $msgbody = $this->mbox->createTextNode($message->body);
     $msgel->appendChild($msgbody);
     $this->mbox->documentElement->appendChild($msgel);
     return true;
 }