Completed
Pull Request — development (#227)
by Claudio
05:24 queued 02:41
created
app/Helpers/User.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
      */
123 123
     public function hasSession()
124 124
     {
125
-        return (bool) Session::get(Config::get('chocolatey.security.session'));
125
+        return (bool)Session::get(Config::get('chocolatey.security.session'));
126 126
     }
127 127
 
128 128
     /**
Please login to merge, or discard this patch.
Switch Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,44 +1,44 @@  discard block
 block discarded – undo
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
 block discarded – undo
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.
69 69
      *
70 70
      * @param Request      $request
@@ -72,18 +72,18 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @return UserModel
74 74
      */
75
-    private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId)
76
-    {
77
-        $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get();
78
-
79
-        foreach ($temporaryUsers as $forUser) {
80
-            if (!$forUser->isBanned()) {
81
-                return $forUser;
82
-            }
83
-        }
84
-    }
85
-
86
-    /**
75
+     private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId)
76
+     {
77
+         $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get();
78
+
79
+         foreach ($temporaryUsers as $forUser) {
80
+             if (!$forUser->isBanned()) {
81
+                 return $forUser;
82
+             }
83
+         }
84
+     }
85
+
86
+     /**
87 87
      * Get Users.
88 88
      *
89 89
      * @param Request      $request
@@ -91,65 +91,65 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @return UserModel
93 93
      */
94
-    private function retrieveUser(Request $request, ChocolateyId $chocolateyId)
95
-    {
96
-        if ($chocolateyId->last_logged_id != 0) {
97
-            $temporaryUser = UserModel::find($chocolateyId->last_logged_id);
94
+     private function retrieveUser(Request $request, ChocolateyId $chocolateyId)
95
+     {
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;
128
-        }
126
+         if ($chocolateyId == null) {
127
+             return;
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
 }
Please login to merge, or discard this patch.