Get user profile data into $user variable

This commit is contained in:
Bofh 2021-11-27 03:04:22 +01:00
parent 9745fe5a9f
commit 4590975b96
2 changed files with 22 additions and 0 deletions

View File

@ -45,3 +45,4 @@ function conf($key, $default='') {
require_once '/src/base.methods.php'; require_once '/src/base.methods.php';
require_once '/src/base.auth.php'; require_once '/src/base.auth.php';
require_once '/src/base.user.php';

21
src/base.user.php Normal file
View File

@ -0,0 +1,21 @@
<?php
$user = null;
if ($valid_cookie) {
$sm = $db->prepare('SELECT id_user FROM oauth_tokens WHERE cookie = ?');
$sm->execute([$cookie]);
if (($row = $sm->fetch()) !== false) {
if (isset($row['id_user'])) {
$sm = $db->prepare('SELECT * FROM users WHERE id = ?');
$sm->execute([$row['id_user']]);
if (($user = $sm->fetchObject()) !== false) {
switch ($user->account_type)
{
case 'mastodon':
$user->account_data = json_decode($user->account_data);
break;
}
}
}
}
}