Completed
Push — development ( 637a74...b2f2cf )
by Claudio
20:44 queued 18:07
created
app/Helpers/User.php 1 patch
Switch Indentation   +80 added lines, -80 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 (If all Users are Banned, return the Banned user Also).
69 69
      *
70 70
      * @param Request      $request
@@ -72,20 +72,20 @@  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();
75
+     private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId)
76
+     {
77
+         $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get();
78 78
 
79
-        foreach ($temporaryUsers as $forUser) {
80
-            if (!$forUser->isBanned) {
81
-                return $forUser;
82
-            }
83
-        }
79
+         foreach ($temporaryUsers as $forUser) {
80
+             if (!$forUser->isBanned) {
81
+                 return $forUser;
82
+             }
83
+         }
84 84
 
85
-        return $temporaryUsers->get(0);
86
-    }
85
+         return $temporaryUsers->get(0);
86
+     }
87 87
 
88
-    /**
88
+     /**
89 89
      * Get Users.
90 90
      *
91 91
      * @param Request      $request
@@ -93,65 +93,65 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return UserModel
95 95
      */
96
-    private function retrieveUser(Request $request, ChocolateyId $chocolateyId)
97
-    {
98
-        if ($chocolateyId->last_logged_id != 0) {
99
-            $temporaryUser = UserModel::find($chocolateyId->last_logged_id);
96
+     private function retrieveUser(Request $request, ChocolateyId $chocolateyId)
97
+     {
98
+         if ($chocolateyId->last_logged_id != 0) {
99
+             $temporaryUser = UserModel::find($chocolateyId->last_logged_id);
100 100
 
101
-            if ($temporaryUser->isBanned) {
102
-                return $this->checkForBanAlternative($request, $chocolateyId);
103
-            }
101
+             if ($temporaryUser->isBanned) {
102
+                 return $this->checkForBanAlternative($request, $chocolateyId);
103
+             }
104 104
 
105
-            return $temporaryUser;
106
-        }
105
+             return $temporaryUser;
106
+         }
107 107
 
108
-        $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first();
108
+         $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first();
109 109
 
110
-        if ($temporaryUser->isBanned) {
111
-            return $this->checkForBanAlternative($request, $chocolateyId);
112
-        }
110
+         if ($temporaryUser->isBanned) {
111
+             return $this->checkForBanAlternative($request, $chocolateyId);
112
+         }
113 113
 
114
-        return $temporaryUser;
115
-    }
114
+         return $temporaryUser;
115
+     }
116 116
 
117
-    /**
117
+     /**
118 118
      * Set Session From Login Credentials.
119 119
      *
120 120
      * @param Request $request
121 121
      *
122 122
      * @return UserModel
123 123
      */
124
-    public function loginUser(Request $request)
125
-    {
126
-        $chocolateyId = ChocolateyId::find($request->json()->get('email'));
124
+     public function loginUser(Request $request)
125
+     {
126
+         $chocolateyId = ChocolateyId::find($request->json()->get('email'));
127 127
 
128
-        if ($chocolateyId == null) {
129
-            return;
130
-        }
128
+         if ($chocolateyId == null) {
129
+             return;
130
+         }
131 131
 
132
-        $user = $this->retrieveUser($request, $chocolateyId);
132
+         $user = $this->retrieveUser($request, $chocolateyId);
133 133
 
134
-        $chocolateyId->last_logged_id = $user->uniqueId;
134
+         $chocolateyId->last_logged_id = $user->uniqueId;
135 135
 
136
-        return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password'))
137
-            ? $this->setSession($user) : null;
138
-    }
136
+         return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password'))
137
+             ? $this->setSession($user) : null;
138
+     }
139 139
 
140
-    /**
140
+     /**
141 141
      * Return if USer Session Exists.
142 142
      *
143 143
      * @return bool
144 144
      */
145
-    public function hasSession()
146
-    {
147
-        return (bool) Session::get(Config::get('chocolatey.security.session'));
148
-    }
145
+     public function hasSession()
146
+     {
147
+         return (bool) Session::get(Config::get('chocolatey.security.session'));
148
+     }
149 149
 
150
-    /**
150
+     /**
151 151
      * Erase User Session.
152 152
      */
153
-    public function eraseSession()
154
-    {
155
-        Session::erase(Config::get('chocolatey.security.session'));
156
-    }
153
+     public function eraseSession()
154
+     {
155
+         Session::erase(Config::get('chocolatey.security.session'));
156
+     }
157 157
 }
Please login to merge, or discard this patch.