@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) { |
76 | 76 | $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
77 | 77 | |
78 | - foreach($temporaryUsers as $forUser) { |
|
79 | - if(!$forUser->isBanned()) { |
|
78 | + foreach ($temporaryUsers as $forUser) { |
|
79 | + if (!$forUser->isBanned()) { |
|
80 | 80 | return $forUser; |
81 | 81 | } |
82 | 82 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | * @return UserModel |
94 | 94 | */ |
95 | 95 | private function retrieveUser(Request $request, ChocolateyId $chocolateyId) { |
96 | - if($chocolateyId->last_logged_id != 0) { |
|
96 | + if ($chocolateyId->last_logged_id != 0) { |
|
97 | 97 | $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
98 | 98 | |
99 | - if($temporaryUser->isBanned()) { |
|
99 | + if ($temporaryUser->isBanned()) { |
|
100 | 100 | return $this->checkForBanAlternative($request, $chocolateyId); |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
107 | 107 | |
108 | - if($temporaryUser->isBanned()) { |
|
108 | + if ($temporaryUser->isBanned()) { |
|
109 | 109 | return $this->checkForBanAlternative($request, $chocolateyId); |
110 | 110 | } |
111 | 111 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function hasSession() |
144 | 144 | { |
145 | - return (bool) Session::get(Config::get('chocolatey.security.session')); |
|
145 | + return (bool)Session::get(Config::get('chocolatey.security.session')); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -1,44 +1,44 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -namespace App\Helpers; |
|
3 | + namespace App\Helpers; |
|
4 | 4 | |
5 | -use App\Facades\Session; |
|
6 | -use App\Models\ChocolateyId; |
|
7 | -use App\Models\User as UserModel; |
|
8 | -use App\Singleton; |
|
9 | -use Illuminate\Http\Request; |
|
10 | -use Illuminate\Support\Facades\Config; |
|
5 | + use App\Facades\Session; |
|
6 | + use App\Models\ChocolateyId; |
|
7 | + use App\Models\User as UserModel; |
|
8 | + use App\Singleton; |
|
9 | + use Illuminate\Http\Request; |
|
10 | + use Illuminate\Support\Facades\Config; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Class User. |
14 | 14 | */ |
15 | -final class User extends Singleton |
|
16 | -{ |
|
17 | - /** |
|
15 | + final class User extends Singleton |
|
16 | + { |
|
17 | + /** |
|
18 | 18 | * Update User Data without overwriting Session. |
19 | 19 | * |
20 | 20 | * @param array $parameters |
21 | 21 | * |
22 | 22 | * @return UserModel |
23 | 23 | */ |
24 | - public function updateSession(array $parameters) |
|
25 | - { |
|
26 | - return $this->setSession($this->updateUser($this->getUser(), $parameters)); |
|
27 | - } |
|
24 | + public function updateSession(array $parameters) |
|
25 | + { |
|
26 | + return $this->setSession($this->updateUser($this->getUser(), $parameters)); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
29 | + /** |
|
30 | 30 | * Set User Data on Session. |
31 | 31 | * |
32 | 32 | * @param UserModel $user |
33 | 33 | * |
34 | 34 | * @return UserModel |
35 | 35 | */ |
36 | - public function setSession(UserModel $user) |
|
37 | - { |
|
38 | - return Session::set(Config::get('chocolatey.security.session'), $user); |
|
39 | - } |
|
36 | + public function setSession(UserModel $user) |
|
37 | + { |
|
38 | + return Session::set(Config::get('chocolatey.security.session'), $user); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
41 | + /** |
|
42 | 42 | * Update User Data by User Model. |
43 | 43 | * |
44 | 44 | * @param UserModel $user |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return UserModel |
48 | 48 | */ |
49 | - public function updateUser($user, array $parameters) |
|
50 | - { |
|
51 | - $user->update($parameters); |
|
49 | + public function updateUser($user, array $parameters) |
|
50 | + { |
|
51 | + $user->update($parameters); |
|
52 | 52 | |
53 | - return $user; |
|
54 | - } |
|
53 | + return $user; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
56 | + /** |
|
57 | 57 | * Get User Data from Session |
58 | 58 | * If User Session doesn't exists, return null. |
59 | 59 | * |
60 | 60 | * @return UserModel|null |
61 | 61 | */ |
62 | - public function getUser() |
|
63 | - { |
|
64 | - return Session::get(Config::get('chocolatey.security.session')) ?? null; |
|
65 | - } |
|
62 | + public function getUser() |
|
63 | + { |
|
64 | + return Session::get(Config::get('chocolatey.security.session')) ?? null; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
67 | + /** |
|
68 | 68 | * Retrieve Non Banned Users (If all Users are Banned, return the Banned user Also) |
69 | 69 | * |
70 | 70 | * @param Request $request |
@@ -72,19 +72,19 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return UserModel |
74 | 74 | */ |
75 | - private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) { |
|
76 | - $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
|
75 | + private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) { |
|
76 | + $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
|
77 | 77 | |
78 | - foreach($temporaryUsers as $forUser) { |
|
79 | - if(!$forUser->isBanned()) { |
|
80 | - return $forUser; |
|
81 | - } |
|
82 | - } |
|
78 | + foreach($temporaryUsers as $forUser) { |
|
79 | + if(!$forUser->isBanned()) { |
|
80 | + return $forUser; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - return $temporaryUsers->get(0); |
|
85 | - } |
|
84 | + return $temporaryUsers->get(0); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
87 | + /** |
|
88 | 88 | * Get Users |
89 | 89 | * |
90 | 90 | * @param Request $request |
@@ -92,64 +92,64 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return UserModel |
94 | 94 | */ |
95 | - private function retrieveUser(Request $request, ChocolateyId $chocolateyId) { |
|
96 | - if($chocolateyId->last_logged_id != 0) { |
|
97 | - $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
|
95 | + private function retrieveUser(Request $request, ChocolateyId $chocolateyId) { |
|
96 | + if($chocolateyId->last_logged_id != 0) { |
|
97 | + $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
|
98 | 98 | |
99 | - if($temporaryUser->isBanned()) { |
|
100 | - return $this->checkForBanAlternative($request, $chocolateyId); |
|
101 | - } |
|
99 | + if($temporaryUser->isBanned()) { |
|
100 | + return $this->checkForBanAlternative($request, $chocolateyId); |
|
101 | + } |
|
102 | 102 | |
103 | - return $temporaryUser; |
|
104 | - } |
|
103 | + return $temporaryUser; |
|
104 | + } |
|
105 | 105 | |
106 | - $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
|
106 | + $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
|
107 | 107 | |
108 | - if($temporaryUser->isBanned()) { |
|
109 | - return $this->checkForBanAlternative($request, $chocolateyId); |
|
110 | - } |
|
108 | + if($temporaryUser->isBanned()) { |
|
109 | + return $this->checkForBanAlternative($request, $chocolateyId); |
|
110 | + } |
|
111 | 111 | |
112 | - return $temporaryUser; |
|
113 | - } |
|
112 | + return $temporaryUser; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
115 | + /** |
|
116 | 116 | * Set Session From Login Credentials. |
117 | 117 | * |
118 | 118 | * @param Request $request |
119 | 119 | * |
120 | 120 | * @return UserModel |
121 | 121 | */ |
122 | - public function loginUser(Request $request) |
|
123 | - { |
|
124 | - $chocolateyId = ChocolateyId::find($request->json()->get('email')); |
|
122 | + public function loginUser(Request $request) |
|
123 | + { |
|
124 | + $chocolateyId = ChocolateyId::find($request->json()->get('email')); |
|
125 | 125 | |
126 | - if ($chocolateyId == null) { |
|
127 | - return null; |
|
128 | - } |
|
126 | + if ($chocolateyId == null) { |
|
127 | + return null; |
|
128 | + } |
|
129 | 129 | |
130 | - $user = $this->retrieveUser($request, $chocolateyId); |
|
130 | + $user = $this->retrieveUser($request, $chocolateyId); |
|
131 | 131 | |
132 | - $chocolateyId->last_logged_id = $user->uniqueId; |
|
132 | + $chocolateyId->last_logged_id = $user->uniqueId; |
|
133 | 133 | |
134 | - return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password')) |
|
135 | - ? $this->setSession($user) : null; |
|
136 | - } |
|
134 | + return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password')) |
|
135 | + ? $this->setSession($user) : null; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
138 | + /** |
|
139 | 139 | * Return if USer Session Exists. |
140 | 140 | * |
141 | 141 | * @return bool |
142 | 142 | */ |
143 | - public function hasSession() |
|
144 | - { |
|
145 | - return (bool) Session::get(Config::get('chocolatey.security.session')); |
|
146 | - } |
|
143 | + public function hasSession() |
|
144 | + { |
|
145 | + return (bool) Session::get(Config::get('chocolatey.security.session')); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
148 | + /** |
|
149 | 149 | * Erase User Session. |
150 | 150 | */ |
151 | - public function eraseSession() |
|
152 | - { |
|
153 | - Session::erase(Config::get('chocolatey.security.session')); |
|
154 | - } |
|
151 | + public function eraseSession() |
|
152 | + { |
|
153 | + Session::erase(Config::get('chocolatey.security.session')); |
|
154 | + } |
|
155 | 155 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | { |
140 | 140 | $ban = Ban::where('user_id', $this->attributes['id'])->first(); |
141 | 141 | |
142 | - if($ban == null) { |
|
142 | + if ($ban == null) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | { |
293 | 293 | $accountCreated = $this->attributes['account_created'] ?? time(); |
294 | 294 | |
295 | - return date('Y-m-d', $accountCreated).'T'.date('H:i:s.ZZZZ+ZZZZ', $accountCreated); |
|
295 | + return date('Y-m-d', $accountCreated) . 'T' . date('H:i:s.ZZZZ+ZZZZ', $accountCreated); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | { |
305 | 305 | $accountCreated = $this->attributes['account_created'] ?? time(); |
306 | 306 | |
307 | - return date('Y-m-d', $accountCreated).'T'.date('H:i:s.ZZZZ+ZZZZ', $accountCreated); |
|
307 | + return date('Y-m-d', $accountCreated) . 'T' . date('H:i:s.ZZZZ+ZZZZ', $accountCreated); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | { |
327 | 327 | $lastLogin = $this->attributes['last_login'] ?? time(); |
328 | 328 | |
329 | - return date('Y-m-d', $lastLogin).'T'.date('H:i:s.ZZZZ+ZZZZ', $lastLogin); |
|
329 | + return date('Y-m-d', $lastLogin) . 'T' . date('H:i:s.ZZZZ+ZZZZ', $lastLogin); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |