mirror of
https://github.com/ellite/Wallos.git
synced 2026-04-17 21:50:11 -04:00
feat: user has api key available on profile page feat: api endpoint to calculate monthly cost feat: split settings page into settings and profile page feat: redesigned experimental mobile navigation menu fix: small fixes and typos
22 lines
760 B
PHP
22 lines
760 B
PHP
<?php
|
|
|
|
// This migration adds a "api_key" column to the user table
|
|
// It also generates an API key for each user
|
|
|
|
/** @noinspection PhpUndefinedVariableInspection */
|
|
$columnQuery = $db->query("SELECT * FROM pragma_table_info('user') where name='api_key'");
|
|
$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;
|
|
|
|
if ($columnRequired) {
|
|
$db->exec('ALTER TABLE user ADD COLUMN api_key TEXT');
|
|
}
|
|
|
|
/** @noinspection PhpUndefinedVariableInspection */
|
|
$users = $db->query('SELECT * FROM user');
|
|
while ($user = $users->fetchArray(SQLITE3_ASSOC)) {
|
|
if (empty($user['api_key'])) {
|
|
$apiKey = bin2hex(random_bytes(32));
|
|
$db->exec('UPDATE user SET api_key = "' . $apiKey . '" WHERE id = ' . $user['id']);
|
|
}
|
|
}
|