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