Issues (20)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

app/Models/User.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Models;
4
5
use App\Support\Image\Filters\Fit;
6
use App\Support\Traits\ImageStorage;
7
use Iatstuti\Database\Support\NullableFields;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
use Illuminate\Notifications\Notifiable;
10
use Illuminate\Support\Facades\Request;
11
12
class User extends Authenticatable
13
{
14
    use NullableFields, ImageStorage, Notifiable;
15
16
    /**
17
     * The user status.
18
     */
19
    const STATUS_NORMAL = 1;
20
21
    /**
22
     * The directory stores all users' avatars.
23
     */
24
    const AVATAR_DIRECTORY = 'avatar';
25
26
    /**
27
     * The avatar size.
28
     */
29
    const AVATAR_SIZE = 200;
30
    const ORIGINAL_AVATAR_SIZE = 640;
31
32
    /**
33
     * The attributes that should be visible in arrays.
34
     *
35
     * @var array
36
     */
37
    protected $visible = [
38
        'id', 'email', 'phone', 'username', 'avatar', 'original_avatar', 'status',
39
    ];
40
41
    /**
42
     * The attributes that should be mutated to dates.
43
     *
44
     * @var array
45
     */
46
    protected $dates = ['last_login_at'];
47
48
    /**
49
     * The attributes that should be saved as null when empty.
50
     *
51
     * @var array
52
     */
53
    protected $nullable = [
54
        'email', 'phone', 'username', 'avatar', 'original_avatar',
55
        'last_login_ip', 'registered_ip',
56
    ];
57
58
    /**
59
     * The model's attributes.
60
     *
61
     * @var array
62
     */
63
    protected $attributes = [
64
        'status' => 1,
65
        'login_count' => 0,
66
    ];
67
68
    /**
69
     * Get the `avatar` attribute.
70
     *
71
     * @param  string|null  $value
72
     * @return string|null
73
     */
74
    public function getAvatarAttribute($value)
75
    {
76
        return $this->getAssetUrl($value, 'avatar');
77
    }
78
79
    /**
80
     * Set the `avatar` attribute.
81
     *
82
     * @param  string|null  $value
83
     */
84
    public function setAvatarAttribute($value)
85
    {
86
        $this->attributes['avatar'] = $value;
87
    }
88
89
    /**
90
     * Get the `original_avatar` attribute.
91
     *
92
     * @param  string|null  $value
93
     * @return string|null
94
     */
95
    public function getOriginalAvatarAttribute($value)
96
    {
97
        return $this->getAssetUrl($value, 'original_avatar');
98
    }
99
100
    /**
101
     * Set the `original_avatar` attribute.
102
     *
103
     * @param  string|null  $value
104
     */
105
    public function setOriginalAvatarAttribute($value)
106
    {
107
        $this->attributes['original_avatar'] = $value;
108
    }
109
110
    /**
111
     * Update login info.
112
     *
113
     * @param  bool  $save
114
     * @return $this
115
     */
116
    public function updateLoginInfo($save = true)
117
    {
118
        $this->login_count++;
119
        $this->last_login_at = $this->freshTimestamp();
120
        $this->last_login_ip = Request::ip();
121
122
        if ($save) {
123
            $this->save();
124
        }
125
126
        return $this;
127
    }
128
129
    /**
130
     * Update user info from social user.
131
     *
132
     * @param  mixed  $social
133
     * @param  array  $user
134
     * @param  bool  $save
135
     */
136
    public function updateUserInfoWithSocialUser($social, $user, $save = false)
137
    {
138
        $this->storeAvatarFile(SocialAuth::getAvatarFromSocialUser($social, $user));
139
140
        $this->username = str_limit2(SocialAuth::getUsernameFromSocialUser($social, $user), 10);
141
142
        if ($save) {
143
            $this->save();
144
        }
145
    }
146
147
    /**
148
     * Store the given file as user's avatar.
149
     *
150
     * @param  mixed  $file
151
     * @return bool
152
     */
153
    public function storeAvatarFile($file)
154
    {
155
        if (is_string($file) && filter_var($file, FILTER_VALIDATE_URL) !== false) {
156
            $file = app('image')->make($file);
157
        }
158
159
        if (($avatar = $this->storeImageFile(clone $file, 'avatar')) &&
160
            ($original_avatar = $this->storeImageFile($file, 'original_avatar'))
161
        ) {
162
            $this->avatar = $avatar;
163
            $this->original_avatar = $original_avatar;
0 ignored issues
show
The property original_avatar does not seem to exist. Did you mean original?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
164
165
            return true;
166
        }
167
168
        return false;
169
    }
170
171
    /**
172
     * Get image filter.
173
     *
174
     * @see http://image.intervention.io/api/filter
175
     *
176
     * @param  string|null  $identifier
177
     */
178
    protected function getImageFilter($identifier = null)
179
    {
180
        return (new Fit)->width(constant('static::'.strtoupper($identifier).'_SIZE'));
181
    }
182
183
    /**
184
     * Get image directory for the given attribute.
185
     *
186
     * @param  string  $attribute
187
     * @return string
188
     */
189
    protected function getImageDirectory($attribute)
190
    {
191
        return static::AVATAR_DIRECTORY.'/'.dechex((int) date('Y') - 2010).'/'.dechex(date('W'));
192
    }
193
194
    /**
195
     * Get user's devices.
196
     *
197
     * @param  bool  $withTrashed
198
     * @return \Illuminate\Support\Collection
199
     */
200 View Code Duplication
    public function getDevices($withTrashed = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
201
    {
202
        return Device::whereIn('id', function ($query) use ($withTrashed) {
203
            $query->select('device_id')->from('user_devices')->where('user_id', $this->id);
204
205
            if (! $withTrashed) {
206
                $query->where('deleted_at', null);
207
            }
208
        })->get();
209
    }
210
}
211