This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
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 function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
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 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. ![]() |
|||
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 function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
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. ![]() |
|||
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. ![]() |
|||
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 |
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.