This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/_sakura/components/Users.php

116 lines
2.8 KiB
PHP
Raw Normal View History

2015-04-02 13:24:05 +00:00
<?php
/*
* User Management
*/
namespace Sakura;
class Users {
// Empty user template
public static $emptyUser = [
'id' => 0,
2015-04-02 13:25:18 +00:00
'username' => 'Deleted User',
'username_clean' => 'deleted user',
2015-04-02 13:24:05 +00:00
'password_hash' => '',
'password_salt' => '',
'password_algo' => 'sha256',
'password_iter' => 1000,
'password_chan' => 0,
'password_new' => '',
'email' => 'deleted@flashii.net',
'rank_main' => 0,
'ranks' => '[0]',
2015-04-02 13:24:05 +00:00
'name_colour' => '',
'register_ip' => '127.0.0.1',
'last_ip' => '127.0.0.1',
'usertitle' => 'Non-existent user account',
'profile_md' => '',
'avatar_url' => '',
'background_url' => '',
'regdate' => 0,
'lastdate' => 0,
'lastunamechange' => 0,
'birthday' => '',
'profile_data' => '[]'
];
// Empty rank template
public static $emptyRank = [
2015-04-02 13:24:05 +00:00
'id' => 0,
'rankname' => 'Non-existent Rank',
2015-04-02 13:24:05 +00:00
'multi' => 0,
'colour' => '',
'description' => 'A hardcoded dummy rank for fallback.'
2015-04-02 13:24:05 +00:00
];
// Check if a user is logged in
public static function loggedIn() {
// Just return false for now since we don't have a user system yet
return false;
}
// Get user data by id
public static function getUser($id) {
// Execute query
$user = Database::fetch('users', false, ['id' => [$id, '=']]);
// Return false if no user was found
if(empty($user))
return self::$emptyUser;
// If user was found return user data
return $user;
}
// Get rank data by id
public static function getRank($id) {
2015-04-02 13:24:05 +00:00
// Execute query
$rank = Database::fetch('ranks', false, ['id' => [$id, '=']]);
2015-04-02 13:24:05 +00:00
// Return false if no rank was found
if(empty($rank))
return self::$emptyRank;
2015-04-02 13:24:05 +00:00
// If rank was found return rank data
return $rank;
2015-04-02 13:24:05 +00:00
}
// 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 ranks
public static function getAllRanks() {
2015-04-02 13:24:05 +00:00
// Execute query
$getRanks = Database::fetch('ranks', true);
2015-04-02 13:24:05 +00:00
// Reorder shit
foreach($getRanks as $rank)
$ranks[$rank['id']] = $rank;
2015-04-02 13:24:05 +00:00
// and return an array with the ranks
return $ranks;
2015-04-02 13:24:05 +00:00
}
}