Exemplo n.º 1
0
 /**
  * Generates a new token.
  *
  * @access  protected
  * @return  string
  */
 protected function generateToken()
 {
     if (!$this->exists) {
         throw new LogicException(vsprintf("%s(): You can only generate auth tokens for users that exist in the database.", [__METHOD__]));
     }
     return hash('sha256', UUID::v4() . $this->getId() . uniqid('token', true));
 }
Exemplo n.º 2
0
 /**
  * Generates a session id.
  *
  * @access  protected
  * @return  string
  */
 protected function generateId()
 {
     return hash('sha256', UUID::v4() . uniqid('session', true));
 }
Exemplo n.º 3
0
 /**
  * Inserts a new record into the database.
  *
  * @access  protected
  * @param   \mako\database\midgard\Query  $query  Query builder
  */
 protected function insertRecord($query)
 {
     if ($this->primaryKeyType === static::PRIMARY_KEY_TYPE_INCREMENTING) {
         $this->columns[$this->primaryKey] = $query->insertAndGetId($this->columns, $this->primaryKey);
     } else {
         switch ($this->primaryKeyType) {
             case static::PRIMARY_KEY_TYPE_UUID:
                 $this->columns[$this->primaryKey] = UUID::v4();
                 break;
             case static::PRIMARY_KEY_TYPE_CUSTOM:
                 $this->columns[$this->primaryKey] = $this->generatePrimaryKey();
                 break;
         }
         $query->insert($this->columns);
     }
 }
Exemplo n.º 4
0
 /**
  *
  */
 public function testV4()
 {
     $this->assertEquals(4, substr(UUID::v4(), 14, 1));
     $this->assertTrue(in_array(substr(UUID::v4(), 19, 1), [8, 9, 'a', 'b']));
     $this->assertTrue(UUID::validate(UUID::v4()));
 }