From dd35ceb85f96adbbb9079c2d64617cd0362d0a3e Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 7 Dec 2016 16:20:40 +0100 Subject: [PATCH] some fixes in the user obj --- app/User.php | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/app/User.php b/app/User.php index 1394555..14efd7c 100644 --- a/app/User.php +++ b/app/User.php @@ -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); }