Completed
Push — master ( 2c4876...f9862b )
by Sherif
10:06
created
src/Modules/V1/Acl/Database/Factories/UserFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$factory->define(App\Modules\V1\Acl\AclUser::class, function (Faker\Generator $faker) {
3
+$factory->define(App\Modules\V1\Acl\AclUser::class, function(Faker\Generator $faker) {
4 4
     return [
5 5
 		'profile_picture' => 'http://lorempixel.com/400/200/',
6 6
 		'name'            => $faker->name(),
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $factory->define(App\Modules\V1\Acl\AclUser::class, function (Faker\Generator $faker) {
4
-    return [
4
+	return [
5 5
 		'profile_picture' => 'http://lorempixel.com/400/200/',
6 6
 		'name'            => $faker->name(),
7 7
 		'email'           => $faker->safeEmail(),
8 8
 		'password'        => 123456,
9 9
 		'created_at'      => $faker->dateTimeBetween('-1 years', 'now'),
10 10
 		'updated_at'      => $faker->dateTimeBetween('-1 years', 'now')
11
-    ];
11
+	];
12 12
 });
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 4 patches
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
         
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function assignGroups($user_id, $group_ids)
83 83
     {
84
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
+        \DB::transaction(function() use ($user_id, $group_ids) {
85 85
             $user = $this->find($user_id);
86 86
             $user->groups()->detach();
87 87
             $user->groups()->attach($group_ids);
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function resetPassword($credentials)
250 250
     {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
251
+        $response = \Password::reset($credentials, function($user, $password) {
252 252
             $user->password = $password;
253 253
             $user->save();
254 254
         });
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
     /**
62 62
      * Check if the logged in user has the given group.
63 63
      * 
64
-     * @param  string  $groupName
65
-     * @param  integer $userId
64
+     * @param  integer $user
65
+     * @param string[] $groups
66 66
      * @return boolean
67 67
      */
68 68
     public function hasGroup($groups, $user = false)
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      * Reset the given user's password.
245 245
      *
246 246
      * @param  array  $credentials
247
-     * @return array
247
+     * @return string|null
248 248
      */
249 249
     public function resetPassword($credentials)
250 250
     {
@@ -361,7 +361,6 @@  discard block
 block discarded – undo
361 361
     /**
362 362
      * Save the given data to the logged in user.
363 363
      *
364
-     * @param  array $credentials
365 364
      * @return void
366 365
      */
367 366
     public function saveProfile($data) 
Please login to merge, or discard this patch.
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 ( ! $user->confirmed)
114
+        } else if ( ! $user->confirmed)
119 115
         {
120 116
             \ErrorHandler::emailNotConfirmed();
121 117
         }
@@ -143,8 +139,7 @@  discard block
 block discarded – undo
143 139
         {
144 140
             $data = ['email' => $user->email, 'password' => ''];
145 141
             return $this->register($data);
146
-        }
147
-        else
142
+        } else
148 143
         {
149 144
             if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150 145
             {
@@ -187,12 +182,10 @@  discard block
 block discarded – undo
187 182
         if ( ! $this->hasGroup(['Admin']))
188 183
         {
189 184
             \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
185
+        } else if (\Auth::id() == $user_id)
192 186
         {
193 187
             \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
188
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196 189
         {
197 190
             \ErrorHandler::noPermissions();
198 191
         }
Please login to merge, or discard this patch.
Indentation   +382 added lines, -382 removed lines patch added patch discarded remove patch
@@ -5,394 +5,394 @@
 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\V1\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  boolean $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\V1\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  boolean $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  string  $groupName
65
-     * @param  integer $userId
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 $user_id    
78
-     * @param  array   $group_ids
79
-     * @return object
80
-     */
81
-    public function assignGroups($user_id, $group_ids)
82
-    {
83
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
-            $user = $this->find($user_id);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($group_ids);
87
-        });
88
-
89
-        return $this->find($user_id);
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 ( ! $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  array   $credentials
130
-     * @return array
131
-     */
132
-    public function loginSocial($credentials)
133
-    {
134
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
-
137
-        if ( ! $user->email)
138
-        {
139
-            \ErrorHandler::noSocialEmail();
140
-        }
141
-
142
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
-        {
144
-            $data = ['email' => $user->email, 'password' => ''];
145
-            return $this->register($data);
146
-        }
147
-        else
148
-        {
149
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
-            {
151
-                \ErrorHandler::userAlreadyRegistered();
152
-            }
153
-
154
-            $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
155
-            return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
-        }
157
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  string  $groupName
65
+	 * @param  integer $userId
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 $user_id    
78
+	 * @param  array   $group_ids
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($user_id, $group_ids)
82
+	{
83
+		\DB::transaction(function () use ($user_id, $group_ids) {
84
+			$user = $this->find($user_id);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($group_ids);
87
+		});
88
+
89
+		return $this->find($user_id);
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 ( ! $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  array   $credentials
130
+	 * @return array
131
+	 */
132
+	public function loginSocial($credentials)
133
+	{
134
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
+
137
+		if ( ! $user->email)
138
+		{
139
+			\ErrorHandler::noSocialEmail();
140
+		}
141
+
142
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
+		{
144
+			$data = ['email' => $user->email, 'password' => ''];
145
+			return $this->register($data);
146
+		}
147
+		else
148
+		{
149
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
+			{
151
+				\ErrorHandler::userAlreadyRegistered();
152
+			}
153
+
154
+			$loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
155
+			return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
+		}
157
+	}
158 158
     
159
-    /**
160
-     * Handle a registration request.
161
-     * 
162
-     * @param  array $credentials
163
-     * @return array
164
-     */
165
-    public function register($credentials)
166
-    {
167
-        $user = $this->save($credentials);
168
-
169
-        if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-    }
159
+	/**
160
+	 * Handle a registration request.
161
+	 * 
162
+	 * @param  array $credentials
163
+	 * @return array
164
+	 */
165
+	public function register($credentials)
166
+	{
167
+		$user = $this->save($credentials);
168
+
169
+		if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+	}
174 174
     
175
-    /**
176
-     * Block the user.
177
-     *
178
-     * @param  integer $user_id
179
-     * @return object
180
-     */
181
-    public function block($user_id)
182
-    {
183
-        if ( ! $user = $this->find($user_id)) 
184
-        {
185
-            \ErrorHandler::notFound('user');
186
-        }
187
-        if ( ! $this->hasGroup(['Admin']))
188
-        {
189
-            \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
192
-        {
193
-            \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
-        {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user->blocked = 1;
201
-        $user->save();
175
+	/**
176
+	 * Block the user.
177
+	 *
178
+	 * @param  integer $user_id
179
+	 * @return object
180
+	 */
181
+	public function block($user_id)
182
+	{
183
+		if ( ! $user = $this->find($user_id)) 
184
+		{
185
+			\ErrorHandler::notFound('user');
186
+		}
187
+		if ( ! $this->hasGroup(['Admin']))
188
+		{
189
+			\ErrorHandler::noPermissions();
190
+		}
191
+		else if (\Auth::id() == $user_id)
192
+		{
193
+			\ErrorHandler::noPermissions();
194
+		}
195
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
+		{
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user->blocked = 1;
201
+		$user->save();
202 202
         
203
-        return $user;
204
-    }
205
-
206
-    /**
207
-     * Unblock the user.
208
-     *
209
-     * @param  integer $user_id
210
-     * @return object
211
-     */
212
-    public function unblock($user_id)
213
-    {
214
-        if ( ! $this->hasGroup(['Admin']))
215
-        {
216
-            \ErrorHandler::noPermissions();
217
-        }
218
-
219
-        $user          = $this->find($user_id);
220
-        $user->blocked = 0;
221
-        $user->save();
222
-
223
-        return $user;
224
-    }
225
-
226
-    /**
227
-     * Send a reset link to the given user.
228
-     *
229
-     * @param  string  $email
230
-     * @return void
231
-     */
232
-    public function sendReset($email)
233
-    {
234
-        if ( ! $user = $this->model->where('email', $email)->first())
235
-        {
236
-            \ErrorHandler::notFound('email');
237
-        }
238
-
239
-        $token = \Password::getRepository()->create($user);
240
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
241
-    }
242
-
243
-    /**
244
-     * Reset the given user's password.
245
-     *
246
-     * @param  array  $credentials
247
-     * @return array
248
-     */
249
-    public function resetPassword($credentials)
250
-    {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
252
-            $user->password = $password;
253
-            $user->save();
254
-        });
255
-
256
-        switch ($response) {
257
-            case \Password::PASSWORD_RESET:
258
-                return 'success';
203
+		return $user;
204
+	}
205
+
206
+	/**
207
+	 * Unblock the user.
208
+	 *
209
+	 * @param  integer $user_id
210
+	 * @return object
211
+	 */
212
+	public function unblock($user_id)
213
+	{
214
+		if ( ! $this->hasGroup(['Admin']))
215
+		{
216
+			\ErrorHandler::noPermissions();
217
+		}
218
+
219
+		$user          = $this->find($user_id);
220
+		$user->blocked = 0;
221
+		$user->save();
222
+
223
+		return $user;
224
+	}
225
+
226
+	/**
227
+	 * Send a reset link to the given user.
228
+	 *
229
+	 * @param  string  $email
230
+	 * @return void
231
+	 */
232
+	public function sendReset($email)
233
+	{
234
+		if ( ! $user = $this->model->where('email', $email)->first())
235
+		{
236
+			\ErrorHandler::notFound('email');
237
+		}
238
+
239
+		$token = \Password::getRepository()->create($user);
240
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
241
+	}
242
+
243
+	/**
244
+	 * Reset the given user's password.
245
+	 *
246
+	 * @param  array  $credentials
247
+	 * @return array
248
+	 */
249
+	public function resetPassword($credentials)
250
+	{
251
+		$response = \Password::reset($credentials, function ($user, $password) {
252
+			$user->password = $password;
253
+			$user->save();
254
+		});
255
+
256
+		switch ($response) {
257
+			case \Password::PASSWORD_RESET:
258
+				return 'success';
259 259
                 
260
-            case \Password::INVALID_TOKEN:
261
-                \ErrorHandler::invalidResetToken('token');
262
-
263
-            case \Password::INVALID_PASSWORD:
264
-                \ErrorHandler::invalidResetPassword('email');
265
-
266
-            case \Password::INVALID_USER:
267
-                \ErrorHandler::notFound('user');
268
-
269
-            default:
270
-                \ErrorHandler::generalError();
271
-        }
272
-    }
273
-
274
-    /**
275
-     * Change the logged in user password.
276
-     *
277
-     * @param  array  $credentials
278
-     * @return void
279
-     */
280
-    public function changePassword($credentials)
281
-    {
282
-        $user = \Auth::user();
283
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
-        {
285
-            \ErrorHandler::invalidOldPassword();
286
-        }
287
-
288
-        $user->password = $credentials['password'];
289
-        $user->save();
290
-    }
291
-
292
-    /**
293
-     * Confirm email using the confirmation code.
294
-     *
295
-     * @param  string $confirmationCode
296
-     * @return void
297
-     */
298
-    public function confirmEmail($confirmationCode)
299
-    {
300
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
-        $user->confirmed         = 1;
302
-        $user->confirmation_code = null;
303
-        $user->save();
304
-    }
305
-
306
-    /**
307
-     * Send the confirmation mail.
308
-     *
309
-     * @param  string $email
310
-     * @return void
311
-     */
312
-    public function sendConfirmationEmail($email)
313
-    {
314
-        $user = $this->first(['email' => $email]);
315
-        if ($user->confirmed) 
316
-        {
317
-            \ErrorHandler::emailAlreadyConfirmed();
318
-        }
319
-
320
-        $user->confirmed         = 0;
321
-        $user->confirmation_code = sha1(microtime());
322
-        $user->save();
323
-        \Core::notifications()->notify($user, 'ConfirmEmail');
324
-    }
325
-
326
-    /**
327
-     * Paginate all users in the given group based on the given conditions.
328
-     * 
329
-     * @param  string  $groupName
330
-     * @param  array   $relations
331
-     * @param  integer $perPage
332
-     * @param  string  $sortBy
333
-     * @param  boolean $desc
334
-     * @return \Illuminate\Http\Response
335
-     */
336
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
-    {   
338
-        unset($conditions['page']);
339
-        $conditions = $this->constructConditions($conditions, $this->model);
340
-        $sort       = $desc ? 'desc' : 'asc';
341
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
-
343
-        $model->whereHas('groups', function($q) use ($groupName){
344
-            $q->where('name', $groupName);
345
-        });
260
+			case \Password::INVALID_TOKEN:
261
+				\ErrorHandler::invalidResetToken('token');
262
+
263
+			case \Password::INVALID_PASSWORD:
264
+				\ErrorHandler::invalidResetPassword('email');
265
+
266
+			case \Password::INVALID_USER:
267
+				\ErrorHandler::notFound('user');
268
+
269
+			default:
270
+				\ErrorHandler::generalError();
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * Change the logged in user password.
276
+	 *
277
+	 * @param  array  $credentials
278
+	 * @return void
279
+	 */
280
+	public function changePassword($credentials)
281
+	{
282
+		$user = \Auth::user();
283
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
+		{
285
+			\ErrorHandler::invalidOldPassword();
286
+		}
287
+
288
+		$user->password = $credentials['password'];
289
+		$user->save();
290
+	}
291
+
292
+	/**
293
+	 * Confirm email using the confirmation code.
294
+	 *
295
+	 * @param  string $confirmationCode
296
+	 * @return void
297
+	 */
298
+	public function confirmEmail($confirmationCode)
299
+	{
300
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
+		$user->confirmed         = 1;
302
+		$user->confirmation_code = null;
303
+		$user->save();
304
+	}
305
+
306
+	/**
307
+	 * Send the confirmation mail.
308
+	 *
309
+	 * @param  string $email
310
+	 * @return void
311
+	 */
312
+	public function sendConfirmationEmail($email)
313
+	{
314
+		$user = $this->first(['email' => $email]);
315
+		if ($user->confirmed) 
316
+		{
317
+			\ErrorHandler::emailAlreadyConfirmed();
318
+		}
319
+
320
+		$user->confirmed         = 0;
321
+		$user->confirmation_code = sha1(microtime());
322
+		$user->save();
323
+		\Core::notifications()->notify($user, 'ConfirmEmail');
324
+	}
325
+
326
+	/**
327
+	 * Paginate all users in the given group based on the given conditions.
328
+	 * 
329
+	 * @param  string  $groupName
330
+	 * @param  array   $relations
331
+	 * @param  integer $perPage
332
+	 * @param  string  $sortBy
333
+	 * @param  boolean $desc
334
+	 * @return \Illuminate\Http\Response
335
+	 */
336
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
+	{   
338
+		unset($conditions['page']);
339
+		$conditions = $this->constructConditions($conditions, $this->model);
340
+		$sort       = $desc ? 'desc' : 'asc';
341
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
+
343
+		$model->whereHas('groups', function($q) use ($groupName){
344
+			$q->where('name', $groupName);
345
+		});
346 346
 
347 347
         
348
-        if (count($conditions['conditionValues']))
349
-        {
350
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
-        }
352
-
353
-        if ($perPage) 
354
-        {
355
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
-        }
357
-
358
-        return $model->orderBy($sortBy, $sort)->get();
359
-    }
360
-
361
-    /**
362
-     * Save the given data to the logged in user.
363
-     *
364
-     * @param  array $credentials
365
-     * @return void
366
-     */
367
-    public function saveProfile($data) 
368
-    {
369
-        if (array_key_exists('profile_picture', $data)) 
370
-        {
371
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
-        }
348
+		if (count($conditions['conditionValues']))
349
+		{
350
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
+		}
352
+
353
+		if ($perPage) 
354
+		{
355
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
+		}
357
+
358
+		return $model->orderBy($sortBy, $sort)->get();
359
+	}
360
+
361
+	/**
362
+	 * Save the given data to the logged in user.
363
+	 *
364
+	 * @param  array $credentials
365
+	 * @return void
366
+	 */
367
+	public function saveProfile($data) 
368
+	{
369
+		if (array_key_exists('profile_picture', $data)) 
370
+		{
371
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
+		}
373 373
         
374
-        $data['id'] = \Auth::id();
375
-        $this->save($data);
376
-    }
377
-
378
-    /**
379
-     * Ensure access token hasn't expired or revoked.
380
-     * 
381
-     * @param  string $accessToken
382
-     * @return boolean
383
-     */
384
-    public function accessTokenExpiredOrRevoked($accessToken)
385
-    {
386
-
387
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
-        $data = new ValidationData();
389
-        $data->setCurrentTime(time());
390
-
391
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
-        {
393
-            return true;
394
-        }
395
-
396
-        return false;
397
-    }
374
+		$data['id'] = \Auth::id();
375
+		$this->save($data);
376
+	}
377
+
378
+	/**
379
+	 * Ensure access token hasn't expired or revoked.
380
+	 * 
381
+	 * @param  string $accessToken
382
+	 * @return boolean
383
+	 */
384
+	public function accessTokenExpiredOrRevoked($accessToken)
385
+	{
386
+
387
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
+		$data = new ValidationData();
389
+		$data->setCurrentTime(time());
390
+
391
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
+		{
393
+			return true;
394
+		}
395
+
396
+		return false;
397
+	}
398 398
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Providers/ModuleServiceProvider.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -7,75 +7,75 @@
 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');
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 18
 
19
-        $factory = app('Illuminate\Database\Eloquent\Factory');
20
-        $factory->load(__DIR__.'/../Database/Factories');
21
-    }
19
+		$factory = app('Illuminate\Database\Eloquent\Factory');
20
+		$factory->load(__DIR__.'/../Database/Factories');
21
+	}
22 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\V1\Core\Core;
34
-        });
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\V1\Core\Core;
34
+		});
35 35
 
36
-        //Bind ErrorHandler Facade to the IoC Container
37
-        \App::bind('ErrorHandler', function()
38
-        {
39
-            return new \App\Modules\V1\Core\Utl\ErrorHandler;
40
-        });
36
+		//Bind ErrorHandler Facade to the IoC Container
37
+		\App::bind('ErrorHandler', function()
38
+		{
39
+			return new \App\Modules\V1\Core\Utl\ErrorHandler;
40
+		});
41 41
 
42
-        //Bind CoreConfig Facade to the IoC Container
43
-        \App::bind('CoreConfig', function()
44
-        {
45
-            return new \App\Modules\V1\Core\Utl\CoreConfig;
46
-        });
42
+		//Bind CoreConfig Facade to the IoC Container
43
+		\App::bind('CoreConfig', function()
44
+		{
45
+			return new \App\Modules\V1\Core\Utl\CoreConfig;
46
+		});
47 47
 
48
-        //Bind Mpgs Facade to the IoC Container
49
-        \App::bind('Media', function()
50
-        {
51
-            return new \App\Modules\V1\Core\Utl\Media;
52
-        });
48
+		//Bind Mpgs Facade to the IoC Container
49
+		\App::bind('Media', function()
50
+		{
51
+			return new \App\Modules\V1\Core\Utl\Media;
52
+		});
53 53
 
54
-        \Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) {
55
-            $explode = explode(',', $value);
56
-            $allow   = ['png', 'jpg', 'svg'];
57
-            $format  = str_replace(
58
-                [
59
-                    'data:image/',
60
-                    ';',
61
-                    'base64',
62
-                ],
63
-                [
64
-                    '', '', '',
65
-                ],
66
-                $explode[0]
67
-            );
68
-            // check file format
69
-            if (!in_array($format, $allow)) {
70
-                return false;
71
-            }
72
-            // check base64 format
73
-            if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
74
-                return false;
75
-            }
76
-            return true;
77
-        });
54
+		\Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) {
55
+			$explode = explode(',', $value);
56
+			$allow   = ['png', 'jpg', 'svg'];
57
+			$format  = str_replace(
58
+				[
59
+					'data:image/',
60
+					';',
61
+					'base64',
62
+				],
63
+				[
64
+					'', '', '',
65
+				],
66
+				$explode[0]
67
+			);
68
+			// check file format
69
+			if (!in_array($format, $allow)) {
70
+				return false;
71
+			}
72
+			// check base64 format
73
+			if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
74
+				return false;
75
+			}
76
+			return true;
77
+		});
78 78
         
79
-        $this->app->register(RouteServiceProvider::class);
80
-    }
79
+		$this->app->register(RouteServiceProvider::class);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             return new \App\Modules\V1\Core\Utl\Media;
52 52
         });
53 53
 
54
-        \Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) {
54
+        \Validator::extend('base64image', function($attribute, $value, $parameters, $validator) {
55 55
             $explode = explode(',', $value);
56 56
             $allow   = ['png', 'jpg', 'svg'];
57 57
             $format  = str_replace(
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
                 $explode[0]
67 67
             );
68 68
             // check file format
69
-            if (!in_array($format, $allow)) {
69
+            if ( ! in_array($format, $allow)) {
70 70
                 return false;
71 71
             }
72 72
             // check base64 format
73
-            if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
73
+            if ( ! preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
74 74
                 return false;
75 75
             }
76 76
             return true;
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/CoreConfig.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@  discard block
 block discarded – undo
2 2
 
3 3
 class CoreConfig
4 4
 {
5
-    public function getConfig()
6
-    {
7
-        return [
5
+	public function getConfig()
6
+	{
7
+		return [
8 8
 			/**
9 9
 			 * Specify what relations should be used for every model.
10 10
 			 */
@@ -133,5 +133,5 @@  discard block
 block discarded – undo
133 133
 				]
134 134
 			]
135 135
 		];
136
-    }
136
+	}
137 137
 }
138 138
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Notifications/Notifications/ConfirmEmail.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -10,41 +10,41 @@
 block discarded – undo
10 10
 
11 11
 class ConfirmEmail extends Notification implements ShouldQueue
12 12
 {
13
-    use Queueable;
13
+	use Queueable;
14 14
 
15
-    /**
16
-     * Create a new notification instance.
17
-     *
18
-     * @return void
19
-     */
20
-    public function __construct()
21
-    {
22
-        //
23
-    }
15
+	/**
16
+	 * Create a new notification instance.
17
+	 *
18
+	 * @return void
19
+	 */
20
+	public function __construct()
21
+	{
22
+		//
23
+	}
24 24
 
25
-    /**
26
-     * Get the notification's delivery channels.
27
-     *
28
-     * @param  mixed  $notifiable
29
-     * @return array
30
-     */
31
-    public function via($notifiable)
32
-    {
33
-        return ['mail'];
34
-    }
25
+	/**
26
+	 * Get the notification's delivery channels.
27
+	 *
28
+	 * @param  mixed  $notifiable
29
+	 * @return array
30
+	 */
31
+	public function via($notifiable)
32
+	{
33
+		return ['mail'];
34
+	}
35 35
 
36
-    /**
37
-     * Get the mail representation of the notification.
38
-     *
39
-     * @param  mixed  $notifiable
40
-     * @return \Illuminate\Notifications\Messages\MailMessage
41
-     */
42
-    public function toMail($notifiable)
43
-    {
44
-        return (new MailMessage)
45
-            ->subject('Email verification')
46
-            ->line('Email verification')
47
-            ->line('To validate your email click on the button below')
48
-            ->action('Verify your email', env('CONFIRM_EMAIL_URL') . '/' . $notifiable->confirmation_code));
49
-    }
36
+	/**
37
+	 * Get the mail representation of the notification.
38
+	 *
39
+	 * @param  mixed  $notifiable
40
+	 * @return \Illuminate\Notifications\Messages\MailMessage
41
+	 */
42
+	public function toMail($notifiable)
43
+	{
44
+		return (new MailMessage)
45
+			->subject('Email verification')
46
+			->line('Email verification')
47
+			->line('To validate your email click on the button below')
48
+			->action('Verify your email', env('CONFIRM_EMAIL_URL') . '/' . $notifiable->confirmation_code));
49
+	}
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,6 +45,6 @@
 block discarded – undo
45 45
             ->subject('Email verification')
46 46
             ->line('Email verification')
47 47
             ->line('To validate your email click on the button below')
48
-            ->action('Verify your email', env('CONFIRM_EMAIL_URL') . '/' . $notifiable->confirmation_code));
48
+            ->action('Verify your email', env('CONFIRM_EMAIL_URL').'/'.$notifiable->confirmation_code));
49 49
     }
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Repositories/SettingRepository.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 		return 'App\Modules\V1\Core\Settings';
15 15
 	}
16 16
 
17
-    /**
18
-     * Save list of settings.
19
-     *
20
-     * @param  array   $data
21
-     * @return void
22
-     */
23
-    public function saveMany(array $data)
24
-    {
25
-    	\DB::transaction(function () use ($data) {
26
-    		foreach ($data as $key => $value) 
27
-    		{
28
-    			$this->save($value);
29
-    		}
30
-    	});
31
-    }
17
+	/**
18
+	 * Save list of settings.
19
+	 *
20
+	 * @param  array   $data
21
+	 * @return void
22
+	 */
23
+	public function saveMany(array $data)
24
+	{
25
+		\DB::transaction(function () use ($data) {
26
+			foreach ($data as $key => $value) 
27
+			{
28
+				$this->save($value);
29
+			}
30
+		});
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
      */
23 23
     public function saveMany(array $data)
24 24
     {
25
-    	\DB::transaction(function () use ($data) {
25
+    	\DB::transaction(function() use ($data) {
26 26
     		foreach ($data as $key => $value) 
27 27
     		{
28 28
     			$this->save($value);
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/Media.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -2,67 +2,67 @@
 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
-       $response        = [];
15
-       $image           = $image;
16
-       $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
17
-       $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
+	   $response        = [];
15
+	   $image           = $image;
16
+	   $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
17
+	   $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
18 18
 
19
-       ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
20
-       $image->move($destinationPath, $imageName);
19
+	   ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
20
+	   $image->move($destinationPath, $imageName);
21 21
 
22
-       return url($destinationPath . $imageName);
23
-    }
22
+	   return url($destinationPath . $imageName);
23
+	}
24 24
 
25
-    /**
26
-     * Upload the given image.
27
-     * 
28
-     * @param  object  $image
29
-     * @param  string  $dir
30
-     * @return string
31
-     */
32
-    public function uploadImageBas64($image, $dir) 
33
-    {
34
-        if (! strlen($image)) 
35
-        {
36
-            return null;
37
-        }
25
+	/**
26
+	 * Upload the given image.
27
+	 * 
28
+	 * @param  object  $image
29
+	 * @param  string  $dir
30
+	 * @return string
31
+	 */
32
+	public function uploadImageBas64($image, $dir) 
33
+	{
34
+		if (! strlen($image)) 
35
+		{
36
+			return null;
37
+		}
38 38
         
39
-        $response        = [];
40
-        $image           = $image;
41
-        $imageName       = 'image' . uniqid() . time() . '.jpg';
42
-        $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
39
+		$response        = [];
40
+		$image           = $image;
41
+		$imageName       = 'image' . uniqid() . time() . '.jpg';
42
+		$destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
43 43
 
44
-        ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
44
+		! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
45 45
 
46
-        $base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
47
-        $image = \Image::make($base)->save($destinationPath . $imageName);
46
+		$base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
47
+		$image = \Image::make($base)->save($destinationPath . $imageName);
48 48
 
49
-        return url($destinationPath . $imageName);
50
-    }
49
+		return url($destinationPath . $imageName);
50
+	}
51 51
 
52
-    /**
53
-     * Delete the given image.
54
-     * 
55
-     * @param  object  $path
56
-     * @param  string  $dir
57
-     * @return void
58
-     */
59
-    public function deleteImage($path, $dir) 
60
-    {   
61
-        $arr      = explode('/', $path);
62
-        $path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
63
-        if (\File::exists($path)) 
64
-        {
65
-            \File::delete($path);
66
-        }
67
-    }
52
+	/**
53
+	 * Delete the given image.
54
+	 * 
55
+	 * @param  object  $path
56
+	 * @param  string  $dir
57
+	 * @return void
58
+	 */
59
+	public function deleteImage($path, $dir) 
60
+	{   
61
+		$arr      = explode('/', $path);
62
+		$path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
63
+		if (\File::exists($path)) 
64
+		{
65
+			\File::delete($path);
66
+		}
67
+	}
68 68
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
     {
14 14
        $response        = [];
15 15
        $image           = $image;
16
-       $imageName       =  str_slug('image' . uniqid() . time() . '_' . $image->getClientOriginalName());
17
-       $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
16
+       $imageName       = str_slug('image'.uniqid().time().'_'.$image->getClientOriginalName());
17
+       $destinationPath = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR;
18 18
 
19 19
        ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
20 20
        $image->move($destinationPath, $imageName);
21 21
 
22
-       return url($destinationPath . $imageName);
22
+       return url($destinationPath.$imageName);
23 23
     }
24 24
 
25 25
     /**
@@ -31,22 +31,22 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function uploadImageBas64($image, $dir) 
33 33
     {
34
-        if (! strlen($image)) 
34
+        if ( ! strlen($image)) 
35 35
         {
36 36
             return null;
37 37
         }
38 38
         
39 39
         $response        = [];
40 40
         $image           = $image;
41
-        $imageName       = 'image' . uniqid() . time() . '.jpg';
42
-        $destinationPath = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR;
41
+        $imageName       = 'image'.uniqid().time().'.jpg';
42
+        $destinationPath = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR;
43 43
 
44 44
         ! file_exists($destinationPath) ? \File::makeDirectory($destinationPath) : false;
45 45
 
46 46
         $base  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image));
47
-        $image = \Image::make($base)->save($destinationPath . $imageName);
47
+        $image = \Image::make($base)->save($destinationPath.$imageName);
48 48
 
49
-        return url($destinationPath . $imageName);
49
+        return url($destinationPath.$imageName);
50 50
     }
51 51
 
52 52
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     public function deleteImage($path, $dir) 
60 60
     {   
61 61
         $arr      = explode('/', $path);
62
-        $path     = 'media' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . end($arr);
62
+        $path     = 'media'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.end($arr);
63 63
         if (\File::exists($path)) 
64 64
         {
65 65
             \File::delete($path);
Please login to merge, or discard this patch.
src/Modules/V1/Core/Database/Seeds/SettingsTableSeeder.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -6,76 +6,76 @@
 block discarded – undo
6 6
 
7 7
 class SettingsTableSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-    	/**
17
-         * Insert the permissions related to settings table.
18
-         */
19
-        \DB::table('permissions')->insert(
20
-        	[
21
-        		/**
22
-        		 * Settings model permissions.
23
-        		 */
24
-	        	[
25
-	        	'name'       => 'save',
26
-	        	'model'      => 'settings',
27
-	        	'created_at' => \DB::raw('NOW()'),
28
-	        	'updated_at' => \DB::raw('NOW()')
29
-	        	],
30
-	        	[
31
-	        	'name'       => 'find',
32
-	        	'model'      => 'settings',
33
-	        	'created_at' => \DB::raw('NOW()'),
34
-	        	'updated_at' => \DB::raw('NOW()')
35
-	        	],
36
-	        	[
37
-	        	'name'       => 'search',
38
-	        	'model'      => 'settings',
39
-	        	'created_at' => \DB::raw('NOW()'),
40
-	        	'updated_at' => \DB::raw('NOW()')
41
-	        	],
42
-	        	[
43
-	        	'name'       => 'list',
44
-	        	'model'      => 'settings',
45
-	        	'created_at' => \DB::raw('NOW()'),
46
-	        	'updated_at' => \DB::raw('NOW()')
47
-	        	],
48
-	        	[
49
-	        	'name'       => 'findby',
50
-	        	'model'      => 'settings',
51
-	        	'created_at' => \DB::raw('NOW()'),
52
-	        	'updated_at' => \DB::raw('NOW()')
53
-	        	],
54
-	        	[
55
-	        	'name'       => 'first',
56
-	        	'model'      => 'settings',
57
-	        	'created_at' => \DB::raw('NOW()'),
58
-	        	'updated_at' => \DB::raw('NOW()')
59
-	        	],
60
-	        	[
61
-	        	'name'       => 'paginate',
62
-	        	'model'      => 'settings',
63
-	        	'created_at' => \DB::raw('NOW()'),
64
-	        	'updated_at' => \DB::raw('NOW()')
65
-	        	],
66
-	        	[
67
-	        	'name'       => 'paginateby',
68
-	        	'model'      => 'settings',
69
-	        	'created_at' => \DB::raw('NOW()'),
70
-	        	'updated_at' => \DB::raw('NOW()')
71
-	        	],
72
-	        	[
73
-	        	'name'       => 'saveMany',
74
-	        	'model'      => 'settings',
75
-	        	'created_at' => \DB::raw('NOW()'),
76
-	        	'updated_at' => \DB::raw('NOW()')
77
-	        	]
78
-        	]
79
-        );
80
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		/**
17
+		 * Insert the permissions related to settings table.
18
+		 */
19
+		\DB::table('permissions')->insert(
20
+			[
21
+				/**
22
+				 * Settings model permissions.
23
+				 */
24
+				[
25
+				'name'       => 'save',
26
+				'model'      => 'settings',
27
+				'created_at' => \DB::raw('NOW()'),
28
+				'updated_at' => \DB::raw('NOW()')
29
+				],
30
+				[
31
+				'name'       => 'find',
32
+				'model'      => 'settings',
33
+				'created_at' => \DB::raw('NOW()'),
34
+				'updated_at' => \DB::raw('NOW()')
35
+				],
36
+				[
37
+				'name'       => 'search',
38
+				'model'      => 'settings',
39
+				'created_at' => \DB::raw('NOW()'),
40
+				'updated_at' => \DB::raw('NOW()')
41
+				],
42
+				[
43
+				'name'       => 'list',
44
+				'model'      => 'settings',
45
+				'created_at' => \DB::raw('NOW()'),
46
+				'updated_at' => \DB::raw('NOW()')
47
+				],
48
+				[
49
+				'name'       => 'findby',
50
+				'model'      => 'settings',
51
+				'created_at' => \DB::raw('NOW()'),
52
+				'updated_at' => \DB::raw('NOW()')
53
+				],
54
+				[
55
+				'name'       => 'first',
56
+				'model'      => 'settings',
57
+				'created_at' => \DB::raw('NOW()'),
58
+				'updated_at' => \DB::raw('NOW()')
59
+				],
60
+				[
61
+				'name'       => 'paginate',
62
+				'model'      => 'settings',
63
+				'created_at' => \DB::raw('NOW()'),
64
+				'updated_at' => \DB::raw('NOW()')
65
+				],
66
+				[
67
+				'name'       => 'paginateby',
68
+				'model'      => 'settings',
69
+				'created_at' => \DB::raw('NOW()'),
70
+				'updated_at' => \DB::raw('NOW()')
71
+				],
72
+				[
73
+				'name'       => 'saveMany',
74
+				'model'      => 'settings',
75
+				'created_at' => \DB::raw('NOW()'),
76
+				'updated_at' => \DB::raw('NOW()')
77
+				]
78
+			]
79
+		);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Traits/Translatable.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -2,51 +2,51 @@
 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($key, $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($key, $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 $key
31
-     * @param $values
32
-     * @return string
33
-     */
34
-    protected function getTranslatedAttribute($key, $values)
35
-    {
36
-        $values         = json_decode($values);
37
-        $primaryLocale  = \Session::get('locale');
38
-        $fallbackLocale = 'en';
27
+	/**
28
+	 * Returns a translatable model attribute based on the application's locale settings.
29
+	 *
30
+	 * @param $key
31
+	 * @param $values
32
+	 * @return string
33
+	 */
34
+	protected function getTranslatedAttribute($key, $values)
35
+	{
36
+		$values         = json_decode($values);
37
+		$primaryLocale  = \Session::get('locale');
38
+		$fallbackLocale = 'en';
39 39
 
40
-        if ($primaryLocale == 'all') 
41
-        {
42
-            return $values;
43
-        }
40
+		if ($primaryLocale == 'all') 
41
+		{
42
+			return $values;
43
+		}
44 44
 
45
-        if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) 
46
-        {
47
-            return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
48
-        }
45
+		if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) 
46
+		{
47
+			return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : '';
48
+		}
49 49
 
50
-        return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
51
-    }
50
+		return $primaryLocale == 'all' ? $values : $values->$primaryLocale;
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.