|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Facades\Nux; |
|
6
|
|
|
use App\Facades\User as UserFacade; |
|
7
|
|
|
use App\Facades\Validation; |
|
8
|
|
|
use App\Models\NuxValidation; |
|
9
|
|
|
use App\Models\User; |
|
10
|
|
|
use Illuminate\Http\JsonResponse; |
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
use Illuminate\Http\Response; |
|
13
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class NuxController. |
|
17
|
|
|
*/ |
|
18
|
|
|
class NuxController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Check an User Name. |
|
22
|
|
|
* |
|
23
|
|
|
* @param Request $request |
|
24
|
|
|
* |
|
25
|
|
|
* @return JsonResponse |
|
26
|
|
|
*/ |
|
27
|
|
|
public function checkName(Request $request): JsonResponse |
|
28
|
|
|
{ |
|
29
|
|
|
if (User::where('username', $request->json()->get('name'))->where('id', '<>', UserFacade::getUser()->uniqueId)->count() > 0) { |
|
30
|
|
|
return response()->json(new NuxValidation('NAME_IN_USE')); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (!Validation::filterUserName($request->json()->get('name'))) { |
|
34
|
|
|
return response()->json(new NuxValidation('INVALID_NAME', ['resultType' => 'VALIDATION_ERROR_ILLEGAL_WORDS'])); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return response()->json(new NuxValidation()); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Select an User Name. |
|
42
|
|
|
* |
|
43
|
|
|
* @param Request $request |
|
44
|
|
|
* |
|
45
|
|
|
* @return JsonResponse |
|
46
|
|
|
*/ |
|
47
|
|
|
public function selectName(Request $request): JsonResponse |
|
48
|
|
|
{ |
|
49
|
|
|
UserFacade::updateSession(['username' => $request->json()->get('name')]); |
|
50
|
|
|
|
|
51
|
|
|
return response()->json(new NuxValidation()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Select a Room. |
|
56
|
|
|
* |
|
57
|
|
|
* @param Request $request |
|
58
|
|
|
* |
|
59
|
|
|
* @return Response |
|
60
|
|
|
*/ |
|
61
|
|
|
public function selectRoom(Request $request): Response |
|
62
|
|
|
{ |
|
63
|
|
|
if (!in_array($request->json()->get('roomIndex'), [1, 2, 3])) { |
|
64
|
|
|
return response('', 400); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
Nux::generateRoom($request); |
|
68
|
|
|
|
|
69
|
|
|
UserFacade::getUser()->traits = ['USER']; |
|
70
|
|
|
|
|
71
|
|
|
return response(null, 200); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: