@@ -4,7 +4,6 @@ |
||
4 | 4 | use App\Http\Models\Api; |
5 | 5 | use Illuminate\Http\Request; |
6 | 6 | use Illuminate\Support\Facades\Auth; |
7 | -use Illuminate\Support\Facades\Input; |
|
8 | 7 | |
9 | 8 | |
10 | 9 | /** |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | 'created' => new \DateTime("now"), |
35 | 35 | ]; |
36 | 36 | |
37 | - try{ |
|
37 | + try { |
|
38 | 38 | $collection->insertOne($stat); |
39 | - }catch (\Exception $e){ |
|
40 | - return response()->json(['state' => false]); |
|
39 | + } catch (\Exception $e) { |
|
40 | + return response()->json([ 'state' => false ]); |
|
41 | 41 | } |
42 | 42 | |
43 | - $data["email"] = $request->email; |
|
44 | - return response()->json(['data' => $data, 'state' => true]); |
|
43 | + $data[ "email" ] = $request->email; |
|
44 | + return response()->json([ 'data' => $data, 'state' => true ]); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | $collection = new \MongoDB\Collection($manager, 'builders', 'account'); |
58 | 58 | |
59 | 59 | |
60 | - if ($collection->count(["email" => $email]) == 0) { |
|
61 | - return response()->json(['data' => "User doesn't exist", 'state' => false]); |
|
60 | + if ($collection->count([ "email" => $email ]) == 0) { |
|
61 | + return response()->json([ 'data' => "User doesn't exist", 'state' => false ]); |
|
62 | 62 | } |
63 | 63 | |
64 | - $user = $collection->findOne(["email" => $email])->bsonSerialize(); |
|
64 | + $user = $collection->findOne([ "email" => $email ])->bsonSerialize(); |
|
65 | 65 | |
66 | - if(password_verify($password, $user->password) == false){ |
|
67 | - return response()->json(['data' => "Bad email or password", 'state' => false]); |
|
66 | + if (password_verify($password, $user->password) == false) { |
|
67 | + return response()->json([ 'data' => "Bad email or password", 'state' => false ]); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $api = new Api($user); |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | |
73 | 73 | dump(Auth::user()); |
74 | 74 | |
75 | - return response()->json(['data' => $user, 'state' => true]); |
|
75 | + return response()->json([ 'data' => $user, 'state' => true ]); |
|
76 | 76 | |
77 | 77 | } else { |
78 | - return response()->json(['data' => "Invalid parameters", 'state' => false]); |
|
78 | + return response()->json([ 'data' => "Invalid parameters", 'state' => false ]); |
|
79 | 79 | } |
80 | 80 | |
81 | - return response()->json(['data' => "Bad credentials", 'state' => false]); |
|
81 | + return response()->json([ 'data' => "Bad credentials", 'state' => false ]); |
|
82 | 82 | } |
83 | 83 | /** |
84 | 84 | * Auth |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | |
100 | 100 | if ($auth->attempt($credentials) && auth()->guard('user')->check()) { |
101 | 101 | |
102 | - return response()->json(['data' => auth()->guard('user')->user()->toArray(), 'state' => true]); |
|
102 | + return response()->json([ 'data' => auth()->guard('user')->user()->toArray(), 'state' => true ]); |
|
103 | 103 | } else { |
104 | - return response()->json(['data' => "Bad email or password", 'state' => false]); |
|
104 | + return response()->json([ 'data' => "Bad email or password", 'state' => false ]); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } else { |
108 | - return response()->json(['data' => "Invalid parameters", 'state' => false]); |
|
108 | + return response()->json([ 'data' => "Invalid parameters", 'state' => false ]); |
|
109 | 109 | } |
110 | 110 | |
111 | - return response()->json(['data' => "Bad credentials", 'state' => false]); |
|
111 | + return response()->json([ 'data' => "Bad credentials", 'state' => false ]); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | |
122 | 122 | $result = $collection->find()->toArray(); |
123 | 123 | |
124 | - $tab = []; |
|
125 | - foreach($result as $one){ |
|
126 | - $tab[] = $one->bsonSerialize(); |
|
124 | + $tab = [ ]; |
|
125 | + foreach ($result as $one) { |
|
126 | + $tab[ ] = $one->bsonSerialize(); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | return response()->json($tab); |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | 'created' => new \DateTime("now"), |
151 | 151 | ]; |
152 | 152 | |
153 | - try{ |
|
154 | - $collection->updateOne(["email" => $request->email], $stat); |
|
155 | - }catch (\Exception $e){ |
|
156 | - return response()->json(['state' => false]); |
|
153 | + try { |
|
154 | + $collection->updateOne([ "email" => $request->email ], $stat); |
|
155 | + } catch (\Exception $e) { |
|
156 | + return response()->json([ 'state' => false ]); |
|
157 | 157 | } |
158 | 158 | |
159 | - $data["email"] = $request->email; |
|
160 | - return response()->json(['data' => $data, 'state' => true]); |
|
159 | + $data[ "email" ] = $request->email; |
|
160 | + return response()->json([ 'data' => $data, 'state' => true ]); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * @param array $user |
29 | 29 | */ |
30 | - public function __construct($user){ |
|
30 | + public function __construct($user) { |
|
31 | 31 | $this->user = $user; |
32 | 32 | $this->email = $user->email; |
33 | 33 | $this->password = $user->password; |