GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 27d472...cbeecf )
by Dane
02:46
created

User::access()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 4
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace Pterodactyl\Models;
26
27
use Hash;
28
use Google2FA;
29
use Illuminate\Auth\Authenticatable;
30
use Illuminate\Database\Eloquent\Model;
31
use Illuminate\Notifications\Notifiable;
32
use Pterodactyl\Exceptions\DisplayException;
33
use Nicolaslopezj\Searchable\SearchableTrait;
34
use Illuminate\Auth\Passwords\CanResetPassword;
35
use Illuminate\Foundation\Auth\Access\Authorizable;
36
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
37
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
38
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
39
use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
40
41
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
42
{
43
    use Authenticatable, Authorizable, CanResetPassword, Notifiable, SearchableTrait;
44
45
    /**
46
     * The rules for user passwords.
47
     *
48
     * @var string
49
     */
50
    const PASSWORD_RULES = 'regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})';
51
52
    /**
53
     * The regex rules for usernames.
54
     *
55
     * @var string
56
     */
57
    const USERNAME_RULES = 'regex:/^([\w\d\.\-]{1,255})$/';
58
59
    /**
60
     * The table associated with the model.
61
     *
62
     * @var string
63
     */
64
    protected $table = 'users';
65
66
    /**
67
     * A list of mass-assignable variables.
68
     *
69
     * @var array
70
     */
71
    protected $fillable = ['username', 'email', 'name_first', 'name_last', 'password', 'language', 'use_totp', 'totp_secret', 'gravatar', 'root_admin'];
72
73
    /**
74
     * Cast values to correct type.
75
     *
76
     * @var array
77
     */
78
    protected $casts = [
79
        'root_admin' => 'integer',
80
        'use_totp' => 'integer',
81
        'gravatar' => 'integer',
82
    ];
83
84
    /**
85
     * The attributes excluded from the model's JSON form.
86
     *
87
     * @var array
88
     */
89
    protected $hidden = ['password', 'remember_token', 'totp_secret'];
90
91
    /**
92
     * Parameters for search querying.
93
     *
94
     * @var array
95
     */
96
    protected $searchable = [
97
        'columns' => [
98
            'email' => 10,
99
            'username' => 9,
100
            'name_first' => 6,
101
            'name_last' => 6,
102
            'uuid' => 1,
103
        ],
104
    ];
105
106
    protected $query;
107
108
    /**
109
     * Enables or disables TOTP on an account if the token is valid.
110
     *
111
     * @param  int  $token
112
     * @return bool
113
     */
114
    public function toggleTotp($token)
115
    {
116
        if (! Google2FA::verifyKey($this->totp_secret, $token, 1)) {
0 ignored issues
show
Documentation introduced by
The property totp_secret does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
117
            return false;
118
        }
119
120
        $this->use_totp = ! $this->use_totp;
0 ignored issues
show
Documentation introduced by
The property use_totp does not exist on object<Pterodactyl\Models\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property use_totp does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
122
        return $this->save();
123
    }
124
125
    /**
126
     * Set a user password to a new value assuming it meets the following requirements:
127
     *      - 8 or more characters in length
128
     *      - at least one uppercase character
129
     *      - at least one lowercase character
130
     *      - at least one number.
131
     *
132
     * @param  string  $password
133
     * @param  string  $regex
134
     * @return void
135
     */
136
    public function setPassword($password, $regex = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})')
137
    {
138
        if (! preg_match($regex, $password)) {
139
            throw new DisplayException('The password passed did not meet the minimum password requirements.');
140
        }
141
142
        $this->password = Hash::make($password);
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<Pterodactyl\Models\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143
        $this->save();
144
    }
145
146
    /**
147
     * Send the password reset notification.
148
     *
149
     * @param  string  $token
150
     * @return void
151
     */
152
    public function sendPasswordResetNotification($token)
153
    {
154
        $this->notify(new ResetPasswordNotification($token));
155
    }
156
157
    /**
158
     * Return true or false depending on wether the user is root admin or not.
159
     *
160
     * @return bool
161
     */
162
    public function isRootAdmin()
163
    {
164
        return $this->root_admin === 1;
0 ignored issues
show
Documentation introduced by
The property root_admin does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
165
    }
166
167
    /**
168
     * Returns the user's daemon secret for a given server.
169
     *
170
     * @param  \Pterodactyl\Models\Server  $server
171
     * @return null|string
172
     */
173
    public function daemonToken(Server $server)
174
    {
175
        if ($this->id === $server->owner_id || $this->isRootAdmin()) {
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property owner_id does not exist on object<Pterodactyl\Models\Server>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
176
            return $server->daemonSecret;
0 ignored issues
show
Documentation introduced by
The property daemonSecret does not exist on object<Pterodactyl\Models\Server>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
177
        }
178
179
        $subuser = Subuser::where('server_id', $server->id)->where('user_id', $this->id)->first();
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\Server>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
180
181
        if (is_null($subuser)) {
182
            return null;
183
        }
184
185
        return $subuser->daemonSecret;
186
    }
187
188
    /**
189
     * Returns an array of all servers a user is able to access.
190
     * Note: does not account for user admin status.
191
     *
192
     * @return array
193
     */
194
    public function serverAccessArray()
195
    {
196
        $union = Subuser::select('server_id')->where('user_id', $this->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
197
198
        return Server::select('id')->where('owner_id', $this->id)->union($union)->pluck('id')->all();
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Pterodactyl\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method select() does not exist on Pterodactyl\Models\Server. Did you maybe mean addSelectsToQuery()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
199
    }
200
201
    /**
202
     * Returns an array of all servers a user is able to access.
203
     * Note: does not account for user admin status.
204
     *
205
     * @param  array        $load
206
     * @return \Illuiminate\Database\Eloquent\Builder
207
     */
208
    public function access(...$load)
209
    {
210
        if (count($load) > 0 && is_null($load[0])) {
211
            $query = Server::query();
212
        } else {
213
            $query = Server::with(! empty($load) ? $load : ['service', 'node', 'allocation']);
214
        }
215
216
        if (! $this->isRootAdmin()) {
217
            $query->whereIn('id', $this->serverAccessArray());
218
        }
219
220
        return $query;
221
    }
222
223
    /**
224
     * Returns all permissions that a user has.
225
     *
226
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
227
     */
228
    public function permissions()
229
    {
230
        return $this->hasManyThrough(Permission::class, Subuser::class);
231
    }
232
233
    /**
234
     * Returns all servers that a user owns.
235
     *
236
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
237
     */
238
    public function servers()
239
    {
240
        return $this->hasMany(Server::class, 'owner_id');
241
    }
242
}
243