Implement dummy group and user

This commit is contained in:
flash 2015-04-02 15:24:05 +02:00
parent 65e2727da0
commit 26c96c78cc

View file

@ -1,78 +1,115 @@
<?php <?php
/* /*
* User Management * User Management
*/ */
namespace Sakura; namespace Sakura;
class Users { class Users {
// Check if a user is logged in // Empty user template
public static function loggedIn() { public static $emptyUser = [
'id' => 0,
// Just return false for now since we don't have a user system yet 'username' => 'Non-existent user',
return false; 'username_clean' => 'non-existent user',
'password_hash' => '',
} 'password_salt' => '',
'password_algo' => 'sha256',
// Get user data by id 'password_iter' => 1000,
public static function getUser($id) { 'password_chan' => 0,
'password_new' => '',
// Execute query 'email' => 'deleted@flashii.net',
$user = Database::fetch('users', false, ['id' => [$id, '=']]); 'group_main' => 0,
'groups' => '[0]',
// Return false if no user was found 'name_colour' => '',
if(empty($user)) 'register_ip' => '127.0.0.1',
return false; 'last_ip' => '127.0.0.1',
'usertitle' => 'Non-existent user account',
// If user was found return user data 'profile_md' => '',
return $user; 'avatar_url' => '',
'background_url' => '',
} 'regdate' => 0,
'lastdate' => 0,
// Get group data by id 'lastunamechange' => 0,
public static function getGroup($id) { 'birthday' => '',
'profile_data' => '[]'
// Execute query ];
$group = Database::fetch('groups', false, ['id' => [$id, '=']]);
// Empty group template
// Return false if no group was found public static $emptyGroup = [
if(empty($group)) 'id' => 0,
return false; 'groupname' => 'Non-existent group',
'multi' => 0,
// If group was found return group data 'colour' => '',
return $group; 'description' => 'A hardcoded dummy group for fallback.'
];
}
// Check if a user is logged in
// Get all users public static function loggedIn() {
public static function getAllUsers() {
// Just return false for now since we don't have a user system yet
// Execute query return false;
$getUsers = Database::fetch('users', true);
}
// Reorder shit
foreach($getUsers as $user) // Get user data by id
$users[$user['id']] = $user; public static function getUser($id) {
// and return an array with the users // Execute query
return $users; $user = Database::fetch('users', false, ['id' => [$id, '=']]);
} // Return false if no user was found
if(empty($user))
// Get all groups return self::$emptyUser;
public static function getAllGroups() {
// If user was found return user data
// Execute query return $user;
$getGroups = Database::fetch('groups', true);
}
// Reorder shit
foreach($getGroups as $group) // Get group data by id
$groups[$group['id']] = $group; public static function getGroup($id) {
// and return an array with the users // Execute query
return $groups; $group = Database::fetch('groups', false, ['id' => [$id, '=']]);
} // Return false if no group was found
if(empty($group))
} return self::$emptyGroup;
// If group was found return group data
return $group;
}
// Get all users
public static function getAllUsers() {
// Execute query
$getUsers = Database::fetch('users', true);
// Reorder shit
foreach($getUsers as $user)
$users[$user['id']] = $user;
// and return an array with the users
return $users;
}
// Get all groups
public static function getAllGroups() {
// Execute query
$getGroups = Database::fetch('groups', true);
// Reorder shit
foreach($getGroups as $group)
$groups[$group['id']] = $group;
// and return an array with the users
return $groups;
}
}