some fixes in the user obj

This commit is contained in:
flash 2016-12-07 16:20:40 +01:00
parent 4b3aeb6149
commit dd35ceb85f

View file

@ -294,12 +294,10 @@ class User
*/
public static function create(string $username, string $password, string $email, array $ranks = [2]): User
{
// Set a few variables
$usernameClean = clean_string($username, true);
$emailClean = clean_string($email, true);
$password = password_hash($password, PASSWORD_BCRYPT);
// Insert the user into the database and get the id
$userId = DB::table('users')
->insertGetId([
'username' => $username,
@ -314,16 +312,10 @@ class User
'user_country' => get_country_code(),
]);
// Create a user object
$user = self::construct($userId);
// Assign the default rank
$user = static::construct($userId);
$user->addRanks($ranks);
// Set the default rank
$user->setMainRank($ranks[0]);
// Return the user object
return $user;
}
@ -333,13 +325,11 @@ class User
*/
private function __construct($userId)
{
// Get the user database row
$userRow = DB::table('users')
->where('user_id', $userId)
->orWhere('username_clean', clean_string($userId, true))
->first();
// Populate the variables
if ($userRow) {
$this->id = intval($userRow->user_id);
$this->username = $userRow->username;
@ -426,16 +416,10 @@ class User
$this->setMainRank($this->mainRankId);
}
// Assign the main rank to its own var
$this->mainRank = $this->ranks[$this->mainRankId];
// Set user colour
$this->colour = $this->colour ? $this->colour : $this->mainRank->colour;
// Set user title
$this->title = $this->title ? $this->title : $this->mainRank->title;
// Init the permissions
$this->perms = new UserPerms($this);
}
@ -875,20 +859,12 @@ class User
$premiumRank = (int) config('rank.premium');
$defaultRank = (int) config('rank.regular');
// Fetch expiration date
$expire = $this->premiumInfo()->expire;
// Check if the user has static premium
if (!$expire) {
$expire = time() + 1;
}
// Check if the user has premium and isn't in the premium rank
if ($expire && !$this->hasRanks([$premiumRank])) {
// Add the premium rank
$this->addRanks([$premiumRank]);
// Set it as default
if ($this->mainRankId == $defaultRank) {
$this->setMainRank($premiumRank);
}