Completed
Push — master ( de5c78...60eb24 )
by Sherif
09:23
created
Database/Migrations/2016_06_01_000004_create_oauth_auth_codes_table.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -6,33 +6,33 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthAuthCodesTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_auth_codes', function (Blueprint $table) {
17
-            $table->string('id', 100)->primary();
18
-            $table->unsignedInteger('user_id');
19
-            $table->unsignedInteger('client_id');
20
-            $table->text('scopes')->nullable();
21
-            $table->boolean('revoked');
22
-            $table->dateTime('expires_at')->nullable();
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_auth_codes', function (Blueprint $table) {
17
+			$table->string('id', 100)->primary();
18
+			$table->unsignedInteger('user_id');
19
+			$table->unsignedInteger('client_id');
20
+			$table->text('scopes')->nullable();
21
+			$table->boolean('revoked');
22
+			$table->dateTime('expires_at')->nullable();
23 23
 
24
-            $table->foreign('user_id')->references('id')->on('users');
25
-            $table->foreign('client_id')->references('id')->on('oauth_clients');
26
-        });
27
-    }
24
+			$table->foreign('user_id')->references('id')->on('users');
25
+			$table->foreign('client_id')->references('id')->on('oauth_clients');
26
+		});
27
+	}
28 28
 
29
-    /**
30
-     * Reverse the migrations.
31
-     *
32
-     * @return void
33
-     */
34
-    public function down()
35
-    {
36
-        Schema::drop('oauth_auth_codes');
37
-    }
29
+	/**
30
+	 * Reverse the migrations.
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public function down()
35
+	{
36
+		Schema::drop('oauth_auth_codes');
37
+	}
38 38
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_auth_codes', function (Blueprint $table) {
16
+        Schema::create('oauth_auth_codes', function(Blueprint $table) {
17 17
             $table->string('id', 100)->primary();
18 18
             $table->unsignedInteger('user_id');
19 19
             $table->unsignedInteger('client_id');
Please login to merge, or discard this patch.
Database/Migrations/2016_06_01_000002_create_oauth_access_tokens_table.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthAccessTokensTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_access_tokens', function (Blueprint $table) {
17
-            $table->string('id', 100)->primary();
18
-            $table->unsignedInteger('user_id')->nullable();
19
-            $table->unsignedInteger('client_id');
20
-            $table->string('name')->nullable();
21
-            $table->text('scopes')->nullable();
22
-            $table->boolean('revoked');
23
-            $table->timestamps();
24
-            $table->dateTime('expires_at')->nullable();
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_access_tokens', function (Blueprint $table) {
17
+			$table->string('id', 100)->primary();
18
+			$table->unsignedInteger('user_id')->nullable();
19
+			$table->unsignedInteger('client_id');
20
+			$table->string('name')->nullable();
21
+			$table->text('scopes')->nullable();
22
+			$table->boolean('revoked');
23
+			$table->timestamps();
24
+			$table->dateTime('expires_at')->nullable();
25 25
 
26
-            $table->foreign('user_id')->references('id')->on('users');
27
-            $table->foreign('client_id')->references('id')->on('oauth_clients');
28
-        });
29
-    }
26
+			$table->foreign('user_id')->references('id')->on('users');
27
+			$table->foreign('client_id')->references('id')->on('oauth_clients');
28
+		});
29
+	}
30 30
 
31
-    /**
32
-     * Reverse the migrations.
33
-     *
34
-     * @return void
35
-     */
36
-    public function down()
37
-    {
38
-        Schema::drop('oauth_access_tokens');
39
-    }
31
+	/**
32
+	 * Reverse the migrations.
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function down()
37
+	{
38
+		Schema::drop('oauth_access_tokens');
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_access_tokens', function (Blueprint $table) {
16
+        Schema::create('oauth_access_tokens', function(Blueprint $table) {
17 17
             $table->string('id', 100)->primary();
18 18
             $table->unsignedInteger('user_id')->nullable();
19 19
             $table->unsignedInteger('client_id');
Please login to merge, or discard this patch.
src/Modules/Roles/Services/RoleService.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
      *
22 22
      * @param  integer $roleId
23 23
      * @param  array   $permissionIds
24
-     * @return object
24
+     * @return boolean
25 25
      */
26 26
     public function assignPermissions($roleId, $permissionIds)
27 27
     {
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,33 +7,33 @@
 block discarded – undo
7 7
 
8 8
 class RoleService extends BaseService
9 9
 {
10
-    /**
11
-     * Init new object.
12
-     *
13
-     * @param   RoleRepository $repo
14
-     * @return  void
15
-     */
16
-    public function __construct(RoleRepository $repo)
17
-    {
18
-        parent::__construct($repo);
19
-    }
10
+	/**
11
+	 * Init new object.
12
+	 *
13
+	 * @param   RoleRepository $repo
14
+	 * @return  void
15
+	 */
16
+	public function __construct(RoleRepository $repo)
17
+	{
18
+		parent::__construct($repo);
19
+	}
20 20
 
21
-    /**
22
-     * Assign the given permission ids to the given role.
23
-     *
24
-     * @param  integer $roleId
25
-     * @param  array   $permissionIds
26
-     * @return object
27
-     */
28
-    public function assignPermissions($roleId, $permissionIds)
29
-    {
30
-        $role = false;
31
-        \DB::transaction(function () use ($roleId, $permissionIds, &$role) {
32
-            $role = $this->repo->find($roleId);
33
-            $this->repo->detachPermissions($role);
34
-            $this->repo->attachPermissions($role, $permissionIds);
35
-        });
21
+	/**
22
+	 * Assign the given permission ids to the given role.
23
+	 *
24
+	 * @param  integer $roleId
25
+	 * @param  array   $permissionIds
26
+	 * @return object
27
+	 */
28
+	public function assignPermissions($roleId, $permissionIds)
29
+	{
30
+		$role = false;
31
+		\DB::transaction(function () use ($roleId, $permissionIds, &$role) {
32
+			$role = $this->repo->find($roleId);
33
+			$this->repo->detachPermissions($role);
34
+			$this->repo->attachPermissions($role, $permissionIds);
35
+		});
36 36
 
37
-        return $role;
38
-    }
37
+		return $role;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
     public function assignPermissions($roleId, $permissionIds)
29 29
     {
30 30
         $role = false;
31
-        \DB::transaction(function () use ($roleId, $permissionIds, &$role) {
31
+        \DB::transaction(function() use ($roleId, $permissionIds, &$role) {
32 32
             $role = $this->repo->find($roleId);
33 33
             $this->repo->detachPermissions($role);
34 34
             $this->repo->attachPermissions($role, $permissionIds);
Please login to merge, or discard this patch.
src/Modules/Users/Services/UserService.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
      *
133 133
      * @param  integer $userId
134 134
      * @param  array   $roleIds
135
-     * @return object
135
+     * @return boolean
136 136
      */
137 137
     public function assignRoles($userId, $roleIds)
138 138
     {
Please login to merge, or discard this patch.
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -12,368 +12,368 @@
 block discarded – undo
12 12
 
13 13
 class UserService extends BaseService
14 14
 {
15
-    /**
16
-     * @var PermissionService
17
-     */
18
-    protected $permissionService;
19
-
20
-    /**
21
-     * @var LoginProxy
22
-     */
23
-    protected $loginProxy;
24
-
25
-    /**
26
-     * @var NotificationService
27
-     */
28
-    protected $notificationService;
29
-
30
-    /**
31
-     * @var OauthClientService
32
-     */
33
-    protected $oauthClientService;
34
-
35
-    /**
36
-     * Init new object.
37
-     *
38
-     * @param   UserRepository       $repo
39
-     * @param   PermissionService    $permissionService
40
-     * @param   LoginProxy           $loginProxy
41
-     * @param   NotificationService  $notificationService
42
-     * @param   OauthClientService   $oauthClientService
43
-     * @return  void
44
-     */
45
-    public function __construct(
46
-        UserRepository $repo,
47
-        PermissionService $permissionService,
48
-        LoginProxy $loginProxy,
49
-        NotificationService $notificationService,
50
-        OauthClientService $oauthClientService
51
-    ) {
52
-        $this->permissionService   = $permissionService;
53
-        $this->loginProxy          = $loginProxy;
54
-        $this->notificationService = $notificationService;
55
-        $this->oauthClientService  = $oauthClientService;
56
-        parent::__construct($repo);
57
-    }
58
-
59
-    /**
60
-     * Return the logged in user account.
61
-     *
62
-     * @param  array   $relations
63
-     * @return boolean
64
-     */
65
-    public function account($relations = ['roles.permissions'])
66
-    {
67
-        $permissions = [];
68
-        $user        = $this->repo->find(\Auth::id(), $relations);
69
-        foreach ($user->roles as $role) {
70
-            $role->permissions->each(function ($permission) use (&$permissions) {
71
-                $permissions[$permission->repo][$permission->id] = $permission->name;
72
-            });
73
-        }
74
-        $user->permissions = $permissions;
75
-
76
-        return $user;
77
-    }
78
-
79
-    /**
80
-     * Check if the logged in user or the given user
81
-     * has the given permissions on the given model.
82
-     *
83
-     * @param  string $permissionName
84
-     * @param  string $model
85
-     * @param  mixed  $userId
86
-     * @return boolean
87
-     */
88
-    public function can($permissionName, $model, $userId = false)
89
-    {
90
-        $permission = $this->permissionService->first([
91
-            'and' => [
92
-                'model' => $model,
93
-                'name'  => $permissionName,
94
-                'roles' => [
95
-                    'op' => 'has',
96
-                    'val' => [
97
-                        'users' => [
98
-                            'op' => 'has',
99
-                            'val' => [
100
-                                'users.id' => $userId ?: \Auth::id()
101
-                            ]
102
-                        ]
103
-                    ]
104
-                ]
105
-            ]
106
-        ]);
107
-
108
-        return $permission ? true : false;
109
-    }
110
-
111
-    /**
112
-     * Check if the logged in or the given user has the given role.
113
-     *
114
-     * @param  string[] $roles
115
-     * @param  mixed    $user
116
-     * @return boolean
117
-     */
118
-    public function hasRoles($roles, $user = false)
119
-    {
120
-        return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
121
-    }
122
-
123
-    /**
124
-     * Assign the given role ids to the given user.
125
-     *
126
-     * @param  integer $userId
127
-     * @param  array   $roleIds
128
-     * @return object
129
-     */
130
-    public function assignRoles($userId, $roleIds)
131
-    {
132
-        $user = false;
133
-        \DB::transaction(function () use ($userId, $roleIds, &$user) {
134
-            $user = $this->repo->find($userId);
135
-            $this->repo->detachRoles($user);
136
-            $this->repo->attachRoles($user, $roleIds);
137
-        });
138
-
139
-        return $user;
140
-    }
141
-
142
-    /**
143
-     * Handle the login request to the application.
144
-     *
145
-     * @param  string  $email
146
-     * @param  string  $password
147
-     * @return object
148
-     */
149
-    public function login($email, $password)
150
-    {
151
-        if (! $user = $this->repo->first(['email' => $email])) {
152
-            \Errors::loginFailed();
153
-        } elseif ($user->blocked) {
154
-            \Errors::userIsBlocked();
155
-        } elseif (! config('user.disable_confirm_email') && ! $user->confirmed) {
156
-            \Errors::emailNotConfirmed();
157
-        }
158
-
159
-        return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
160
-    }
161
-
162
-    /**
163
-     * Handle the social login request to the application.
164
-     *
165
-     * @param  string $authCode
166
-     * @param  string $accessToken
167
-     * @return array
168
-     */
169
-    public function loginSocial($authCode, $accessToken, $type)
170
-    {
171
-        $accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
172
-        $user        = \Socialite::driver($type)->userFromToken($accessToken)->user;
173
-
174
-        if (! \Arr::has($user, 'email')) {
175
-            \Errors::noSocialEmail();
176
-        }
177
-
178
-        if (! $this->repo->first(['email' => $user['email']])) {
179
-            $this->register($user['name'], $user['email'], '', true);
180
-        }
181
-
182
-        return $this->login($user['email'], config('user.social_pass'));
183
-    }
15
+	/**
16
+	 * @var PermissionService
17
+	 */
18
+	protected $permissionService;
19
+
20
+	/**
21
+	 * @var LoginProxy
22
+	 */
23
+	protected $loginProxy;
24
+
25
+	/**
26
+	 * @var NotificationService
27
+	 */
28
+	protected $notificationService;
29
+
30
+	/**
31
+	 * @var OauthClientService
32
+	 */
33
+	protected $oauthClientService;
34
+
35
+	/**
36
+	 * Init new object.
37
+	 *
38
+	 * @param   UserRepository       $repo
39
+	 * @param   PermissionService    $permissionService
40
+	 * @param   LoginProxy           $loginProxy
41
+	 * @param   NotificationService  $notificationService
42
+	 * @param   OauthClientService   $oauthClientService
43
+	 * @return  void
44
+	 */
45
+	public function __construct(
46
+		UserRepository $repo,
47
+		PermissionService $permissionService,
48
+		LoginProxy $loginProxy,
49
+		NotificationService $notificationService,
50
+		OauthClientService $oauthClientService
51
+	) {
52
+		$this->permissionService   = $permissionService;
53
+		$this->loginProxy          = $loginProxy;
54
+		$this->notificationService = $notificationService;
55
+		$this->oauthClientService  = $oauthClientService;
56
+		parent::__construct($repo);
57
+	}
58
+
59
+	/**
60
+	 * Return the logged in user account.
61
+	 *
62
+	 * @param  array   $relations
63
+	 * @return boolean
64
+	 */
65
+	public function account($relations = ['roles.permissions'])
66
+	{
67
+		$permissions = [];
68
+		$user        = $this->repo->find(\Auth::id(), $relations);
69
+		foreach ($user->roles as $role) {
70
+			$role->permissions->each(function ($permission) use (&$permissions) {
71
+				$permissions[$permission->repo][$permission->id] = $permission->name;
72
+			});
73
+		}
74
+		$user->permissions = $permissions;
75
+
76
+		return $user;
77
+	}
78
+
79
+	/**
80
+	 * Check if the logged in user or the given user
81
+	 * has the given permissions on the given model.
82
+	 *
83
+	 * @param  string $permissionName
84
+	 * @param  string $model
85
+	 * @param  mixed  $userId
86
+	 * @return boolean
87
+	 */
88
+	public function can($permissionName, $model, $userId = false)
89
+	{
90
+		$permission = $this->permissionService->first([
91
+			'and' => [
92
+				'model' => $model,
93
+				'name'  => $permissionName,
94
+				'roles' => [
95
+					'op' => 'has',
96
+					'val' => [
97
+						'users' => [
98
+							'op' => 'has',
99
+							'val' => [
100
+								'users.id' => $userId ?: \Auth::id()
101
+							]
102
+						]
103
+					]
104
+				]
105
+			]
106
+		]);
107
+
108
+		return $permission ? true : false;
109
+	}
110
+
111
+	/**
112
+	 * Check if the logged in or the given user has the given role.
113
+	 *
114
+	 * @param  string[] $roles
115
+	 * @param  mixed    $user
116
+	 * @return boolean
117
+	 */
118
+	public function hasRoles($roles, $user = false)
119
+	{
120
+		return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
121
+	}
122
+
123
+	/**
124
+	 * Assign the given role ids to the given user.
125
+	 *
126
+	 * @param  integer $userId
127
+	 * @param  array   $roleIds
128
+	 * @return object
129
+	 */
130
+	public function assignRoles($userId, $roleIds)
131
+	{
132
+		$user = false;
133
+		\DB::transaction(function () use ($userId, $roleIds, &$user) {
134
+			$user = $this->repo->find($userId);
135
+			$this->repo->detachRoles($user);
136
+			$this->repo->attachRoles($user, $roleIds);
137
+		});
138
+
139
+		return $user;
140
+	}
141
+
142
+	/**
143
+	 * Handle the login request to the application.
144
+	 *
145
+	 * @param  string  $email
146
+	 * @param  string  $password
147
+	 * @return object
148
+	 */
149
+	public function login($email, $password)
150
+	{
151
+		if (! $user = $this->repo->first(['email' => $email])) {
152
+			\Errors::loginFailed();
153
+		} elseif ($user->blocked) {
154
+			\Errors::userIsBlocked();
155
+		} elseif (! config('user.disable_confirm_email') && ! $user->confirmed) {
156
+			\Errors::emailNotConfirmed();
157
+		}
158
+
159
+		return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
160
+	}
161
+
162
+	/**
163
+	 * Handle the social login request to the application.
164
+	 *
165
+	 * @param  string $authCode
166
+	 * @param  string $accessToken
167
+	 * @return array
168
+	 */
169
+	public function loginSocial($authCode, $accessToken, $type)
170
+	{
171
+		$accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
172
+		$user        = \Socialite::driver($type)->userFromToken($accessToken)->user;
173
+
174
+		if (! \Arr::has($user, 'email')) {
175
+			\Errors::noSocialEmail();
176
+		}
177
+
178
+		if (! $this->repo->first(['email' => $user['email']])) {
179
+			$this->register($user['name'], $user['email'], '', true);
180
+		}
181
+
182
+		return $this->login($user['email'], config('user.social_pass'));
183
+	}
184 184
     
185
-    /**
186
-     * Handle the registration request.
187
-     *
188
-     * @param  string  $name
189
-     * @param  string  $email
190
-     * @param  string  $password
191
-     * @param  boolean $skipConfirmEmail
192
-     * @return array
193
-     */
194
-    public function register($name, $email, $password, $skipConfirmEmail = false)
195
-    {
196
-        $user = $this->repo->save([
197
-            'name'      => $name,
198
-            'email'     => $email,
199
-            'password'  => $password,
200
-            'confirmed' => $skipConfirmEmail
201
-        ]);
202
-
203
-        if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
204
-            $this->sendConfirmationEmail($user->email);
205
-        }
206
-
207
-        return $user;
208
-    }
185
+	/**
186
+	 * Handle the registration request.
187
+	 *
188
+	 * @param  string  $name
189
+	 * @param  string  $email
190
+	 * @param  string  $password
191
+	 * @param  boolean $skipConfirmEmail
192
+	 * @return array
193
+	 */
194
+	public function register($name, $email, $password, $skipConfirmEmail = false)
195
+	{
196
+		$user = $this->repo->save([
197
+			'name'      => $name,
198
+			'email'     => $email,
199
+			'password'  => $password,
200
+			'confirmed' => $skipConfirmEmail
201
+		]);
202
+
203
+		if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
204
+			$this->sendConfirmationEmail($user->email);
205
+		}
206
+
207
+		return $user;
208
+	}
209 209
     
210
-    /**
211
-     * Block the user.
212
-     *
213
-     * @param  integer $userId
214
-     * @return object
215
-     */
216
-    public function block($userId)
217
-    {
218
-        if (\Auth::id() == $userId) {
219
-            \Errors::noPermissions();
220
-        }
210
+	/**
211
+	 * Block the user.
212
+	 *
213
+	 * @param  integer $userId
214
+	 * @return object
215
+	 */
216
+	public function block($userId)
217
+	{
218
+		if (\Auth::id() == $userId) {
219
+			\Errors::noPermissions();
220
+		}
221 221
         
222
-        return $this->repo->save(['id' => $userId, 'blocked' => 1]);
223
-    }
224
-
225
-    /**
226
-     * Unblock the user.
227
-     *
228
-     * @param  integer $userId
229
-     * @return object
230
-     */
231
-    public function unblock($userId)
232
-    {
233
-        return $this->repo->save(['id' => $userId, 'blocked' => 0]);
234
-    }
235
-
236
-    /**
237
-     * Send a reset link to the given user.
238
-     *
239
-     * @param  string  $email
240
-     * @return void
241
-     */
242
-    public function sendReset($email)
243
-    {
244
-        if (! $user = $this->repo->first(['email' => $email])) {
245
-            \Errors::notFound('email');
246
-        }
247
-
248
-        $token = \Password::createToken($user);
249
-        $this->notificationService->notify($user, 'ResetPassword', $token);
250
-    }
251
-
252
-    /**
253
-     * Reset the given user's password.
254
-     *
255
-     * @param   string  $email
256
-     * @param   string  $password
257
-     * @param   string  $passwordConfirmation
258
-     * @param   string  $token
259
-     * @return string|void
260
-     */
261
-    public function resetPassword($email, $password, $passwordConfirmation, $token)
262
-    {
263
-        $response = \Password::reset([
264
-            'email'                 => $email,
265
-            'password'              => $password,
266
-            'password_confirmation' => $passwordConfirmation,
267
-            'token'                 => $token
268
-        ], function ($user, $password) {
269
-            $this->repo->save(['id' => $user->id, 'password' => $password]);
270
-        });
271
-
272
-        switch ($response) {
273
-            case \Password::PASSWORD_RESET:
274
-                return 'success';
275
-                break;
276
-
277
-            case \Password::INVALID_TOKEN:
278
-                \Errors::invalidResetToken();
279
-                break;
280
-
281
-            case \Password::INVALID_PASSWORD:
282
-                \Errors::invalidResetPassword();
283
-                break;
284
-
285
-            case \Password::INVALID_USER:
286
-                \Errors::notFound('user');
287
-                break;
288
-        }
289
-    }
290
-
291
-    /**
292
-     * Change the logged in user password.
293
-     *
294
-     * @param  string  $password
295
-     * @param  string  $oldPassword
296
-     * @return void
297
-     */
298
-    public function changePassword($password, $oldPassword)
299
-    {
300
-        $user = \Auth::user();
301
-        if (! \Hash::check($oldPassword, $user->password)) {
302
-            \Errors::invalidOldPassword();
303
-        }
304
-
305
-        $this->repo->save(['id' => $user->id, 'password' => $password]);
306
-    }
307
-
308
-    /**
309
-     * Confirm email using the confirmation code.
310
-     *
311
-     * @param  string $confirmationCode
312
-     * @return void
313
-     */
314
-    public function confirmEmail($confirmationCode)
315
-    {
316
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
317
-            \Errors::invalidConfirmationCode();
318
-        }
319
-
320
-        $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
321
-    }
322
-
323
-    /**
324
-     * Send the confirmation mail.
325
-     *
326
-     * @param  string $email
327
-     * @return void
328
-     */
329
-    public function sendConfirmationEmail($email)
330
-    {
331
-        $user = $this->repo->first(['email' => $email]);
332
-        if ($user->confirmed) {
333
-            \Errors::emailAlreadyConfirmed();
334
-        }
335
-
336
-        $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
337
-        $this->notificationService->notify($user, 'ConfirmEmail');
338
-    }
339
-
340
-    /**
341
-     * Save the given data to the logged in user.
342
-     *
343
-     * @param  string $name
344
-     * @param  string $email
345
-     * @param  string $profilePicture
346
-     * @return void
347
-     */
348
-    public function saveProfile($name, $email, $profilePicture = false)
349
-    {
350
-        $data['id'] = \Auth::id();
351
-        return $this->repo->save([
352
-            'id'             => \Auth::id(),
353
-            'name'           => $name,
354
-            'email'          => $email,
355
-            'profilePicture' => $profilePicture,
356
-        ]);
357
-    }
358
-
359
-    /**
360
-     * Logs out the user, revoke access token and refresh token.
361
-     *
362
-     * @return void
363
-     */
364
-    public function logout()
365
-    {
366
-        $this->oauthClientService->revokeAccessToken(\Auth::user()->token());
367
-    }
368
-
369
-    /**
370
-     * Attempt to refresh the access token using the given refresh token.
371
-     *
372
-     * @param  string $refreshToken
373
-     * @return array
374
-     */
375
-    public function refreshToken($refreshToken)
376
-    {
377
-        return $this->loginProxy->refreshToken($refreshToken);
378
-    }
222
+		return $this->repo->save(['id' => $userId, 'blocked' => 1]);
223
+	}
224
+
225
+	/**
226
+	 * Unblock the user.
227
+	 *
228
+	 * @param  integer $userId
229
+	 * @return object
230
+	 */
231
+	public function unblock($userId)
232
+	{
233
+		return $this->repo->save(['id' => $userId, 'blocked' => 0]);
234
+	}
235
+
236
+	/**
237
+	 * Send a reset link to the given user.
238
+	 *
239
+	 * @param  string  $email
240
+	 * @return void
241
+	 */
242
+	public function sendReset($email)
243
+	{
244
+		if (! $user = $this->repo->first(['email' => $email])) {
245
+			\Errors::notFound('email');
246
+		}
247
+
248
+		$token = \Password::createToken($user);
249
+		$this->notificationService->notify($user, 'ResetPassword', $token);
250
+	}
251
+
252
+	/**
253
+	 * Reset the given user's password.
254
+	 *
255
+	 * @param   string  $email
256
+	 * @param   string  $password
257
+	 * @param   string  $passwordConfirmation
258
+	 * @param   string  $token
259
+	 * @return string|void
260
+	 */
261
+	public function resetPassword($email, $password, $passwordConfirmation, $token)
262
+	{
263
+		$response = \Password::reset([
264
+			'email'                 => $email,
265
+			'password'              => $password,
266
+			'password_confirmation' => $passwordConfirmation,
267
+			'token'                 => $token
268
+		], function ($user, $password) {
269
+			$this->repo->save(['id' => $user->id, 'password' => $password]);
270
+		});
271
+
272
+		switch ($response) {
273
+			case \Password::PASSWORD_RESET:
274
+				return 'success';
275
+				break;
276
+
277
+			case \Password::INVALID_TOKEN:
278
+				\Errors::invalidResetToken();
279
+				break;
280
+
281
+			case \Password::INVALID_PASSWORD:
282
+				\Errors::invalidResetPassword();
283
+				break;
284
+
285
+			case \Password::INVALID_USER:
286
+				\Errors::notFound('user');
287
+				break;
288
+		}
289
+	}
290
+
291
+	/**
292
+	 * Change the logged in user password.
293
+	 *
294
+	 * @param  string  $password
295
+	 * @param  string  $oldPassword
296
+	 * @return void
297
+	 */
298
+	public function changePassword($password, $oldPassword)
299
+	{
300
+		$user = \Auth::user();
301
+		if (! \Hash::check($oldPassword, $user->password)) {
302
+			\Errors::invalidOldPassword();
303
+		}
304
+
305
+		$this->repo->save(['id' => $user->id, 'password' => $password]);
306
+	}
307
+
308
+	/**
309
+	 * Confirm email using the confirmation code.
310
+	 *
311
+	 * @param  string $confirmationCode
312
+	 * @return void
313
+	 */
314
+	public function confirmEmail($confirmationCode)
315
+	{
316
+		if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
317
+			\Errors::invalidConfirmationCode();
318
+		}
319
+
320
+		$this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
321
+	}
322
+
323
+	/**
324
+	 * Send the confirmation mail.
325
+	 *
326
+	 * @param  string $email
327
+	 * @return void
328
+	 */
329
+	public function sendConfirmationEmail($email)
330
+	{
331
+		$user = $this->repo->first(['email' => $email]);
332
+		if ($user->confirmed) {
333
+			\Errors::emailAlreadyConfirmed();
334
+		}
335
+
336
+		$this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
337
+		$this->notificationService->notify($user, 'ConfirmEmail');
338
+	}
339
+
340
+	/**
341
+	 * Save the given data to the logged in user.
342
+	 *
343
+	 * @param  string $name
344
+	 * @param  string $email
345
+	 * @param  string $profilePicture
346
+	 * @return void
347
+	 */
348
+	public function saveProfile($name, $email, $profilePicture = false)
349
+	{
350
+		$data['id'] = \Auth::id();
351
+		return $this->repo->save([
352
+			'id'             => \Auth::id(),
353
+			'name'           => $name,
354
+			'email'          => $email,
355
+			'profilePicture' => $profilePicture,
356
+		]);
357
+	}
358
+
359
+	/**
360
+	 * Logs out the user, revoke access token and refresh token.
361
+	 *
362
+	 * @return void
363
+	 */
364
+	public function logout()
365
+	{
366
+		$this->oauthClientService->revokeAccessToken(\Auth::user()->token());
367
+	}
368
+
369
+	/**
370
+	 * Attempt to refresh the access token using the given refresh token.
371
+	 *
372
+	 * @param  string $refreshToken
373
+	 * @return array
374
+	 */
375
+	public function refreshToken($refreshToken)
376
+	{
377
+		return $this->loginProxy->refreshToken($refreshToken);
378
+	}
379 379
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $permissions = [];
68 68
         $user        = $this->repo->find(\Auth::id(), $relations);
69 69
         foreach ($user->roles as $role) {
70
-            $role->permissions->each(function ($permission) use (&$permissions) {
70
+            $role->permissions->each(function($permission) use (&$permissions) {
71 71
                 $permissions[$permission->repo][$permission->id] = $permission->name;
72 72
             });
73 73
         }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     public function assignRoles($userId, $roleIds)
131 131
     {
132 132
         $user = false;
133
-        \DB::transaction(function () use ($userId, $roleIds, &$user) {
133
+        \DB::transaction(function() use ($userId, $roleIds, &$user) {
134 134
             $user = $this->repo->find($userId);
135 135
             $this->repo->detachRoles($user);
136 136
             $this->repo->attachRoles($user, $roleIds);
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function login($email, $password)
150 150
     {
151
-        if (! $user = $this->repo->first(['email' => $email])) {
151
+        if ( ! $user = $this->repo->first(['email' => $email])) {
152 152
             \Errors::loginFailed();
153 153
         } elseif ($user->blocked) {
154 154
             \Errors::userIsBlocked();
155
-        } elseif (! config('user.disable_confirm_email') && ! $user->confirmed) {
155
+        } elseif ( ! config('user.disable_confirm_email') && ! $user->confirmed) {
156 156
             \Errors::emailNotConfirmed();
157 157
         }
158 158
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
         $accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
172 172
         $user        = \Socialite::driver($type)->userFromToken($accessToken)->user;
173 173
 
174
-        if (! \Arr::has($user, 'email')) {
174
+        if ( ! \Arr::has($user, 'email')) {
175 175
             \Errors::noSocialEmail();
176 176
         }
177 177
 
178
-        if (! $this->repo->first(['email' => $user['email']])) {
178
+        if ( ! $this->repo->first(['email' => $user['email']])) {
179 179
             $this->register($user['name'], $user['email'], '', true);
180 180
         }
181 181
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             'confirmed' => $skipConfirmEmail
201 201
         ]);
202 202
 
203
-        if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
203
+        if ( ! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
204 204
             $this->sendConfirmationEmail($user->email);
205 205
         }
206 206
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public function sendReset($email)
243 243
     {
244
-        if (! $user = $this->repo->first(['email' => $email])) {
244
+        if ( ! $user = $this->repo->first(['email' => $email])) {
245 245
             \Errors::notFound('email');
246 246
         }
247 247
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
             'password'              => $password,
266 266
             'password_confirmation' => $passwordConfirmation,
267 267
             'token'                 => $token
268
-        ], function ($user, $password) {
268
+        ], function($user, $password) {
269 269
             $this->repo->save(['id' => $user->id, 'password' => $password]);
270 270
         });
271 271
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     public function changePassword($password, $oldPassword)
299 299
     {
300 300
         $user = \Auth::user();
301
-        if (! \Hash::check($oldPassword, $user->password)) {
301
+        if ( ! \Hash::check($oldPassword, $user->password)) {
302 302
             \Errors::invalidOldPassword();
303 303
         }
304 304
 
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      */
314 314
     public function confirmEmail($confirmationCode)
315 315
     {
316
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
316
+        if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
317 317
             \Errors::invalidConfirmationCode();
318 318
         }
319 319
 
Please login to merge, or discard this patch.
src/Modules/Users/Database/Seeds/AssignRelationsSeeder.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin role.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
22
-            \DB::table('permission_role')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'role_id'       => $adminRoleId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin role.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
22
+			\DB::table('permission_role')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'role_id'       => $adminRoleId,
26
+				'created_at'    => \DB::raw('NOW()'),
27
+				'updated_at'    => \DB::raw('NOW()')
28
+				]
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
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         /**
19 19
          * Assign the permissions to the admin role.
20 20
          */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
21
+        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function($permission) use ($adminRoleId) {
22 22
             \DB::table('permission_role')->insert(
23 23
                 [
24 24
                 'permission_id' => $permission->id,
Please login to merge, or discard this patch.
src/Modules/Users/Database/Seeds/ClearDataSeeder.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 
7 7
 class ClearDataSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $permissions = \DB::table('permissions')->whereIn('model', ['user']);
17
-        \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
-        $permissions->delete();
19
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$permissions = \DB::table('permissions')->whereIn('model', ['user']);
17
+		\DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.
PushNotificationDevices/Repositories/PushNotificationDeviceRepository.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@
 block discarded – undo
8 8
 
9 9
 class PushNotificationDeviceRepository extends BaseRepository
10 10
 {
11
-    /**
12
-     * Init new object.
13
-     *
14
-     * @param   PushNotificationDevice $model
15
-     * @return  void
16
-     */
17
-    public function __construct(PushNotificationDevice $model)
18
-    {
19
-        parent::__construct($model);
20
-    }
11
+	/**
12
+	 * Init new object.
13
+	 *
14
+	 * @param   PushNotificationDevice $model
15
+	 * @return  void
16
+	 */
17
+	public function __construct(PushNotificationDevice $model)
18
+	{
19
+		parent::__construct($model);
20
+	}
21 21
 }
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -3,9 +3,6 @@
 block discarded – undo
3 3
 namespace App\Modules\PushNotificationDevices\Repositories;
4 4
 
5 5
 use App\Modules\Core\BaseClasses\BaseRepository;
6
-use LaravelFCM\Message\OptionsBuilder;
7
-use LaravelFCM\Message\PayloadDataBuilder;
8
-use LaravelFCM\Message\PayloadNotificationBuilder;
9 6
 use App\Modules\PushNotificationDevices\PushNotificationDevice;
10 7
 
11 8
 class PushNotificationDeviceRepository extends BaseRepository
Please login to merge, or discard this patch.
Modules/PushNotificationDevices/Database/Seeds/AssignRelationsSeeder.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin role.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
22
-            \DB::table('permission_role')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'role_id'      => $adminRoleId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin role.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
22
+			\DB::table('permission_role')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'role_id'      => $adminRoleId,
26
+				'created_at'    => \DB::raw('NOW()'),
27
+				'updated_at'    => \DB::raw('NOW()')
28
+				]
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
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         /**
19 19
          * Assign the permissions to the admin role.
20 20
          */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
21
+        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function($permission) use ($adminRoleId) {
22 22
             \DB::table('permission_role')->insert(
23 23
                 [
24 24
                 'permission_id' => $permission->id,
Please login to merge, or discard this patch.
src/Modules/PushNotificationDevices/Database/Seeds/ClearDataSeeder.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 
7 7
 class ClearDataSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $permissions = \DB::table('permissions')->whereIn('model', ['pushNotificationDevice']);
17
-        \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
-        $permissions->delete();
19
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$permissions = \DB::table('permissions')->whereIn('model', ['pushNotificationDevice']);
17
+		\DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.