Completed
Push — master ( 456045...7e51b9 )
by Sherif
04:39
created
src/Modules/Acl/Proxy/LoginProxy.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -5,95 +5,95 @@
 block discarded – undo
5 5
 
6 6
 class LoginProxy
7 7
 {
8
-    private $apiConsumer;
9
-
10
-    private $auth;
11
-
12
-    private $request;
13
-
14
-    private $userRepository;
15
-
16
-    public function __construct(Application $app) 
17
-    {
18
-
19
-        $this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository');
20
-        $this->apiConsumer    = $app->make('apiconsumer');
21
-        $this->auth           = $app->make('auth');
22
-        $this->request        = $app->make('request');
23
-    }
24
-
25
-    /**
26
-     * Attempt to create an access token using user credentials.
27
-     *
28
-     * @param  array   $credentials
29
-     * @param  boolean $adminLogin
30
-     * @return array
31
-     */
32
-    public function login($credentials, $adminLogin = false)
33
-    {
34
-        $this->userRepository->login($credentials, $adminLogin);
35
-
36
-        return $this->proxy('password', [
37
-            'username' => $credentials['email'],
38
-            'password' => $credentials['password']
39
-        ]);
40
-    }
41
-
42
-    /**
43
-     * Attempt to refresh the access token useing the given refresh token.
44
-     * 
45
-     * @param  string $refreshToken
46
-     * @return array
47
-     */
48
-    public function refreshtoken($refreshToken)
49
-    {
50
-        return $this->proxy('refresh_token', [
51
-            'refresh_token' => $refreshToken
52
-        ]);
53
-    }
54
-
55
-    /**
56
-     * Proxy a request to the OAuth server.
57
-     *
58
-     * @param string $grantType what type of grant type should be proxied
59
-     * @param array 
60
-     */
61
-    public function proxy($grantType, array $data = [])
62
-    {
63
-        $data = array_merge($data, [
64
-            'client_id'     => config('skeleton.passport_client_id'),
65
-            'client_secret' => config('skeleton.passport_client_secret'),
66
-            'grant_type'    => $grantType
67
-        ]);
68
-
69
-        $response = $this->apiConsumer->post('/oauth/token', $data);
70
-
71
-        if ( ! $response->isSuccessful()) 
72
-        {
73
-            if ($grantType == 'refresh_token') 
74
-            {
75
-                \ErrorHandler::invalidRefreshToken();
76
-            }
77
-
78
-            \ErrorHandler::loginFailed();
79
-        }
80
-
81
-        $data = json_decode($response->getContent());
82
-
83
-        return [
84
-            'access_token'  => $data->access_token,
85
-            'refresh_token' => $data->refresh_token,
86
-            'expires_in'    => $data->expires_in
87
-        ];
88
-    }
89
-
90
-    /**
91
-     * Logs out the user. We revoke access token and refresh token.
92
-     * 
93
-     * @return void
94
-     */
95
-    public function logout()
96
-    {
97
-        \Core::users()->revokeAccessToken($this->auth->user()->token());
98
-    }
8
+	private $apiConsumer;
9
+
10
+	private $auth;
11
+
12
+	private $request;
13
+
14
+	private $userRepository;
15
+
16
+	public function __construct(Application $app) 
17
+	{
18
+
19
+		$this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository');
20
+		$this->apiConsumer    = $app->make('apiconsumer');
21
+		$this->auth           = $app->make('auth');
22
+		$this->request        = $app->make('request');
23
+	}
24
+
25
+	/**
26
+	 * Attempt to create an access token using user credentials.
27
+	 *
28
+	 * @param  array   $credentials
29
+	 * @param  boolean $adminLogin
30
+	 * @return array
31
+	 */
32
+	public function login($credentials, $adminLogin = false)
33
+	{
34
+		$this->userRepository->login($credentials, $adminLogin);
35
+
36
+		return $this->proxy('password', [
37
+			'username' => $credentials['email'],
38
+			'password' => $credentials['password']
39
+		]);
40
+	}
41
+
42
+	/**
43
+	 * Attempt to refresh the access token useing the given refresh token.
44
+	 * 
45
+	 * @param  string $refreshToken
46
+	 * @return array
47
+	 */
48
+	public function refreshtoken($refreshToken)
49
+	{
50
+		return $this->proxy('refresh_token', [
51
+			'refresh_token' => $refreshToken
52
+		]);
53
+	}
54
+
55
+	/**
56
+	 * Proxy a request to the OAuth server.
57
+	 *
58
+	 * @param string $grantType what type of grant type should be proxied
59
+	 * @param array 
60
+	 */
61
+	public function proxy($grantType, array $data = [])
62
+	{
63
+		$data = array_merge($data, [
64
+			'client_id'     => config('skeleton.passport_client_id'),
65
+			'client_secret' => config('skeleton.passport_client_secret'),
66
+			'grant_type'    => $grantType
67
+		]);
68
+
69
+		$response = $this->apiConsumer->post('/oauth/token', $data);
70
+
71
+		if ( ! $response->isSuccessful()) 
72
+		{
73
+			if ($grantType == 'refresh_token') 
74
+			{
75
+				\ErrorHandler::invalidRefreshToken();
76
+			}
77
+
78
+			\ErrorHandler::loginFailed();
79
+		}
80
+
81
+		$data = json_decode($response->getContent());
82
+
83
+		return [
84
+			'access_token'  => $data->access_token,
85
+			'refresh_token' => $data->refresh_token,
86
+			'expires_in'    => $data->expires_in
87
+		];
88
+	}
89
+
90
+	/**
91
+	 * Logs out the user. We revoke access token and refresh token.
92
+	 * 
93
+	 * @return void
94
+	 */
95
+	public function logout()
96
+	{
97
+		\Core::users()->revokeAccessToken($this->auth->user()->token());
98
+	}
99 99
 }
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/UserRepository.php 4 patches
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -102,20 +102,16 @@  discard block
 block discarded – undo
102 102
         if ( ! $user = $this->first(['email' => $credentials['email']])) 
103 103
         {
104 104
             \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
105
+        } else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107 106
         {
108 107
             \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
108
+        } else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111 109
         {
112 110
             \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
111
+        } else if ($user->blocked)
115 112
         {
116 113
             \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed)
114
+        } else if ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed)
119 115
         {
120 116
             \ErrorHandler::emailNotConfirmed();
121 117
         }
@@ -165,8 +161,7 @@  discard block
 block discarded – undo
165 161
         {
166 162
             $user->confirmed = 1;
167 163
             $user->save();
168
-        }
169
-        else if ( ! config('skeleton.disable_confirm_email'))  
164
+        } else if ( ! config('skeleton.disable_confirm_email'))  
170 165
         {
171 166
             $this->sendConfirmationEmail($user->email);
172 167
         }
@@ -189,12 +184,10 @@  discard block
 block discarded – undo
189 184
         if ( ! $this->hasGroup(['Admin']))
190 185
         {
191 186
             \ErrorHandler::noPermissions();
192
-        }
193
-        else if (\Auth::id() == $userId)
187
+        } else if (\Auth::id() == $userId)
194 188
         {
195 189
             \ErrorHandler::noPermissions();
196
-        }
197
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
190
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
198 191
         {
199 192
             \ErrorHandler::noPermissions();
200 193
         }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $user        = \Core::users()->find(\Auth::id(), $relations);
29 29
         foreach ($user->groups()->get() as $group)
30 30
         {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
31
+            $group->permissions->each(function($permission) use (&$permissions){
32 32
                 $permissions[$permission->model][$permission->id] = $permission->name;
33 33
             });
34 34
         }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52 52
         $permissions = [];
53 53
 
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
54
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
55 55
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56 56
         });
57 57
         
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function assignGroups($userId, $groupIds)
82 82
     {
83
-        \DB::transaction(function () use ($userId, $groupIds) {
83
+        \DB::transaction(function() use ($userId, $groupIds) {
84 84
             $user = $this->find($userId);
85 85
             $user->groups()->detach();
86 86
             $user->groups()->attach($groupIds);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     public function resetPassword($credentials)
252 252
     {
253
-        $response = \Password::reset($credentials, function ($user, $password) {
253
+        $response = \Password::reset($credentials, function($user, $password) {
254 254
             $user->password = $password;
255 255
             $user->save();
256 256
         });
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     /**
62 62
      * Check if the logged in user has the given group.
63 63
      * 
64
-     * @param  array $groups
64
+     * @param  string[] $groups
65 65
      * @param  mixed $user
66 66
      * @return boolean
67 67
      */
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * 
156 156
      * @param  array   $credentials
157 157
      * @param  boolean $skipConfirmEmail
158
-     * @return array
158
+     * @return boolean
159 159
      */
160 160
     public function register($credentials, $skipConfirmEmail = false)
161 161
     {
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      * Reset the given user's password.
247 247
      *
248 248
      * @param  array  $credentials
249
-     * @return array
249
+     * @return string|null
250 250
      */
251 251
     public function resetPassword($credentials)
252 252
     {
Please login to merge, or discard this patch.
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -5,414 +5,414 @@
 block discarded – undo
5 5
 
6 6
 class UserRepository extends AbstractRepository
7 7
 {
8
-    /**
9
-     * Return the model full namespace.
10
-     * 
11
-     * @return string
12
-     */
13
-    protected function getModel()
14
-    {
15
-        return 'App\Modules\Acl\AclUser';
16
-    }
17
-
18
-
19
-    /**
20
-     * Return the logged in user account.
21
-     *
22
-     * @param  array   $relations
23
-     * @return boolean
24
-     */
25
-    public function account($relations = [])
26
-    {
27
-        $permissions = [];
28
-        $user        = \Core::users()->find(\Auth::id(), $relations);
29
-        foreach ($user->groups()->get() as $group)
30
-        {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
32
-                $permissions[$permission->model][$permission->id] = $permission->name;
33
-            });
34
-        }
35
-        $user->permissions = $permissions;
36
-
37
-       return $user;
38
-    }
39
-
40
-    /**
41
-     * Check if the logged in user or the given user 
42
-     * has the given permissions on the given model.
43
-     * 
44
-     * @param  string $nameOfPermission
45
-     * @param  string $model            
46
-     * @param  mixed  $user
47
-     * @return boolean
48
-     */
49
-    public function can($nameOfPermission, $model, $user = false)
50
-    {      
51
-        $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
-        $permissions = [];
53
-
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
-        });
8
+	/**
9
+	 * Return the model full namespace.
10
+	 * 
11
+	 * @return string
12
+	 */
13
+	protected function getModel()
14
+	{
15
+		return 'App\Modules\Acl\AclUser';
16
+	}
17
+
18
+
19
+	/**
20
+	 * Return the logged in user account.
21
+	 *
22
+	 * @param  array   $relations
23
+	 * @return boolean
24
+	 */
25
+	public function account($relations = [])
26
+	{
27
+		$permissions = [];
28
+		$user        = \Core::users()->find(\Auth::id(), $relations);
29
+		foreach ($user->groups()->get() as $group)
30
+		{
31
+			$group->permissions->each(function ($permission) use (&$permissions){
32
+				$permissions[$permission->model][$permission->id] = $permission->name;
33
+			});
34
+		}
35
+		$user->permissions = $permissions;
36
+
37
+	   return $user;
38
+	}
39
+
40
+	/**
41
+	 * Check if the logged in user or the given user 
42
+	 * has the given permissions on the given model.
43
+	 * 
44
+	 * @param  string $nameOfPermission
45
+	 * @param  string $model            
46
+	 * @param  mixed  $user
47
+	 * @return boolean
48
+	 */
49
+	public function can($nameOfPermission, $model, $user = false)
50
+	{      
51
+		$user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
+		$permissions = [];
53
+
54
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
+		});
57 57
         
58
-        return in_array($nameOfPermission, $permissions);
59
-    }
60
-
61
-    /**
62
-     * Check if the logged in user has the given group.
63
-     * 
64
-     * @param  array $groups
65
-     * @param  mixed $user
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groups, $user = false)
69
-    {
70
-        $user = $user ?: $this->find(\Auth::id());
71
-        return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
-    }
73
-
74
-    /**
75
-     * Assign the given group ids to the given user.
76
-     * 
77
-     * @param  integer $userId    
78
-     * @param  array   $groupIds
79
-     * @return object
80
-     */
81
-    public function assignGroups($userId, $groupIds)
82
-    {
83
-        \DB::transaction(function () use ($userId, $groupIds) {
84
-            $user = $this->find($userId);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($groupIds);
87
-        });
88
-
89
-        return $this->find($userId);
90
-    }
91
-
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     * 
96
-     * @param  array   $credentials    
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
-        {
104
-            \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
-        {
108
-            \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
-        {
112
-            \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
115
-        {
116
-            \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed)
119
-        {
120
-            \ErrorHandler::emailNotConfirmed();
121
-        }
122
-
123
-        return $user;
124
-    }
125
-
126
-    /**
127
-     * Handle a social login request of the none admin to the application.
128
-     * 
129
-     * @param  string $authCode
130
-     * @param  string $accessToken
131
-     * @param  string $type
132
-     * @return array
133
-     */
134
-    public function loginSocial($authCode, $accessToken, $type)
135
-    {
136
-        $access_token = $authCode ? array_get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
137
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
138
-
139
-        if ( ! $user->email)
140
-        {
141
-            \ErrorHandler::noSocialEmail();
142
-        }
143
-
144
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
145
-        {
146
-            $this->register(['email' => $user->email, 'password' => ''], true);
147
-        }
148
-
149
-        $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
150
-        return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
151
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  array $groups
65
+	 * @param  mixed $user
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groups, $user = false)
69
+	{
70
+		$user = $user ?: $this->find(\Auth::id());
71
+		return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
+	}
73
+
74
+	/**
75
+	 * Assign the given group ids to the given user.
76
+	 * 
77
+	 * @param  integer $userId    
78
+	 * @param  array   $groupIds
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($userId, $groupIds)
82
+	{
83
+		\DB::transaction(function () use ($userId, $groupIds) {
84
+			$user = $this->find($userId);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($groupIds);
87
+		});
88
+
89
+		return $this->find($userId);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 * 
96
+	 * @param  array   $credentials    
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
+		{
104
+			\ErrorHandler::loginFailed();
105
+		}
106
+		else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
+		{
108
+			\ErrorHandler::loginFailed();
109
+		}
110
+		else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
+		{
112
+			\ErrorHandler::loginFailed();
113
+		}
114
+		else if ($user->blocked)
115
+		{
116
+			\ErrorHandler::userIsBlocked();
117
+		}
118
+		else if ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed)
119
+		{
120
+			\ErrorHandler::emailNotConfirmed();
121
+		}
122
+
123
+		return $user;
124
+	}
125
+
126
+	/**
127
+	 * Handle a social login request of the none admin to the application.
128
+	 * 
129
+	 * @param  string $authCode
130
+	 * @param  string $accessToken
131
+	 * @param  string $type
132
+	 * @return array
133
+	 */
134
+	public function loginSocial($authCode, $accessToken, $type)
135
+	{
136
+		$access_token = $authCode ? array_get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
137
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
138
+
139
+		if ( ! $user->email)
140
+		{
141
+			\ErrorHandler::noSocialEmail();
142
+		}
143
+
144
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
145
+		{
146
+			$this->register(['email' => $user->email, 'password' => ''], true);
147
+		}
148
+
149
+		$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
150
+		return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
151
+	}
152 152
     
153
-    /**
154
-     * Handle a registration request.
155
-     * 
156
-     * @param  array   $credentials
157
-     * @param  boolean $skipConfirmEmail
158
-     * @return array
159
-     */
160
-    public function register($credentials, $skipConfirmEmail = false)
161
-    {
162
-        $user = $this->save($credentials);
163
-
164
-        if ($skipConfirmEmail) 
165
-        {
166
-            $user->confirmed = 1;
167
-            $user->save();
168
-        }
169
-        else if ( ! config('skeleton.disable_confirm_email'))  
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-
174
-        return $user;
175
-    }
153
+	/**
154
+	 * Handle a registration request.
155
+	 * 
156
+	 * @param  array   $credentials
157
+	 * @param  boolean $skipConfirmEmail
158
+	 * @return array
159
+	 */
160
+	public function register($credentials, $skipConfirmEmail = false)
161
+	{
162
+		$user = $this->save($credentials);
163
+
164
+		if ($skipConfirmEmail) 
165
+		{
166
+			$user->confirmed = 1;
167
+			$user->save();
168
+		}
169
+		else if ( ! config('skeleton.disable_confirm_email'))  
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+
174
+		return $user;
175
+	}
176 176
     
177
-    /**
178
-     * Block the user.
179
-     *
180
-     * @param  integer $userId
181
-     * @return object
182
-     */
183
-    public function block($userId)
184
-    {
185
-        if ( ! $user = $this->find($userId)) 
186
-        {
187
-            \ErrorHandler::notFound('user');
188
-        }
189
-        if ( ! $this->hasGroup(['Admin']))
190
-        {
191
-            \ErrorHandler::noPermissions();
192
-        }
193
-        else if (\Auth::id() == $userId)
194
-        {
195
-            \ErrorHandler::noPermissions();
196
-        }
197
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
198
-        {
199
-            \ErrorHandler::noPermissions();
200
-        }
201
-
202
-        $user->blocked = 1;
203
-        $user->save();
177
+	/**
178
+	 * Block the user.
179
+	 *
180
+	 * @param  integer $userId
181
+	 * @return object
182
+	 */
183
+	public function block($userId)
184
+	{
185
+		if ( ! $user = $this->find($userId)) 
186
+		{
187
+			\ErrorHandler::notFound('user');
188
+		}
189
+		if ( ! $this->hasGroup(['Admin']))
190
+		{
191
+			\ErrorHandler::noPermissions();
192
+		}
193
+		else if (\Auth::id() == $userId)
194
+		{
195
+			\ErrorHandler::noPermissions();
196
+		}
197
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
198
+		{
199
+			\ErrorHandler::noPermissions();
200
+		}
201
+
202
+		$user->blocked = 1;
203
+		$user->save();
204 204
         
205
-        return $user;
206
-    }
207
-
208
-    /**
209
-     * Unblock the user.
210
-     *
211
-     * @param  integer $userId
212
-     * @return object
213
-     */
214
-    public function unblock($userId)
215
-    {
216
-        if ( ! $this->hasGroup(['Admin']))
217
-        {
218
-            \ErrorHandler::noPermissions();
219
-        }
220
-
221
-        $user          = $this->find($userId);
222
-        $user->blocked = 0;
223
-        $user->save();
224
-
225
-        return $user;
226
-    }
227
-
228
-    /**
229
-     * Send a reset link to the given user.
230
-     *
231
-     * @param  string  $email
232
-     * @return void
233
-     */
234
-    public function sendReset($email)
235
-    {
236
-        if ( ! $user = $this->model->where('email', $email)->first())
237
-        {
238
-            \ErrorHandler::notFound('email');
239
-        }
240
-
241
-        $token = \Password::getRepository()->create($user);
242
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
243
-    }
244
-
245
-    /**
246
-     * Reset the given user's password.
247
-     *
248
-     * @param  array  $credentials
249
-     * @return array
250
-     */
251
-    public function resetPassword($credentials)
252
-    {
253
-        $response = \Password::reset($credentials, function ($user, $password) {
254
-            $user->password = $password;
255
-            $user->save();
256
-        });
257
-
258
-        switch ($response) {
259
-            case \Password::PASSWORD_RESET:
260
-                return 'success';
205
+		return $user;
206
+	}
207
+
208
+	/**
209
+	 * Unblock the user.
210
+	 *
211
+	 * @param  integer $userId
212
+	 * @return object
213
+	 */
214
+	public function unblock($userId)
215
+	{
216
+		if ( ! $this->hasGroup(['Admin']))
217
+		{
218
+			\ErrorHandler::noPermissions();
219
+		}
220
+
221
+		$user          = $this->find($userId);
222
+		$user->blocked = 0;
223
+		$user->save();
224
+
225
+		return $user;
226
+	}
227
+
228
+	/**
229
+	 * Send a reset link to the given user.
230
+	 *
231
+	 * @param  string  $email
232
+	 * @return void
233
+	 */
234
+	public function sendReset($email)
235
+	{
236
+		if ( ! $user = $this->model->where('email', $email)->first())
237
+		{
238
+			\ErrorHandler::notFound('email');
239
+		}
240
+
241
+		$token = \Password::getRepository()->create($user);
242
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
243
+	}
244
+
245
+	/**
246
+	 * Reset the given user's password.
247
+	 *
248
+	 * @param  array  $credentials
249
+	 * @return array
250
+	 */
251
+	public function resetPassword($credentials)
252
+	{
253
+		$response = \Password::reset($credentials, function ($user, $password) {
254
+			$user->password = $password;
255
+			$user->save();
256
+		});
257
+
258
+		switch ($response) {
259
+			case \Password::PASSWORD_RESET:
260
+				return 'success';
261 261
                 
262
-            case \Password::INVALID_TOKEN:
263
-                \ErrorHandler::invalidResetToken('token');
264
-
265
-            case \Password::INVALID_PASSWORD:
266
-                \ErrorHandler::invalidResetPassword('email');
267
-
268
-            case \Password::INVALID_USER:
269
-                \ErrorHandler::notFound('user');
270
-
271
-            default:
272
-                \ErrorHandler::generalError();
273
-        }
274
-    }
275
-
276
-    /**
277
-     * Change the logged in user password.
278
-     *
279
-     * @param  array  $credentials
280
-     * @return void
281
-     */
282
-    public function changePassword($credentials)
283
-    {
284
-        $user = \Auth::user();
285
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
286
-        {
287
-            \ErrorHandler::invalidOldPassword();
288
-        }
289
-
290
-        $user->password = $credentials['password'];
291
-        $user->save();
292
-    }
293
-
294
-    /**
295
-     * Confirm email using the confirmation code.
296
-     *
297
-     * @param  string $confirmationCode
298
-     * @return void
299
-     */
300
-    public function confirmEmail($confirmationCode)
301
-    {
302
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
303
-        $user->confirmed         = 1;
304
-        $user->confirmation_code = null;
305
-        $user->save();
306
-    }
307
-
308
-    /**
309
-     * Send the confirmation mail.
310
-     *
311
-     * @param  string $email
312
-     * @return void
313
-     */
314
-    public function sendConfirmationEmail($email)
315
-    {
316
-        $user = $this->first(['email' => $email]);
317
-        if ($user->confirmed) 
318
-        {
319
-            \ErrorHandler::emailAlreadyConfirmed();
320
-        }
321
-
322
-        $user->confirmed         = 0;
323
-        $user->confirmation_code = sha1(microtime());
324
-        $user->save();
325
-        \Core::notifications()->notify($user, 'ConfirmEmail');
326
-    }
327
-
328
-    /**
329
-     * Paginate all users in the given group based on the given conditions.
330
-     * 
331
-     * @param  string  $groupName
332
-     * @param  array   $relations
333
-     * @param  integer $perPage
334
-     * @param  string  $sortBy
335
-     * @param  boolean $desc
336
-     * @return \Illuminate\Http\Response
337
-     */
338
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
339
-    {   
340
-        unset($conditions['page']);
341
-        $conditions = $this->constructConditions($conditions, $this->model);
342
-        $sort       = $desc ? 'desc' : 'asc';
343
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
344
-
345
-        $model->whereHas('groups', function($q) use ($groupName){
346
-            $q->where('name', $groupName);
347
-        });
262
+			case \Password::INVALID_TOKEN:
263
+				\ErrorHandler::invalidResetToken('token');
264
+
265
+			case \Password::INVALID_PASSWORD:
266
+				\ErrorHandler::invalidResetPassword('email');
267
+
268
+			case \Password::INVALID_USER:
269
+				\ErrorHandler::notFound('user');
270
+
271
+			default:
272
+				\ErrorHandler::generalError();
273
+		}
274
+	}
275
+
276
+	/**
277
+	 * Change the logged in user password.
278
+	 *
279
+	 * @param  array  $credentials
280
+	 * @return void
281
+	 */
282
+	public function changePassword($credentials)
283
+	{
284
+		$user = \Auth::user();
285
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
286
+		{
287
+			\ErrorHandler::invalidOldPassword();
288
+		}
289
+
290
+		$user->password = $credentials['password'];
291
+		$user->save();
292
+	}
293
+
294
+	/**
295
+	 * Confirm email using the confirmation code.
296
+	 *
297
+	 * @param  string $confirmationCode
298
+	 * @return void
299
+	 */
300
+	public function confirmEmail($confirmationCode)
301
+	{
302
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
303
+		$user->confirmed         = 1;
304
+		$user->confirmation_code = null;
305
+		$user->save();
306
+	}
307
+
308
+	/**
309
+	 * Send the confirmation mail.
310
+	 *
311
+	 * @param  string $email
312
+	 * @return void
313
+	 */
314
+	public function sendConfirmationEmail($email)
315
+	{
316
+		$user = $this->first(['email' => $email]);
317
+		if ($user->confirmed) 
318
+		{
319
+			\ErrorHandler::emailAlreadyConfirmed();
320
+		}
321
+
322
+		$user->confirmed         = 0;
323
+		$user->confirmation_code = sha1(microtime());
324
+		$user->save();
325
+		\Core::notifications()->notify($user, 'ConfirmEmail');
326
+	}
327
+
328
+	/**
329
+	 * Paginate all users in the given group based on the given conditions.
330
+	 * 
331
+	 * @param  string  $groupName
332
+	 * @param  array   $relations
333
+	 * @param  integer $perPage
334
+	 * @param  string  $sortBy
335
+	 * @param  boolean $desc
336
+	 * @return \Illuminate\Http\Response
337
+	 */
338
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
339
+	{   
340
+		unset($conditions['page']);
341
+		$conditions = $this->constructConditions($conditions, $this->model);
342
+		$sort       = $desc ? 'desc' : 'asc';
343
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
344
+
345
+		$model->whereHas('groups', function($q) use ($groupName){
346
+			$q->where('name', $groupName);
347
+		});
348 348
 
349 349
         
350
-        if (count($conditions['conditionValues']))
351
-        {
352
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
353
-        }
354
-
355
-        if ($perPage) 
356
-        {
357
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
358
-        }
359
-
360
-        return $model->orderBy($sortBy, $sort)->get();
361
-    }
362
-
363
-    /**
364
-     * Save the given data to the logged in user.
365
-     *
366
-     * @param  array $data
367
-     * @return void
368
-     */
369
-    public function saveProfile($data) 
370
-    {
371
-        if (array_key_exists('profile_picture', $data)) 
372
-        {
373
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
374
-        }
350
+		if (count($conditions['conditionValues']))
351
+		{
352
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
353
+		}
354
+
355
+		if ($perPage) 
356
+		{
357
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
358
+		}
359
+
360
+		return $model->orderBy($sortBy, $sort)->get();
361
+	}
362
+
363
+	/**
364
+	 * Save the given data to the logged in user.
365
+	 *
366
+	 * @param  array $data
367
+	 * @return void
368
+	 */
369
+	public function saveProfile($data) 
370
+	{
371
+		if (array_key_exists('profile_picture', $data)) 
372
+		{
373
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
374
+		}
375 375
         
376
-        $data['id'] = \Auth::id();
377
-        $this->save($data);
378
-    }
379
-
380
-    /**
381
-     * Ensure access token hasn't expired or revoked.
382
-     * 
383
-     * @param  oject $accessToken
384
-     * @return boolean
385
-     */
386
-    public function accessTokenExpiredOrRevoked($accessToken)
387
-    {
388
-
389
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
390
-        $data                  = new ValidationData();
391
-        $data->setCurrentTime(time());
392
-
393
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
394
-        {
395
-            return true;
396
-        }
397
-
398
-        return false;
399
-    }
400
-
401
-    /**
402
-     * Revoke the given access token and all 
403
-     * associated refresh tokens.
404
-     *
405
-     * @param  oject $accessToken
406
-     * @return void
407
-     */
408
-    public function revokeAccessToken($accessToken)
409
-    {
410
-        \DB::table('oauth_refresh_tokens')
411
-            ->where('access_token_id', $accessToken->id)
412
-            ->update([
413
-                'revoked' => true
414
-            ]);
415
-
416
-        $accessToken->revoke();
417
-    }
376
+		$data['id'] = \Auth::id();
377
+		$this->save($data);
378
+	}
379
+
380
+	/**
381
+	 * Ensure access token hasn't expired or revoked.
382
+	 * 
383
+	 * @param  oject $accessToken
384
+	 * @return boolean
385
+	 */
386
+	public function accessTokenExpiredOrRevoked($accessToken)
387
+	{
388
+
389
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
390
+		$data                  = new ValidationData();
391
+		$data->setCurrentTime(time());
392
+
393
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
394
+		{
395
+			return true;
396
+		}
397
+
398
+		return false;
399
+	}
400
+
401
+	/**
402
+	 * Revoke the given access token and all 
403
+	 * associated refresh tokens.
404
+	 *
405
+	 * @param  oject $accessToken
406
+	 * @return void
407
+	 */
408
+	public function revokeAccessToken($accessToken)
409
+	{
410
+		\DB::table('oauth_refresh_tokens')
411
+			->where('access_token_id', $accessToken->id)
412
+			->update([
413
+				'revoked' => true
414
+			]);
415
+
416
+		$accessToken->revoke();
417
+	}
418 418
 }
Please login to merge, or discard this patch.
config/skeleton.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Disable Confirm Email
8 8
     |--------------------------------------------------------------------------
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
     |
12 12
     */
13 13
 
14
-    'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false),
14
+	'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false),
15 15
 
16
-    /*
16
+	/*
17 17
     |--------------------------------------------------------------------------
18 18
     | Confirm Email URL
19 19
     |--------------------------------------------------------------------------
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
     |
23 23
     */
24 24
    
25
-    'confrim_email_url' => env('CONFIRM_EMAIL_URL'),
25
+	'confrim_email_url' => env('CONFIRM_EMAIL_URL'),
26 26
 
27
-    /*
27
+	/*
28 28
     |--------------------------------------------------------------------------
29 29
     | Reset Password URL
30 30
     |--------------------------------------------------------------------------
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
     |
34 34
     */
35 35
    
36
-    'reset_password_url' => env('RESET_PASSWORD_URL'),
36
+	'reset_password_url' => env('RESET_PASSWORD_URL'),
37 37
 
38
-    /*
38
+	/*
39 39
     |--------------------------------------------------------------------------
40 40
     | Passport Client Id
41 41
     |--------------------------------------------------------------------------
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
     |
45 45
     */
46 46
    
47
-    'passport_client_id' => env('PASSWORD_CLIENT_ID'),
47
+	'passport_client_id' => env('PASSWORD_CLIENT_ID'),
48 48
 
49
-    /*
49
+	/*
50 50
     |--------------------------------------------------------------------------
51 51
     | Passport Client Secret
52 52
     |--------------------------------------------------------------------------
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
     |
56 56
     */
57 57
    
58
-    'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'),
58
+	'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'),
59 59
 
60
-    /*
60
+	/*
61 61
     |--------------------------------------------------------------------------
62 62
     | Social Pass
63 63
     |--------------------------------------------------------------------------
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
     |
67 67
     */
68 68
 
69
-    'social_pass' => env('SOCIAL_PASS', false),
69
+	'social_pass' => env('SOCIAL_PASS', false),
70 70
 
71
-    /*
71
+	/*
72 72
     |--------------------------------------------------------------------------
73 73
     | Relations Between Models
74 74
     |--------------------------------------------------------------------------
@@ -77,88 +77,88 @@  discard block
 block discarded – undo
77 77
     |
78 78
     */
79 79
     
80
-    'relations' => [
81
-        'users' => [
82
-            'list'       => [],
83
-            'find'       => [],
84
-            'findby'     => [],
85
-            'paginate'   => [],
86
-            'paginateby' => [],
87
-            'first'      => [],
88
-            'search'     => [],
89
-            'account'    => [],
90
-            'group'      => [],
91
-            'deleted'    => [],
92
-        ],
93
-        'permissions' => [
94
-            'list'       => [],
95
-            'find'       => [],
96
-            'findby'     => [],
97
-            'paginate'   => [],
98
-            'paginateby' => [],
99
-            'first'      => [],
100
-            'search'     => [],
101
-            'deleted'    => [],
102
-        ],
103
-        'groups' => [
104
-            'list'       => [],
105
-            'find'       => [],
106
-            'findby'     => [],
107
-            'paginate'   => [],
108
-            'paginateby' => [],
109
-            'first'      => [],
110
-            'search'     => [],
111
-            'deleted'    => [],
112
-        ],
113
-        'oauthClients' => [
114
-            'list'       => [],
115
-            'find'       => [],
116
-            'findby'     => [],
117
-            'paginate'   => [],
118
-            'paginateby' => [],
119
-            'first'      => [],
120
-            'search'     => [],
121
-            'account'    => [],
122
-            'group'      => [],
123
-            'deleted'    => [],
124
-        ],
125
-        'notifications' => [
126
-            'list'   => [],
127
-            'unread' => [],
128
-        ],
129
-        'pushNotificationDevices' => [
130
-            'list'       => [],
131
-            'find'       => [],
132
-            'findby'     => [],
133
-            'paginate'   => [],
134
-            'paginateby' => [],
135
-            'first'      => [],
136
-            'search'     => [],
137
-            'deleted'    => [],
138
-        ],
139
-        'reports' => [
140
-            'list'       => [],
141
-            'find'       => [],
142
-            'findby'     => [],
143
-            'paginate'   => [],
144
-            'paginateby' => [],
145
-            'first'      => [],
146
-            'search'     => [],
147
-            'deleted'    => [],
148
-        ],
149
-        'settings' => [
150
-            'list'       => [],
151
-            'find'       => [],
152
-            'findby'     => [],
153
-            'paginate'   => [],
154
-            'paginateby' => [],
155
-            'first'      => [],
156
-            'search'     => [],
157
-            'deleted'    => [],
158
-        ]
159
-    ],
80
+	'relations' => [
81
+		'users' => [
82
+			'list'       => [],
83
+			'find'       => [],
84
+			'findby'     => [],
85
+			'paginate'   => [],
86
+			'paginateby' => [],
87
+			'first'      => [],
88
+			'search'     => [],
89
+			'account'    => [],
90
+			'group'      => [],
91
+			'deleted'    => [],
92
+		],
93
+		'permissions' => [
94
+			'list'       => [],
95
+			'find'       => [],
96
+			'findby'     => [],
97
+			'paginate'   => [],
98
+			'paginateby' => [],
99
+			'first'      => [],
100
+			'search'     => [],
101
+			'deleted'    => [],
102
+		],
103
+		'groups' => [
104
+			'list'       => [],
105
+			'find'       => [],
106
+			'findby'     => [],
107
+			'paginate'   => [],
108
+			'paginateby' => [],
109
+			'first'      => [],
110
+			'search'     => [],
111
+			'deleted'    => [],
112
+		],
113
+		'oauthClients' => [
114
+			'list'       => [],
115
+			'find'       => [],
116
+			'findby'     => [],
117
+			'paginate'   => [],
118
+			'paginateby' => [],
119
+			'first'      => [],
120
+			'search'     => [],
121
+			'account'    => [],
122
+			'group'      => [],
123
+			'deleted'    => [],
124
+		],
125
+		'notifications' => [
126
+			'list'   => [],
127
+			'unread' => [],
128
+		],
129
+		'pushNotificationDevices' => [
130
+			'list'       => [],
131
+			'find'       => [],
132
+			'findby'     => [],
133
+			'paginate'   => [],
134
+			'paginateby' => [],
135
+			'first'      => [],
136
+			'search'     => [],
137
+			'deleted'    => [],
138
+		],
139
+		'reports' => [
140
+			'list'       => [],
141
+			'find'       => [],
142
+			'findby'     => [],
143
+			'paginate'   => [],
144
+			'paginateby' => [],
145
+			'first'      => [],
146
+			'search'     => [],
147
+			'deleted'    => [],
148
+		],
149
+		'settings' => [
150
+			'list'       => [],
151
+			'find'       => [],
152
+			'findby'     => [],
153
+			'paginate'   => [],
154
+			'paginateby' => [],
155
+			'first'      => [],
156
+			'search'     => [],
157
+			'deleted'    => [],
158
+		]
159
+	],
160 160
 
161
-    /*
161
+	/*
162 162
     |--------------------------------------------------------------------------
163 163
     | Cache Configurations
164 164
     |--------------------------------------------------------------------------
@@ -167,46 +167,46 @@  discard block
 block discarded – undo
167 167
     |
168 168
     */
169 169
 
170
-    'cache_config' => [
171
-        'oauthClients' => [
172
-            'cache' => [
173
-                'all',
174
-                'find',
175
-                'findBy',
176
-                'paginate',
177
-                'paginateBy',
178
-                'first',
179
-                'search',
180
-                'deleted'
181
-            ],
182
-            'clear' => [
183
-                'update'           => ['oauthClients', 'users', 'groups'],
184
-                'save'             => ['oauthClients', 'users', 'groups'],
185
-                'delete'           => ['oauthClients', 'users', 'groups'],
186
-                'restore'          => ['oauthClients', 'users', 'groups'],
187
-                'revoke'           => ['oauthClients', 'users', 'groups'],
188
-                'ubRevoke'         => ['oauthClients', 'users', 'groups'],
189
-                'regenerateSecret' => ['oauthClients', 'users', 'groups'],
190
-            ],
191
-        ],
192
-        'settings' => [
193
-            'cache' => [
194
-                'all',
195
-                'find',
196
-                'findBy',
197
-                'paginate',
198
-                'paginateBy',
199
-                'first',
200
-                'search',
201
-                'deleted'
202
-            ],
203
-            'clear' => [
204
-                'update'   => ['settings'],
205
-                'save'     => ['settings'],
206
-                'delete'   => ['settings'],
207
-                'restore'  => ['settings'],
208
-                'saveMany' => ['settings'],
209
-            ]
210
-        ]
211
-    ]
170
+	'cache_config' => [
171
+		'oauthClients' => [
172
+			'cache' => [
173
+				'all',
174
+				'find',
175
+				'findBy',
176
+				'paginate',
177
+				'paginateBy',
178
+				'first',
179
+				'search',
180
+				'deleted'
181
+			],
182
+			'clear' => [
183
+				'update'           => ['oauthClients', 'users', 'groups'],
184
+				'save'             => ['oauthClients', 'users', 'groups'],
185
+				'delete'           => ['oauthClients', 'users', 'groups'],
186
+				'restore'          => ['oauthClients', 'users', 'groups'],
187
+				'revoke'           => ['oauthClients', 'users', 'groups'],
188
+				'ubRevoke'         => ['oauthClients', 'users', 'groups'],
189
+				'regenerateSecret' => ['oauthClients', 'users', 'groups'],
190
+			],
191
+		],
192
+		'settings' => [
193
+			'cache' => [
194
+				'all',
195
+				'find',
196
+				'findBy',
197
+				'paginate',
198
+				'paginateBy',
199
+				'first',
200
+				'search',
201
+				'deleted'
202
+			],
203
+			'clear' => [
204
+				'update'   => ['settings'],
205
+				'save'     => ['settings'],
206
+				'delete'   => ['settings'],
207
+				'restore'  => ['settings'],
208
+				'saveMany' => ['settings'],
209
+			]
210
+		]
211
+	]
212 212
 ];
Please login to merge, or discard this patch.
src/Modules/Acl/Http/Controllers/UsersController.php 2 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -8,282 +8,282 @@
 block discarded – undo
8 8
 
9 9
 class UsersController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'users';
17
-
18
-    /**
19
-     * List of all route actions that the base api controller
20
-     * will skip permissions check for them.
21
-     * @var array
22
-     */
23
-    protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account'];
24
-
25
-    /**
26
-     * List of all route actions that the base api controller
27
-     * will skip login check for them.
28
-     * @var array
29
-     */
30
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation'];
31
-
32
-    /**
33
-     * The validations rules used by the base api controller
34
-     * to check before add.
35
-     * @var array
36
-     */
37
-    protected $validationRules     = [
38
-        'name'     => 'nullable|string', 
39
-        'email'    => 'required|email|unique:users,email,{id}', 
40
-        'password' => 'nullable|min:6'
41
-    ];
42
-
43
-    /**
44
-     * The loginProxy implementation.
45
-     * 
46
-     * @var \App\Modules\Acl\Proxy\LoginProxy
47
-     */
48
-    protected $loginProxy;
49
-
50
-    public function __construct(LoginProxy $loginProxy)
51
-    {        
52
-        $this->loginProxy = $loginProxy;
53
-        parent::__construct();
54
-    }
55
-
56
-    /**
57
-     * Return the logged in user account.
58
-     * 
59
-     * @return \Illuminate\Http\Response
60
-     */
61
-    public function account()
62
-    {
63
-        return \Response::json($this->repo->account($this->relations), 200);
64
-    }
65
-
66
-    /**
67
-     * Block the user.
68
-     *
69
-     * @param  integer  $id Id of the user.
70
-     * @return \Illuminate\Http\Response
71
-     */
72
-    public function block($id)
73
-    {
74
-        return \Response::json($this->repo->block($id), 200);
75
-    }
76
-
77
-    /**
78
-     * Unblock the user.
79
-     *
80
-     * @param  integer  $id Id of the user.
81
-     * @return \Illuminate\Http\Response
82
-     */
83
-    public function unblock($id)
84
-    {
85
-        return \Response::json($this->repo->unblock($id), 200);
86
-    }
87
-
88
-    /**
89
-     * Logout the user.
90
-     * 
91
-     * @return \Illuminate\Http\Response
92
-     */
93
-    public function logout()
94
-    {
95
-        return \Response::json($this->loginProxy->logout(), 200);
96
-    }
97
-
98
-    /**
99
-     * Handle a registration request.
100
-     *
101
-     * @param  \Illuminate\Http\Request  $request
102
-     * @return \Illuminate\Http\Response
103
-     */
104
-    public function register(Request $request)
105
-    {
106
-        $this->validate($request, [
107
-            'name'     => 'nullable|string', 
108
-            'email'    => 'required|email|unique:users,email,{id}', 
109
-            'password' => 'required|min:6'
110
-            ]);
111
-
112
-        return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200);
113
-    }
114
-
115
-    /**
116
-     * Handle a login request to the application.
117
-     *
118
-     * @param  \Illuminate\Http\Request  $request
119
-     * @return \Illuminate\Http\Response
120
-     */
121
-    public function login(Request $request)
122
-    {
123
-        $this->validate($request, [
124
-            'email'    => 'required|email', 
125
-            'password' => 'required|min:6', 
126
-            'admin'    => 'nullable|boolean'
127
-            ]);
128
-
129
-        return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200);
130
-    }
131
-
132
-    /**
133
-     * Handle a social login request of the none admin to the application.
134
-     *
135
-     * @param  \Illuminate\Http\Request  $request
136
-     * @return \Illuminate\Http\Response
137
-     */
138
-    public function loginSocial(Request $request)
139
-    {
140
-        $this->validate($request, [
141
-            'auth_code'    => 'required_without:access_token',
142
-            'access_token' => 'required_without:auth_code',
143
-            'type'         => 'required|in:facebook,google'
144
-            ]);
145
-
146
-        return \Response::json($this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')), 200);
147
-    }
148
-
149
-    /**
150
-     * Assign the given groups to the given user.
151
-     *
152
-     * @param  \Illuminate\Http\Request  $request
153
-     * @return \Illuminate\Http\Response
154
-     */
155
-    public function assigngroups(Request $request)
156
-    {
157
-        $this->validate($request, [
158
-            'group_ids' => 'required|exists:groups,id', 
159
-            'user_id'   => 'required|exists:users,id'
160
-            ]);
161
-
162
-        return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
163
-    }
164
-
165
-    /**
166
-     * Send a reset link to the given user.
167
-     *
168
-     * @param  \Illuminate\Http\Request  $request
169
-     * @return \Illuminate\Http\Response
170
-     */
171
-    public function sendreset(Request $request)
172
-    {
173
-        $this->validate($request, ['email' => 'required|email']);
174
-
175
-        return \Response::json($this->repo->sendReset($request->get('email')), 200);
176
-    }
177
-
178
-    /**
179
-     * Reset the given user's password.
180
-     *
181
-     * @param  \Illuminate\Http\Request  $request
182
-     * @return \Illuminate\Http\Response
183
-     */
184
-    public function resetpassword(Request $request)
185
-    {
186
-        $this->validate($request, [
187
-            'token'                 => 'required',
188
-            'email'                 => 'required|email',
189
-            'password'              => 'required|confirmed|min:6',
190
-            'password_confirmation' => 'required',
191
-        ]);
192
-
193
-        return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
194
-    }
195
-
196
-    /**
197
-     * Change the logged in user password.
198
-     *
199
-     * @param  \Illuminate\Http\Request  $request
200
-     * @return \Illuminate\Http\Response
201
-     */
202
-    public function changePassword(Request $request)
203
-    {
204
-        $this->validate($request, [
205
-            'old_password'          => 'required',
206
-            'password'              => 'required|confirmed|min:6',
207
-            'password_confirmation' => 'required',
208
-        ]);
209
-
210
-        return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
211
-    }
212
-
213
-    /**
214
-     * Confirm email using the confirmation code.
215
-     *
216
-     * @param  \Illuminate\Http\Request  $request
217
-     * @return \Illuminate\Http\Response
218
-     */
219
-    public function confirmEmail(Request $request)
220
-    {
221
-        $this->validate($request, [
222
-            'confirmation_code' => 'required|string|exists:users,confirmation_code'
223
-        ]);
224
-
225
-        return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200);
226
-    }
227
-
228
-    /**
229
-     * Resend the email confirmation mail.
230
-     *
231
-     * @param  \Illuminate\Http\Request  $request
232
-     * @return \Illuminate\Http\Response
233
-     */
234
-    public function resendEmailConfirmation(Request $request)
235
-    {
236
-        $this->validate($request, [
237
-            'email' => 'required|exists:users,email'
238
-        ]);
239
-
240
-        return \Response::json($this->repo->sendConfirmationEmail($request->get('email')), 200);
241
-    }
242
-
243
-    /**
244
-     * Refresh the expired login token.
245
-     *
246
-     * @param  \Illuminate\Http\Request  $request
247
-     * @return \Illuminate\Http\Response
248
-     */
249
-    public function refreshtoken(Request $request)
250
-    {
251
-        $this->validate($request, [
252
-            'refreshtoken' => 'required',
253
-        ]);
254
-
255
-        return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200);
256
-    }
257
-
258
-    /**
259
-     * Paginate all users with in the given group.
260
-     * 
261
-     * @param  \Illuminate\Http\Request  $request
262
-     * @param  string $groupName The name of the requested group.
263
-     * @param  integer $perPage  Number of rows per page default 15.
264
-     * @param  string  $sortBy   The name of the column to sort by.
265
-     * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
266
-     * @return \Illuminate\Http\Response
267
-     */
268
-    public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
269
-    {
270
-        return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
271
-    }
272
-
273
-    /**
274
-     * Save the given data to the logged in user.
275
-     *
276
-     * @param  \Illuminate\Http\Request  $request
277
-     * @return \Illuminate\Http\Response
278
-     */
279
-    public function saveProfile(Request $request) 
280
-    {
281
-        $this->validate($request, [
282
-            'profile_picture' => 'nullable|string',
283
-            'name'            => 'nullable|string', 
284
-            'email'           => 'required|email|unique:users,email,' . \Auth::id()
285
-        ]);
286
-
287
-        return \Response::json($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')), 200);
288
-    }
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'users';
17
+
18
+	/**
19
+	 * List of all route actions that the base api controller
20
+	 * will skip permissions check for them.
21
+	 * @var array
22
+	 */
23
+	protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account'];
24
+
25
+	/**
26
+	 * List of all route actions that the base api controller
27
+	 * will skip login check for them.
28
+	 * @var array
29
+	 */
30
+	protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation'];
31
+
32
+	/**
33
+	 * The validations rules used by the base api controller
34
+	 * to check before add.
35
+	 * @var array
36
+	 */
37
+	protected $validationRules     = [
38
+		'name'     => 'nullable|string', 
39
+		'email'    => 'required|email|unique:users,email,{id}', 
40
+		'password' => 'nullable|min:6'
41
+	];
42
+
43
+	/**
44
+	 * The loginProxy implementation.
45
+	 * 
46
+	 * @var \App\Modules\Acl\Proxy\LoginProxy
47
+	 */
48
+	protected $loginProxy;
49
+
50
+	public function __construct(LoginProxy $loginProxy)
51
+	{        
52
+		$this->loginProxy = $loginProxy;
53
+		parent::__construct();
54
+	}
55
+
56
+	/**
57
+	 * Return the logged in user account.
58
+	 * 
59
+	 * @return \Illuminate\Http\Response
60
+	 */
61
+	public function account()
62
+	{
63
+		return \Response::json($this->repo->account($this->relations), 200);
64
+	}
65
+
66
+	/**
67
+	 * Block the user.
68
+	 *
69
+	 * @param  integer  $id Id of the user.
70
+	 * @return \Illuminate\Http\Response
71
+	 */
72
+	public function block($id)
73
+	{
74
+		return \Response::json($this->repo->block($id), 200);
75
+	}
76
+
77
+	/**
78
+	 * Unblock the user.
79
+	 *
80
+	 * @param  integer  $id Id of the user.
81
+	 * @return \Illuminate\Http\Response
82
+	 */
83
+	public function unblock($id)
84
+	{
85
+		return \Response::json($this->repo->unblock($id), 200);
86
+	}
87
+
88
+	/**
89
+	 * Logout the user.
90
+	 * 
91
+	 * @return \Illuminate\Http\Response
92
+	 */
93
+	public function logout()
94
+	{
95
+		return \Response::json($this->loginProxy->logout(), 200);
96
+	}
97
+
98
+	/**
99
+	 * Handle a registration request.
100
+	 *
101
+	 * @param  \Illuminate\Http\Request  $request
102
+	 * @return \Illuminate\Http\Response
103
+	 */
104
+	public function register(Request $request)
105
+	{
106
+		$this->validate($request, [
107
+			'name'     => 'nullable|string', 
108
+			'email'    => 'required|email|unique:users,email,{id}', 
109
+			'password' => 'required|min:6'
110
+			]);
111
+
112
+		return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200);
113
+	}
114
+
115
+	/**
116
+	 * Handle a login request to the application.
117
+	 *
118
+	 * @param  \Illuminate\Http\Request  $request
119
+	 * @return \Illuminate\Http\Response
120
+	 */
121
+	public function login(Request $request)
122
+	{
123
+		$this->validate($request, [
124
+			'email'    => 'required|email', 
125
+			'password' => 'required|min:6', 
126
+			'admin'    => 'nullable|boolean'
127
+			]);
128
+
129
+		return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200);
130
+	}
131
+
132
+	/**
133
+	 * Handle a social login request of the none admin to the application.
134
+	 *
135
+	 * @param  \Illuminate\Http\Request  $request
136
+	 * @return \Illuminate\Http\Response
137
+	 */
138
+	public function loginSocial(Request $request)
139
+	{
140
+		$this->validate($request, [
141
+			'auth_code'    => 'required_without:access_token',
142
+			'access_token' => 'required_without:auth_code',
143
+			'type'         => 'required|in:facebook,google'
144
+			]);
145
+
146
+		return \Response::json($this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')), 200);
147
+	}
148
+
149
+	/**
150
+	 * Assign the given groups to the given user.
151
+	 *
152
+	 * @param  \Illuminate\Http\Request  $request
153
+	 * @return \Illuminate\Http\Response
154
+	 */
155
+	public function assigngroups(Request $request)
156
+	{
157
+		$this->validate($request, [
158
+			'group_ids' => 'required|exists:groups,id', 
159
+			'user_id'   => 'required|exists:users,id'
160
+			]);
161
+
162
+		return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
163
+	}
164
+
165
+	/**
166
+	 * Send a reset link to the given user.
167
+	 *
168
+	 * @param  \Illuminate\Http\Request  $request
169
+	 * @return \Illuminate\Http\Response
170
+	 */
171
+	public function sendreset(Request $request)
172
+	{
173
+		$this->validate($request, ['email' => 'required|email']);
174
+
175
+		return \Response::json($this->repo->sendReset($request->get('email')), 200);
176
+	}
177
+
178
+	/**
179
+	 * Reset the given user's password.
180
+	 *
181
+	 * @param  \Illuminate\Http\Request  $request
182
+	 * @return \Illuminate\Http\Response
183
+	 */
184
+	public function resetpassword(Request $request)
185
+	{
186
+		$this->validate($request, [
187
+			'token'                 => 'required',
188
+			'email'                 => 'required|email',
189
+			'password'              => 'required|confirmed|min:6',
190
+			'password_confirmation' => 'required',
191
+		]);
192
+
193
+		return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
194
+	}
195
+
196
+	/**
197
+	 * Change the logged in user password.
198
+	 *
199
+	 * @param  \Illuminate\Http\Request  $request
200
+	 * @return \Illuminate\Http\Response
201
+	 */
202
+	public function changePassword(Request $request)
203
+	{
204
+		$this->validate($request, [
205
+			'old_password'          => 'required',
206
+			'password'              => 'required|confirmed|min:6',
207
+			'password_confirmation' => 'required',
208
+		]);
209
+
210
+		return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
211
+	}
212
+
213
+	/**
214
+	 * Confirm email using the confirmation code.
215
+	 *
216
+	 * @param  \Illuminate\Http\Request  $request
217
+	 * @return \Illuminate\Http\Response
218
+	 */
219
+	public function confirmEmail(Request $request)
220
+	{
221
+		$this->validate($request, [
222
+			'confirmation_code' => 'required|string|exists:users,confirmation_code'
223
+		]);
224
+
225
+		return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200);
226
+	}
227
+
228
+	/**
229
+	 * Resend the email confirmation mail.
230
+	 *
231
+	 * @param  \Illuminate\Http\Request  $request
232
+	 * @return \Illuminate\Http\Response
233
+	 */
234
+	public function resendEmailConfirmation(Request $request)
235
+	{
236
+		$this->validate($request, [
237
+			'email' => 'required|exists:users,email'
238
+		]);
239
+
240
+		return \Response::json($this->repo->sendConfirmationEmail($request->get('email')), 200);
241
+	}
242
+
243
+	/**
244
+	 * Refresh the expired login token.
245
+	 *
246
+	 * @param  \Illuminate\Http\Request  $request
247
+	 * @return \Illuminate\Http\Response
248
+	 */
249
+	public function refreshtoken(Request $request)
250
+	{
251
+		$this->validate($request, [
252
+			'refreshtoken' => 'required',
253
+		]);
254
+
255
+		return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200);
256
+	}
257
+
258
+	/**
259
+	 * Paginate all users with in the given group.
260
+	 * 
261
+	 * @param  \Illuminate\Http\Request  $request
262
+	 * @param  string $groupName The name of the requested group.
263
+	 * @param  integer $perPage  Number of rows per page default 15.
264
+	 * @param  string  $sortBy   The name of the column to sort by.
265
+	 * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
266
+	 * @return \Illuminate\Http\Response
267
+	 */
268
+	public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
269
+	{
270
+		return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
271
+	}
272
+
273
+	/**
274
+	 * Save the given data to the logged in user.
275
+	 *
276
+	 * @param  \Illuminate\Http\Request  $request
277
+	 * @return \Illuminate\Http\Response
278
+	 */
279
+	public function saveProfile(Request $request) 
280
+	{
281
+		$this->validate($request, [
282
+			'profile_picture' => 'nullable|string',
283
+			'name'            => 'nullable|string', 
284
+			'email'           => 'required|email|unique:users,email,' . \Auth::id()
285
+		]);
286
+
287
+		return \Response::json($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')), 200);
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * to preform actions like (add, edit ... etc).
14 14
      * @var string
15 15
      */
16
-    protected $model               = 'users';
16
+    protected $model = 'users';
17 17
 
18 18
     /**
19 19
      * List of all route actions that the base api controller
@@ -27,14 +27,14 @@  discard block
 block discarded – undo
27 27
      * will skip login check for them.
28 28
      * @var array
29 29
      */
30
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation'];
30
+    protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation'];
31 31
 
32 32
     /**
33 33
      * The validations rules used by the base api controller
34 34
      * to check before add.
35 35
      * @var array
36 36
      */
37
-    protected $validationRules     = [
37
+    protected $validationRules = [
38 38
         'name'     => 'nullable|string', 
39 39
         'email'    => 'required|email|unique:users,email,{id}', 
40 40
         'password' => 'nullable|min:6'
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
         $this->validate($request, [
282 282
             'profile_picture' => 'nullable|string',
283 283
             'name'            => 'nullable|string', 
284
-            'email'           => 'required|email|unique:users,email,' . \Auth::id()
284
+            'email'           => 'required|email|unique:users,email,'.\Auth::id()
285 285
         ]);
286 286
 
287 287
         return \Response::json($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')), 200);
Please login to merge, or discard this patch.
src/Modules/Core/Utl/Media.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -2,63 +2,63 @@
 block discarded – undo
2 2
 
3 3
 class Media
4 4
 {
5
-    /**
6
-     * Upload the given image.
7
-     * 
8
-     * @param  object  $image
9
-     * @param  string  $dir
10
-     * @return string
11
-     */
12
-    public function uploadImage($image, $dir) 
13
-    {
14
-       $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
15
-       $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
5
+	/**
6
+	 * Upload the given image.
7
+	 * 
8
+	 * @param  object  $image
9
+	 * @param  string  $dir
10
+	 * @return string
11
+	 */
12
+	public function uploadImage($image, $dir) 
13
+	{
14
+	   $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
15
+	   $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
16 16
 
17
-       ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
18
-       $image->move($destinationPath, $imageName);
17
+	   ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
18
+	   $image->move($destinationPath, $imageName);
19 19
 
20
-       return url($destinationPath . $imageName);
21
-    }
20
+	   return url($destinationPath . $imageName);
21
+	}
22 22
 
23
-    /**
24
-     * Upload the given image.
25
-     * 
26
-     * @param  object  $image
27
-     * @param  string  $dir
28
-     * @return string
29
-     */
30
-    public function uploadImageBas64($image, $dir) 
31
-    {
32
-        if (! strlen($image)) 
33
-        {
34
-            return null;
35
-        }
23
+	/**
24
+	 * Upload the given image.
25
+	 * 
26
+	 * @param  object  $image
27
+	 * @param  string  $dir
28
+	 * @return string
29
+	 */
30
+	public function uploadImageBas64($image, $dir) 
31
+	{
32
+		if (! strlen($image)) 
33
+		{
34
+			return null;
35
+		}
36 36
         
37
-        $imageName       = 'image' . uniqid() . time() . '.jpg';
38
-        $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
37
+		$imageName       = 'image' . uniqid() . time() . '.jpg';
38
+		$destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
39 39
 
40
-        ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
40
+		! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
41 41
 
42
-        $base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
43
-        \Image::make($base)->save($destinationPath . $imageName);
42
+		$base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
43
+		\Image::make($base)->save($destinationPath . $imageName);
44 44
 
45
-        return url($destinationPath . $imageName);
46
-    }
45
+		return url($destinationPath . $imageName);
46
+	}
47 47
 
48
-    /**
49
-     * Delete the given image.
50
-     * 
51
-     * @param  object  $path
52
-     * @param  string  $dir
53
-     * @return void
54
-     */
55
-    public function deleteImage($path, $dir) 
56
-    {   
57
-        $arr      = explode('/', $path);
58
-        $path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
59
-        if (\File::exists($path)) 
60
-        {
61
-            \File::delete($path);
62
-        }
63
-    }
48
+	/**
49
+	 * Delete the given image.
50
+	 * 
51
+	 * @param  object  $path
52
+	 * @param  string  $dir
53
+	 * @return void
54
+	 */
55
+	public function deleteImage($path, $dir) 
56
+	{   
57
+		$arr      = explode('/', $path);
58
+		$path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
59
+		if (\File::exists($path)) 
60
+		{
61
+			\File::delete($path);
62
+		}
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
      */
12 12
     public function uploadImage($image, $dir) 
13 13
     {
14
-       $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
15
-       $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
14
+       $imageName       = str_slug('image'.uniqid().time().'_'.$image->getClientOriginalName());
15
+       $destinationPath = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR;
16 16
 
17 17
        ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
18 18
        $image->move($destinationPath, $imageName);
19 19
 
20
-       return url($destinationPath . $imageName);
20
+       return url($destinationPath.$imageName);
21 21
     }
22 22
 
23 23
     /**
@@ -29,20 +29,20 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function uploadImageBas64($image, $dir) 
31 31
     {
32
-        if (! strlen($image)) 
32
+        if ( ! strlen($image)) 
33 33
         {
34 34
             return null;
35 35
         }
36 36
         
37
-        $imageName       = 'image' . uniqid() . time() . '.jpg';
38
-        $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
37
+        $imageName       = 'image'.uniqid().time().'.jpg';
38
+        $destinationPath = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR;
39 39
 
40 40
         ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
41 41
 
42
-        $base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
43
-        \Image::make($base)->save($destinationPath . $imageName);
42
+        $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
43
+        \Image::make($base)->save($destinationPath.$imageName);
44 44
 
45
-        return url($destinationPath . $imageName);
45
+        return url($destinationPath.$imageName);
46 46
     }
47 47
 
48 48
     /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public function deleteImage($path, $dir) 
56 56
     {   
57 57
         $arr      = explode('/', $path);
58
-        $path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
58
+        $path     = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.end($arr);
59 59
         if (\File::exists($path)) 
60 60
         {
61 61
             \File::delete($path);
Please login to merge, or discard this patch.
src/Modules/Core/Traits/Translatable.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -2,50 +2,50 @@
 block discarded – undo
2 2
 
3 3
 trait Translatable  
4 4
 {
5
-    /**
6
-     * Create a new model instance that is existing.
7
-     *
8
-     * @param  array  $attributes
9
-     * @param  string|null  $connection
10
-     * @return static
11
-     */
12
-    public function newFromBuilder($attributes = [], $connection = null)
13
-    {
14
-        $model = parent::newFromBuilder($attributes, $connection);
5
+	/**
6
+	 * Create a new model instance that is existing.
7
+	 *
8
+	 * @param  array  $attributes
9
+	 * @param  string|null  $connection
10
+	 * @return static
11
+	 */
12
+	public function newFromBuilder($attributes = [], $connection = null)
13
+	{
14
+		$model = parent::newFromBuilder($attributes, $connection);
15 15
 
16
-        foreach ($model->attributes AS $key => $value)
17
-        {
18
-            if (isset($this->translatable) && in_array($key, $this->translatable)) 
19
-            {
20
-                $model->$key = $this->getTranslatedAttribute($value);
21
-            }
22
-        }
16
+		foreach ($model->attributes AS $key => $value)
17
+		{
18
+			if (isset($this->translatable) && in_array($key, $this->translatable)) 
19
+			{
20
+				$model->$key = $this->getTranslatedAttribute($value);
21
+			}
22
+		}
23 23
 
24
-        return $model;
25
-    }
24
+		return $model;
25
+	}
26 26
 
27
-    /**
28
-     * Returns a translatable model attribute based on the application's locale settings.
29
-     *
30
-     * @param $values
31
-     * @return string
32
-     */
33
-    protected function getTranslatedAttribute($values)
34
-    {
35
-        $values         = json_decode($values);
36
-        $primaryLocale  = \Session::get('locale');
37
-        $fallbackLocale = 'en';
27
+	/**
28
+	 * Returns a translatable model attribute based on the application's locale settings.
29
+	 *
30
+	 * @param $values
31
+	 * @return string
32
+	 */
33
+	protected function getTranslatedAttribute($values)
34
+	{
35
+		$values         = json_decode($values);
36
+		$primaryLocale  = \Session::get('locale');
37
+		$fallbackLocale = 'en';
38 38
 
39
-        if ($primaryLocale == 'all') 
40
-        {
41
-            return $values;
42
-        }
39
+		if ($primaryLocale == 'all') 
40
+		{
41
+			return $values;
42
+		}
43 43
 
44
-        if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) 
45
-        {
46
-            return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
47
-        }
44
+		if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) 
45
+		{
46
+			return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
47
+		}
48 48
 
49
-        return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
50
-    }
49
+		return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Core/Providers/ModuleServiceProvider.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -7,50 +7,50 @@
 block discarded – undo
7 7
 class ModuleServiceProvider extends ServiceProvider
8 8
 {
9 9
 	/**
10
-     * Bootstrap the module services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core');
17
-        $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core');
18
-
19
-        $factory = app('Illuminate\Database\Eloquent\Factory');
20
-        $factory->load(__DIR__.'/../Database/Factories');
21
-    }
22
-
23
-    /**
24
-     * Register the module services.
25
-     *
26
-     * @return void
27
-     */
28
-    public function register()
29
-    {
30
-        //Bind Core Facade to the IoC Container
31
-        \App::bind('Core', function()
32
-        {
33
-            return new \App\Modules\Core\Core;
34
-        });
35
-
36
-        //Bind ErrorHandler Facade to the IoC Container
37
-        \App::bind('ErrorHandler', function()
38
-        {
39
-            return new \App\Modules\Core\Utl\ErrorHandler;
40
-        });
41
-
42
-        //Bind CoreConfig Facade to the IoC Container
43
-        \App::bind('CoreConfig', function()
44
-        {
45
-            return new \App\Modules\Core\Utl\CoreConfig;
46
-        });
47
-
48
-        //Bind Mpgs Facade to the IoC Container
49
-        \App::bind('Media', function()
50
-        {
51
-            return new \App\Modules\Core\Utl\Media;
52
-        });
10
+	 * Bootstrap the module services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core');
17
+		$this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core');
18
+
19
+		$factory = app('Illuminate\Database\Eloquent\Factory');
20
+		$factory->load(__DIR__.'/../Database/Factories');
21
+	}
22
+
23
+	/**
24
+	 * Register the module services.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function register()
29
+	{
30
+		//Bind Core Facade to the IoC Container
31
+		\App::bind('Core', function()
32
+		{
33
+			return new \App\Modules\Core\Core;
34
+		});
35
+
36
+		//Bind ErrorHandler Facade to the IoC Container
37
+		\App::bind('ErrorHandler', function()
38
+		{
39
+			return new \App\Modules\Core\Utl\ErrorHandler;
40
+		});
41
+
42
+		//Bind CoreConfig Facade to the IoC Container
43
+		\App::bind('CoreConfig', function()
44
+		{
45
+			return new \App\Modules\Core\Utl\CoreConfig;
46
+		});
47
+
48
+		//Bind Mpgs Facade to the IoC Container
49
+		\App::bind('Media', function()
50
+		{
51
+			return new \App\Modules\Core\Utl\Media;
52
+		});
53 53
         
54
-        $this->app->register(RouteServiceProvider::class);
55
-    }
54
+		$this->app->register(RouteServiceProvider::class);
55
+	}
56 56
 }
Please login to merge, or discard this patch.
src/Modules/Acl/OauthClient.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 
7 7
 class OauthClient extends Client
8 8
 {
9
-    protected $dates    = ['created_at', 'updated_at'];
10
-    protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked'];
11
-    public $searchable  = ['name'];
9
+	protected $dates    = ['created_at', 'updated_at'];
10
+	protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked'];
11
+	public $searchable  = ['name'];
12 12
     
13
-    public function getCreatedAtAttribute($value)
14
-    {
15
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
16
-    }
13
+	public function getCreatedAtAttribute($value)
14
+	{
15
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
16
+	}
17 17
 
18
-    public function getUpdatedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
-    }
18
+	public function getUpdatedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
+	}
22 22
     
23
-    public static function boot()
24
-    {
25
-        parent::boot();
26
-        OauthClient::observe(\App::make('App\Modules\Acl\ModelObservers\OauthClientObserver'));
27
-    }
23
+	public static function boot()
24
+	{
25
+		parent::boot();
26
+		OauthClient::observe(\App::make('App\Modules\Acl\ModelObservers\OauthClientObserver'));
27
+	}
28 28
 }
Please login to merge, or discard this patch.
src/Modules/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -2,118 +2,118 @@
 block discarded – undo
2 2
 
3 3
 interface RepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
     
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30
-    /**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
30
+	/**
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
     
42
-    /**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
42
+	/**
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array $data
60
-     * @return mixed
61
-     */
62
-    public function save(array $data);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array $data
60
+	  * @return mixed
61
+	  */
62
+	public function save(array $data);
63 63
 
64
-    /**
65
-     * Update record in the storage based on the given
66
-     * condition.
67
-     * 
68
-     * @param  var     $value condition value
69
-     * @param  array   $data
70
-     * @param  string  $attribute condition column name
71
-     * @return integer affected rows
72
-     */
73
-    public function update($value, array $data, $attribute = 'id');
64
+	/**
65
+	 * Update record in the storage based on the given
66
+	 * condition.
67
+	 * 
68
+	 * @param  var     $value condition value
69
+	 * @param  array   $data
70
+	 * @param  string  $attribute condition column name
71
+	 * @return integer affected rows
72
+	 */
73
+	public function update($value, array $data, $attribute = 'id');
74 74
 
75
-    /**
76
-     * Delete record from the storage based on the given
77
-     * condition.
78
-     * 
79
-     * @param  var     $value condition value
80
-     * @param  string  $attribute condition column name
81
-     * @return integer affected rows
82
-     */
83
-    public function delete($value, $attribute = 'id');
75
+	/**
76
+	 * Delete record from the storage based on the given
77
+	 * condition.
78
+	 * 
79
+	 * @param  var     $value condition value
80
+	 * @param  string  $attribute condition column name
81
+	 * @return integer affected rows
82
+	 */
83
+	public function delete($value, $attribute = 'id');
84 84
     
85
-    /**
86
-     * Fetch records from the storage based on the given
87
-     * id.
88
-     * 
89
-     * @param  integer $id
90
-     * @param  array   $relations
91
-     * @param  array   $columns
92
-     * @return object
93
-     */
94
-    public function find($id, $relations = [], $columns = array('*'));
85
+	/**
86
+	 * Fetch records from the storage based on the given
87
+	 * id.
88
+	 * 
89
+	 * @param  integer $id
90
+	 * @param  array   $relations
91
+	 * @param  array   $columns
92
+	 * @return object
93
+	 */
94
+	public function find($id, $relations = [], $columns = array('*'));
95 95
     
96
-    /**
97
-     * Fetch records from the storage based on the given
98
-     * condition.
99
-     * 
100
-     * @param  array   $conditions array of conditions
101
-     * @param  array   $relations
102
-     * @param  array   $sortBy
103
-     * @param  array   $desc
104
-     * @param  array   $columns
105
-     * @return collection
106
-     */
107
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
96
+	/**
97
+	 * Fetch records from the storage based on the given
98
+	 * condition.
99
+	 * 
100
+	 * @param  array   $conditions array of conditions
101
+	 * @param  array   $relations
102
+	 * @param  array   $sortBy
103
+	 * @param  array   $desc
104
+	 * @param  array   $columns
105
+	 * @return collection
106
+	 */
107
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
108 108
 
109
-    /**
110
-     * Fetch the first record fro the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  array   $conditions array of conditions
114
-     * @param  array   $relations
115
-     * @param  array   $columns
116
-     * @return object
117
-     */
118
-    public function first($conditions, $relations = [], $columns = array('*'));
109
+	/**
110
+	 * Fetch the first record fro the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  array   $conditions array of conditions
114
+	 * @param  array   $relations
115
+	 * @param  array   $columns
116
+	 * @return object
117
+	 */
118
+	public function first($conditions, $relations = [], $columns = array('*'));
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.