by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 01:53

    jcheron on master

    [skip ci] Update CHANGELOG (compare)

  • May 30 12:46
    zilveer commented #65
  • May 30 11:17
    andrei-dascalu commented #119
  • May 30 00:21
    jcheron commented #65
  • May 30 00:14
    jcheron commented #120
  • May 30 00:13
    jcheron reopened #120
  • May 30 00:12
    jcheron closed #120
  • May 30 00:12

    jcheron on master

    [skip ci] Add Content-Type for … (compare)

  • May 29 15:27
    jcheron labeled #119
  • May 29 15:27
    jcheron commented #119
  • May 29 15:26
    jcheron commented #120
  • May 29 15:23
    jcheron labeled #120
  • May 29 11:59
    Igorut commented #65
  • May 29 10:08
    andrei-dascalu edited #120
  • May 29 10:07
    andrei-dascalu edited #120
  • May 29 10:07
    andrei-dascalu assigned #120
  • May 29 10:07
    andrei-dascalu opened #120
  • May 29 08:56
    andrei-dascalu assigned #119
  • May 29 08:56
    andrei-dascalu opened #119
  • May 29 06:13
    Igorut commented #65
jcheron
@jcheron

if $var is a model instance, yes, it's a solution.
You can also use DAO::toUpdates to add multiple instances to the update.

DAO::toUpdates([$user1,$user2,$user3]);

With flushUpdates, the update of several objects is then done in a single request.
Otherwise, you can save in a foreach, or use the transactions:

DAO::beginTransaction();
foreach ($users as $user){
    DAO::save($user);
}
DAO::commit();
iDenora
@iDenora
How i can integrate csrf token validation?
And maybe you have solution for "remember me" button?
jcheron
@jcheron

Hi @iDenora
The Csrf part is integrated for the session, with a double cookie system.
It is not yet available for form validation : in the next version (soon).
I guess that's what you were interested in.

For the "Remember me" checkbox, if you use Ubiquity AuthControllers, you just have to override the toCookie method (which allows to memorize the user in a cookie), and the fromCookie, which allows to retrieve a user from a cookie :
Just one example:

    protected function toCookie($connected) {
        return md5($connected->getLogin());
    }

    protected function fromCookie($cookie) {
        $u = DAO::getOne(User::class, 'MD5(login)= ?', false, [
            $cookie
        ]);
        return $u;
    }
jcheron
@jcheron
For a less naive approach to security, it is preferable to implement a solution based on selector and validators stored on the server side (in the database for example).
see https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title.2
jcheron
@jcheron
Here is the corresponding version:
    protected function toCookie($connected) {
        do {
            $token = new Authtokens();
            $token->setUserid($connected->getId());
            $saved = DAO::save($token);
        } while ($saved === false);
        return $token->getSelector() . ':' . $token->getHashedValidator();
    }

    protected function fromCookie($cookie) {
        list ($selector, $validator) = explode(':', $cookie);
        $auth = DAO::getOne(Authtokens::class, 'selector= ?', false, [
            $selector
        ]);
        if (isset($auth)) {
            if (hash_equals($auth->getHashedValidator(), $validator)) {
                return DAO::getById(User::class, $auth->getUserid());
            }
        }
        return null;
    }
James Mahy
@JamesMahy
Hey @jcheron how does one access the logs generated by "Logger::info"
jcheron
@jcheron
Hi @JamesMahy
  • 'debug'=>true in config file
  • monolog/monolog installed
jcheron
@jcheron
If you use the embedded Ubiquity server, debug is set to true by default (whatever value is defined in the configuration file)
jcheron
@jcheron
You can then see the logs in the webtools log section,
or directly in the app/logs folder
iDenora
@iDenora
Hello, where i can edit mysql config? (change default charset, default timestamp)
Or you havent that function?
jcheron
@jcheron
Hi @iDenora
For the charset, you can change this in the db options in app/config/config.php:
        "options" => array(
            \MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'latin1\''
        ),
jcheron
@jcheron
For the default timestamp, the most efficient is to add it on the concerned fields in the database.
But you can also do it on the Ubiquity side by adding a transformer, but this is a less efficient solution.
NoTeefy
@NoTeefy

Hi @NoTeefy
Can you create an issue for this? it'll be easier to deal with.
Thank you!

turned out it was my antivirus (Avast) blocking outgoing mails on my development setup...

I'm kinda stuck with something weird now though. I've created a new project for a tiny task and everything works as it usually would, however my DAO::update or DAO::save calls aren't saving anything into the database and they return true (no errors at all, even in the log).
Do you know what could be causing this? The user defined in the configs has write access and it also performs those updates without any problems if I run the query by hand (cli) @jcheron
My update logic looks like this:
$decodedData = json_decode($jsonString, true);

// build obj
$updatedObj = DAO::getOne(Applications::class, $decodedData['changedObj']['id']);
$updatedObj->setMarked($decodedData['changedObj']['marked']);
$updatedObj->setStatus($decodedData['changedObj']['status']);

// update obj in DB
if(DAO::save($updatedObj)) {
    $this->return(true, 'updateApplication{} - successfully updated application with id '.$decodedData['changedObj']['id']);
}
else {
    $this->return(false, 'updateApplication{} - got an error while trying to update application with id '.$decodedData['changedObj']['id']);
}
NoTeefy
@NoTeefy
and this would be an example for the logs I get:
{"message":"Route found for /api/updateApplication/ : controllers\\MIDDLEWARE_API/updateApplication","context":{"context":"Router","part":"getRouteUrlParts","extra":null},"level":200,"level_name":"INFO","channel":"xxx","datetime":"2020-05-03T16:01:51.841405+00:00","extra":{}}
{"message":"UPDATE `applications` SET `id`= :id,`twitchname`= :twitchname,`surname`= :surname,`socials`= :socials,`age`= :age,`text`= :text,`status`= :status,`marked`= :marked WHERE `id`= :id","context":{"context":"DAOUpdates","part":"update","extra":null},"level":200,"level_name":"INFO","channel":"xxx","datetime":"2020-05-03T16:01:51.865454+00:00","extra":{}}
{"message":"{\"id\":\"2\",\"twitchname\":\"NoTeefy\",\"surname\":\"xxx\",\"socials\":\"https:\\/\\/twitter.com\\/NoTeefy\",\"age\":\"xx\",\"text\":\"nothing to read here\",\"status\":\"-1\",\"marked\":\"1\"}","context":{"context":"DAOUpdates","part":"Key and values","extra":null},"level":200,"level_name":"INFO","channel":"xxx","datetime":"2020-05-03T16:01:51.865502+00:00","extra":{}}
This might help you as well:
· PHP 7.4.4
· Ubiquity devtools (1.2.13)
· Ubiquity 2.3.7
jcheron
@jcheron

Hi @NoTeefy
These logs are displayed just before the update,
they allow the information to be verified, but do not mean that the request has been passed.
In any case, these logs are consistent and do not reveal any errors.
If there was a problem you should have an extra line with a warning.

Did you try to see if the Models part of the webtools worked for updates?

You can force error reporting in services.php:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Otherwise, apart from setting a break point on the save call, and then executing it step by step, I don't see what else to do.

jcheron
@jcheron
If debug is set to true in app/config/config.php
or that you use the embedded php server, a possible exception is necessarily displayed (without the debug, it's just a log).
But in any case, the method must not (or cannot) return true if the update did not take place.
NoTeefy
@NoTeefy
Ah, I thought so. Well save returns a true but I don't see those changes in my db which is really weird (it worked without any problems in earlier projects; although I used update instead of save on them)
Gonna try the error reporting out then. Wasn't sure where to put it to^^
NoTeefy
@NoTeefy
Doesn't help much. I don't get any errors at all. Why the heck doesn't my db reflect those updates? :/
NoTeefy
@NoTeefy
@jcheron I literally just copy & pasted the prepared statement, replaced the placeholders with some test values, executed it on my command line and everything works as it should...
It seems like there's an issue on my Ubiquity installation :s
what really baffles me is that I'm not getting a warning or anything. It just says it made some changes but actually never executes them
NoTeefy
@NoTeefy
Found the error. That was actually my first thought but I didn't think it would have been that kind of a problem. Just checked my DB logs and it looks like Ubiquity is setting a variable called AUTOCOMMIT to 0 when it connects to the db. This requires it to send a commit command after updates/data manipulations. However Ubiquity doesn't do that. It just executes its update and then quits again.
Not sure where we'd need to fix that though. If it's not something specified in any Ubiquity routine, it's probably a new database default on MariaDB
2020-05-03T19:27:07.664585Z       22 Query    SET AUTOCOMMIT=0
2020-05-03T19:27:07.666606Z       22 Query    SELECT `applications`.`id`,`applications`.`twitchname`, ...
2020-05-03T19:27:07.668208Z       22 Query    UPDATE `applications` SET `id`= '2',`twitchname`= 'NoTeefy', ...
2020-05-03T19:27:07.669067Z       22 Quit
NoTeefy
@NoTeefy
Wait a second... Could it be related to that new bulk-query stuff? Like did you maybe change the autocommits to manual ones since you wrote a new logic for bulk inserts/updates/selects? Because it looks like the commit is being sent for those (at least from what I can see in DatabaseTransactionsTrait.php)
jcheron
@jcheron
Ubiquity does not explicitly deal with auto-commit.
jcheron
@jcheron
You didn't use the transactions?
like DAO::beginTransaction()
jcheron
@jcheron
You can try to force the autocommit on the connection in the configuration file app/config/config.php:
"options" => array(
            \PDO::ATTR_AUTOCOMMIT => 1
        )
jcheron
@jcheron
Otherwise, the Bulk queries do not affect the autocommit.
jcheron
@jcheron
You didn't tell me if the webtools admin interface has the same problem to update objects?
iDenora
@iDenora
image.png
It's csrf cookies? How i can off that
NoTeefy
@NoTeefy
@jcheron well that's interesting. I never had to use a transaction for closed/solo calls. I even have one system which is productive on an older Ubiquity version and it doesn't use transactions (and its updates are committed like they should)
And I unfortunately can't test it on the Admin interface since I'm not using it
It seems to work if I'm using a transaction and do manual commits. I don't think that should be the standard procedure though. It would be much more standardized if single db calls/queries would use the autocommit functionality like in other frameworks
NoTeefy
@NoTeefy
Can't thank you enough for this awesome framework though. I'd love to support you by contributing stuff but I don't have the time for it atm :/
jcheron
@jcheron

It's csrf cookies? How i can off that

Hi @iDenora
I don't know what you're showing me here, and I don't know what context you're showing it in.

@NoTeefy , Hello
For your auto-commit problem, we need to isolate the problem.
Can you create a new project,

composer create-project phpmv/ubiquity-project test-autocommit

add your database, generate the classes and tell me if you have the same problem for updates in the models part of the webtools?
at http://127.0.0.1:8090/Admin/models

jcheron
@jcheron
@NoTeefy Can you check the autocommit value on your Mysql/mariaDb server?
You can access it directly from phpMyAdmin, by going to server/variables.
image.png
jcheron
@jcheron
How'd that turn out?
You can try to force the autocommit on the connection in the configuration file app/config/config.php:
"options" => array(
            \PDO::ATTR_AUTOCOMMIT => 1
        )
jcheron
@jcheron
Hi @NoTeefy , @iDenora
It would be nice to get some feedback, see if your problems are solved.
Andrei Dascalu
@andrei-dascalu
Hello, as a dumb n00b, I have a couple of very silly beginner questions, like how to disable the default routing (based on controller/action/etc) and have a 404 unless a specific route is set as well as what's the proper way to return a simple json response from a non-rest controller
jcheron
@jcheron
Hi @andrei-dascalu
To disable default routing and have a 404 route, you can add a last route:
class FooController extends ControllerBase {
    ...

    /**
     * @route("{url}","priority"=>-1000)
     */
    public function route404($url) {
        UResponse::setResponseCode(404);
        echo "Page {$url} not found!";
    }
}
and if you still want to preserve some controllers (the Admin part for example), you must add the requirements attribute, which allows to specify a regex:
   /**
     * @route("{url}","priority"=>-1000,"requirements"=>["url"=>"(?!(a|A)dmin).*?"])
     */
jcheron
@jcheron
For the JSON responses in non REST controllers,
There's nothing specific, the way you do it is fine:
    public function index() {
        UResponse::asJSON();
        echo \json_encode([
            'foo'=>'bar'
        ]);
    }