Issues (115)

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/Http/Controllers/BuildersController.php (6 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\Http\Controllers;
4
use App\Http\Models\Api;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Input;
8
use LukePOLO\LaraCart\Facades\LaraCart;
9
10
11
/**
12
 * Class BuildersController.
13
 */
14
class BuildersController extends Controller
15
{
16
17
    /**
18
     * Create account
19
     */
20 View Code Duplication
    public function createAccount(Request $request)
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...
21
    {
22
        $data = [
23
          "name" => $request->name,
24
          "cp" => $request->cp,
25
          "phone" => $request->phone,
26
          "sexe" => $request->sexe,
27
          "news" => $request->news,
28
        ];
29
30
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
31
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
32
        $stat = [
33
            'email'    => $request->email,
34
            'data'    => $data,
35
            'created' => new  \DateTime("now"),
36
        ];
37
38
        try{
39
            $collection->insertOne($stat);
40
        }catch (\Exception $e){
41
            return response()->json(['state' => false]);
42
        }
43
44
        $data["email"] = $request->email;
45
        return response()->json(['data' => $data, 'state' => true]);
46
    }
47
48
    /**
49
     * Auth
50
     */
51
    public function connect(Request $request)
52
    {
53
        $email = $request->email;
54
        $password = $request->password;
55
56
        if (!empty($email) && !empty($password)) {
57
            $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
58
            $collection = new \MongoDB\Collection($manager, 'builders', 'account');
59
60
61
            if ($collection->count(["email" => $email]) == 0) {
62
                return response()->json(['data' => "User doesn't exist", 'state' => false]);
63
            }
64
65
            $user = $collection->findOne(["email" => $email])->bsonSerialize();
66
67
            if(password_verify($password, $user->password) == false){
68
                return response()->json(['data' => "Bad email or password", 'state' => false]);
69
            }
70
71
            $api = new Api($user);
72
            Auth::login($api);
73
74
            return response()->json(['data' => $user, 'state' => true]);
75
76
        } else {
77
            return response()->json(['data' => "Invalid parameters", 'state' => false]);
78
        }
79
80
        return response()->json(['data' => "Bad credentials", 'state' => false]);
0 ignored issues
show
return response()->json(...s', 'state' => false)); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
81
    }
82
83
    /**
84
     * Auth
85
     */
86
    public function disconnect()
87
    {
88
        if (auth()->guard('api')->check()) {
89
90
            Auth::logout();
91
92
            return response()->json(['state' => true]);
93
94
        } else {
95
96
            return response()->json(['state' => false]);
97
        }
98
99
    }
100
101
102
    /**
103
     * Auth
104
     */
105
    public function getAnnouncesCart()
106
    {
107
108
        $items = LaraCart::getItems();
109
110
        return response()->json(['data' => $items, 'state' => true]);
111
    }
112
113
114
115
    /**
116
     * Auth
117
     */
118
    public function addAnnounceCart(Request $request)
119
    {
120
        $id = $request->id;
121
        $title = $request->title;
122
        $quantity = $request->quantity;
123
        $prix = $request->prix;
124
        $options = $request->options;
125
126
        $item = LaraCart::add($id, $title, $quantity, $prix, ['size' => $options ]);
127
128
        return response()->json(['data' => $item, 'state' => true]);
129
    }
130
131
132
    /**
133
     * Auth
134
     */
135
    public function removeAnnounceCart(Request $request)
136
    {
137
        $hash = $request->hash;
138
139
        LaraCart::removeItem($hash);
140
141
        $items = LaraCart::getItems();
142
143
        return response()->json(['data' => $items, 'state' => true]);
144
    }
145
146
147
    /**
148
     * Auth
149
     */
150
    public function getTotalAnnouncesCart()
151
    {
152
        $data['subtotal'] = LaraCart::subTotal($tax = false, $format = true, $withDiscount = true);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
153
        $data['totaldiscount'] = LaraCart::totalDiscount($formatted = false);
154
        $data['taxtotal'] = LaraCart::taxTotal($formatted = false);
155
        $data['total'] = LaraCart::total($formatted = false, $withDiscount = true);
156
157
        return response()->json(['data' => $data, 'state' => true]);
158
    }
159
160
161
    /**
162
     * Auth
163
     */
164
    public function connectAlreadyExist(Request $request)
165
    {
166
        $email = $request->email;
167
        $password = $request->password;
168
169
        if (!empty($email) && !empty($password)) {
170
                $auth = auth()->guard('user');
171
172
                $credentials = [
173
                    'email' =>  $email,
174
                    'password' =>  $password,
175
                    'enabled' => true
176
                ];
177
178
                if ($auth->attempt($credentials) && auth()->guard('user')->check()) {
179
180
                    return response()->json(['data' => auth()->guard('user')->user()->toArray(), 'state' => true]);
181
                } else {
182
                    return response()->json(['data' => "Bad email or password", 'state' => false]);
183
                }
184
185
        } else {
186
            return response()->json(['data' => "Invalid parameters", 'state' => false]);
187
        }
188
189
        return response()->json(['data' => "Bad credentials", 'state' => false]);
0 ignored issues
show
return response()->json(...s', 'state' => false)); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
190
    }
191
192
    /**
193
     * List account
194
     */
195 View Code Duplication
    public function listAccount()
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...
196
    {
197
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
198
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
199
200
        $result = $collection->find()->toArray();
201
202
        $tab = [];
203
        foreach($result as $one){
204
            $tab[] = $one->bsonSerialize();
205
        }
206
207
        return response()->json($tab);
208
    }
209
210
211
212
    /**
213
     * Update account
214
     */
215 View Code Duplication
    public function updateAccount(Request $request)
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...
216
    {
217
        $data = [
218
          "name" => $request->name,
219
          "cp" => $request->cp,
220
          "phone" => $request->phone,
221
          "sexe" => $request->sexe,
222
          "news" => $request->news,
223
        ];
224
225
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
226
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
227
        $stat = [
228
            'email'    => $request->email,
229
            'data'    => $data,
230
            'created' => new  \DateTime("now"),
231
        ];
232
233
        try{
234
            $collection->updateOne(["email" => $request->email], $stat);
235
        }catch (\Exception $e){
236
            return response()->json(['state' => false]);
237
        }
238
239
        $data["email"] = $request->email;
240
        return response()->json(['data' => $data, 'state' => true]);
241
    }
242
243
}
244