2018-07-24 19:31:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This is executed inside DatabaseMigrationService class/context
|
|
|
|
|
2020-03-01 23:47:47 +07:00
|
|
|
$db = $this->getDatabaseService()->GetDbConnection();
|
2018-07-24 19:31:43 +02:00
|
|
|
|
2018-07-25 20:20:09 +02:00
|
|
|
if (defined('GROCY_HTTP_USER'))
|
2018-07-24 19:31:43 +02:00
|
|
|
{
|
|
|
|
// Migrate old user defined in config file to database
|
|
|
|
$newUserRow = $db->users()->createRow(array(
|
2018-07-25 20:20:09 +02:00
|
|
|
'username' => GROCY_HTTP_USER,
|
|
|
|
'password' => password_hash(GROCY_HTTP_PASSWORD, PASSWORD_DEFAULT)
|
2018-07-24 19:31:43 +02:00
|
|
|
));
|
|
|
|
$newUserRow->save();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create default user "admin" with password "admin"
|
|
|
|
$newUserRow = $db->users()->createRow(array(
|
|
|
|
'username' => 'admin',
|
|
|
|
'password' => password_hash('admin', PASSWORD_DEFAULT)
|
|
|
|
));
|
|
|
|
$newUserRow->save();
|
|
|
|
}
|