Completed
Push — master ( 91df31...876b8b )
by Sherif
01:12
created
src/Modules/Roles/Config/role.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Disable Confirm Email
8 8
     |--------------------------------------------------------------------------
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
     |
12 12
     */
13 13
 
14
-    'admin_email' => '[email protected]',
14
+	'admin_email' => '[email protected]',
15 15
 
16
-    /*
16
+	/*
17 17
     |--------------------------------------------------------------------------
18 18
     | Confirm Email URL
19 19
     |--------------------------------------------------------------------------
@@ -22,5 +22,5 @@  discard block
 block discarded – undo
22 22
     |
23 23
     */
24 24
    
25
-    'admin_password' => '123456',
25
+	'admin_password' => '123456',
26 26
 ];
Please login to merge, or discard this patch.
src/Modules/Roles/Providers/ModuleServiceProvider.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class ModuleServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Bootstrap the module services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'roles');
17
-        $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'roles');
9
+	/**
10
+	 * Bootstrap the module services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'roles');
17
+		$this->loadViewsFrom(__DIR__.'/../Resources/Views', 'roles');
18 18
 
19
-        $this->loadMigrationsFrom(module_path('roles', 'Database/Migrations', 'app'));
20
-        if (!$this->app->configurationIsCached()) {
21
-            $this->loadConfigsFrom(module_path('roles', 'Config', 'app'));
22
-        }
23
-    }
19
+		$this->loadMigrationsFrom(module_path('roles', 'Database/Migrations', 'app'));
20
+		if (!$this->app->configurationIsCached()) {
21
+			$this->loadConfigsFrom(module_path('roles', 'Config', 'app'));
22
+		}
23
+	}
24 24
 
25
-    /**
26
-     * Register the module services.
27
-     *
28
-     * @return void
29
-     */
30
-    public function register()
31
-    {
32
-        $this->app->register(RouteServiceProvider::class);
33
-    }
25
+	/**
26
+	 * Register the module services.
27
+	 *
28
+	 * @return void
29
+	 */
30
+	public function register()
31
+	{
32
+		$this->app->register(RouteServiceProvider::class);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
         $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'roles');
18 18
 
19 19
         $this->loadMigrationsFrom(module_path('roles', 'Database/Migrations', 'app'));
20
-        if (!$this->app->configurationIsCached()) {
20
+        if ( ! $this->app->configurationIsCached()) {
21 21
             $this->loadConfigsFrom(module_path('roles', 'Config', 'app'));
22 22
         }
23 23
     }
Please login to merge, or discard this patch.
src/Modules/Roles/Database/Seeds/RolesTableSeeder.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -9,98 +9,98 @@
 block discarded – undo
9 9
 
10 10
 class RolesTableSeeder extends Seeder
11 11
 {
12
-    /**
13
-     * Run the database seeds.
14
-     *
15
-     * @return void
16
-     */
17
-    public function run()
18
-    {      
19
-        /**
20
-         * Create Default roles.
21
-         */
22
-        Role::updateOrInsert([
23
-            'name' => RoleEnum::ADMIN,
24
-        ]);
12
+	/**
13
+	 * Run the database seeds.
14
+	 *
15
+	 * @return void
16
+	 */
17
+	public function run()
18
+	{      
19
+		/**
20
+		 * Create Default roles.
21
+		 */
22
+		Role::updateOrInsert([
23
+			'name' => RoleEnum::ADMIN,
24
+		]);
25 25
   
26
-        /**
27
-         * Create Default user.
28
-         */
29
-        AclUser::firstOrCreate([
30
-            'email' => config('role.admin_email'),
31
-        ],[
32
-            'name'       => 'Admin',
33
-            'password'   => config('role.admin_password'),
34
-            'confirmed'  => 1
35
-        ]);
26
+		/**
27
+		 * Create Default user.
28
+		 */
29
+		AclUser::firstOrCreate([
30
+			'email' => config('role.admin_email'),
31
+		],[
32
+			'name'       => 'Admin',
33
+			'password'   => config('role.admin_password'),
34
+			'confirmed'  => 1
35
+		]);
36 36
 
37
-        /**
38
-         * Assign default users to admin roles.
39
-         */
40
-        $adminRoleId = Role::where('name', RoleEnum::ADMIN)->select('id')->first()->id;;
41
-        $adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id;
42
-        \DB::table('role_user')->updateOrInsert([
43
-            'user_id' => $adminUserId,
44
-            'role_id' => $adminRoleId,
45
-        ],[]);
37
+		/**
38
+		 * Assign default users to admin roles.
39
+		 */
40
+		$adminRoleId = Role::where('name', RoleEnum::ADMIN)->select('id')->first()->id;;
41
+		$adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id;
42
+		\DB::table('role_user')->updateOrInsert([
43
+			'user_id' => $adminUserId,
44
+			'role_id' => $adminRoleId,
45
+		],[]);
46 46
 
47
-        /**
48
-         * Insert the permissions related to roles table.
49
-         */
50
-        \DB::table('permissions')->insert(
51
-            [
52
-                /**
53
-                 * Roles model permissions.
54
-                 */
55
-                [
56
-                'name'       => 'index',
57
-                'model'      => 'role',
58
-                'created_at' => \DB::raw('NOW()'),
59
-                'updated_at' => \DB::raw('NOW()')
60
-                ],
61
-                [
62
-                'name'       => 'show',
63
-                'model'      => 'role',
64
-                'created_at' => \DB::raw('NOW()'),
65
-                'updated_at' => \DB::raw('NOW()')
66
-                ],
67
-                [
68
-                'name'       => 'store',
69
-                'model'      => 'role',
70
-                'created_at' => \DB::raw('NOW()'),
71
-                'updated_at' => \DB::raw('NOW()')
72
-                ],
73
-                [
74
-                'name'       => 'update',
75
-                'model'      => 'role',
76
-                'created_at' => \DB::raw('NOW()'),
77
-                'updated_at' => \DB::raw('NOW()')
78
-                ],
79
-                [
80
-                'name'       => 'destroy',
81
-                'model'      => 'role',
82
-                'created_at' => \DB::raw('NOW()'),
83
-                'updated_at' => \DB::raw('NOW()')
84
-                ],
85
-                [
86
-                'name'       => 'deleted',
87
-                'model'      => 'role',
88
-                'created_at' => \DB::raw('NOW()'),
89
-                'updated_at' => \DB::raw('NOW()')
90
-                ],
91
-                [
92
-                'name'       => 'restore',
93
-                'model'      => 'role',
94
-                'created_at' => \DB::raw('NOW()'),
95
-                'updated_at' => \DB::raw('NOW()')
96
-                ],
97
-                [
98
-                'name'       => 'assignPermissions',
99
-                'model'      => 'role',
100
-                'created_at' => \DB::raw('NOW()'),
101
-                'updated_at' => \DB::raw('NOW()')
102
-                ],
103
-            ]
104
-        );
105
-    }
47
+		/**
48
+		 * Insert the permissions related to roles table.
49
+		 */
50
+		\DB::table('permissions')->insert(
51
+			[
52
+				/**
53
+				 * Roles model permissions.
54
+				 */
55
+				[
56
+				'name'       => 'index',
57
+				'model'      => 'role',
58
+				'created_at' => \DB::raw('NOW()'),
59
+				'updated_at' => \DB::raw('NOW()')
60
+				],
61
+				[
62
+				'name'       => 'show',
63
+				'model'      => 'role',
64
+				'created_at' => \DB::raw('NOW()'),
65
+				'updated_at' => \DB::raw('NOW()')
66
+				],
67
+				[
68
+				'name'       => 'store',
69
+				'model'      => 'role',
70
+				'created_at' => \DB::raw('NOW()'),
71
+				'updated_at' => \DB::raw('NOW()')
72
+				],
73
+				[
74
+				'name'       => 'update',
75
+				'model'      => 'role',
76
+				'created_at' => \DB::raw('NOW()'),
77
+				'updated_at' => \DB::raw('NOW()')
78
+				],
79
+				[
80
+				'name'       => 'destroy',
81
+				'model'      => 'role',
82
+				'created_at' => \DB::raw('NOW()'),
83
+				'updated_at' => \DB::raw('NOW()')
84
+				],
85
+				[
86
+				'name'       => 'deleted',
87
+				'model'      => 'role',
88
+				'created_at' => \DB::raw('NOW()'),
89
+				'updated_at' => \DB::raw('NOW()')
90
+				],
91
+				[
92
+				'name'       => 'restore',
93
+				'model'      => 'role',
94
+				'created_at' => \DB::raw('NOW()'),
95
+				'updated_at' => \DB::raw('NOW()')
96
+				],
97
+				[
98
+				'name'       => 'assignPermissions',
99
+				'model'      => 'role',
100
+				'created_at' => \DB::raw('NOW()'),
101
+				'updated_at' => \DB::raw('NOW()')
102
+				],
103
+			]
104
+		);
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
          */
29 29
         AclUser::firstOrCreate([
30 30
             'email' => config('role.admin_email'),
31
-        ],[
31
+        ], [
32 32
             'name'       => 'Admin',
33 33
             'password'   => config('role.admin_password'),
34 34
             'confirmed'  => 1
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
         /**
38 38
          * Assign default users to admin roles.
39 39
          */
40
-        $adminRoleId = Role::where('name', RoleEnum::ADMIN)->select('id')->first()->id;;
40
+        $adminRoleId = Role::where('name', RoleEnum::ADMIN)->select('id')->first()->id; ;
41 41
         $adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id;
42 42
         \DB::table('role_user')->updateOrInsert([
43 43
             'user_id' => $adminUserId,
44 44
             'role_id' => $adminRoleId,
45
-        ],[]);
45
+        ], []);
46 46
 
47 47
         /**
48 48
          * Insert the permissions related to roles table.
Please login to merge, or discard this patch.
src/Modules/Roles/Database/Factories/RoleFactory.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
 
8 8
 class RoleFactory extends Factory
9 9
 {
10
-    /**
11
-     * The name of the factory's corresponding model.
12
-     *
13
-     * @var string
14
-     */
15
-    protected $model = Role::class;
10
+	/**
11
+	 * The name of the factory's corresponding model.
12
+	 *
13
+	 * @var string
14
+	 */
15
+	protected $model = Role::class;
16 16
 
17
-    /**
18
-     * Define the model's default state.
19
-     *
20
-     * @return array
21
-     */
22
-    public function definition()
23
-    {
24
-        return [
25
-            'name'       => $this->faker->unique->word(),
26
-            'created_at' => $this->faker->dateTimeBetween('-1 years', 'now'),
27
-            'updated_at' => $this->faker->dateTimeBetween('-1 years', 'now')
28
-        ];
29
-    }
17
+	/**
18
+	 * Define the model's default state.
19
+	 *
20
+	 * @return array
21
+	 */
22
+	public function definition()
23
+	{
24
+		return [
25
+			'name'       => $this->faker->unique->word(),
26
+			'created_at' => $this->faker->dateTimeBetween('-1 years', 'now'),
27
+			'updated_at' => $this->faker->dateTimeBetween('-1 years', 'now')
28
+		];
29
+	}
30 30
 }
Please login to merge, or discard this patch.
src/Modules/Users/Providers/ModuleServiceProvider.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class ModuleServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Bootstrap the module services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'users');
17
-        $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'users');
9
+	/**
10
+	 * Bootstrap the module services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'users');
17
+		$this->loadViewsFrom(__DIR__.'/../Resources/Views', 'users');
18 18
 
19
-        $this->loadMigrationsFrom(module_path('users', 'Database/Migrations', 'app'));
20
-        if (!$this->app->configurationIsCached()) {
21
-            $this->loadConfigsFrom(module_path('users', 'Config', 'app'));
22
-        }
23
-    }
19
+		$this->loadMigrationsFrom(module_path('users', 'Database/Migrations', 'app'));
20
+		if (!$this->app->configurationIsCached()) {
21
+			$this->loadConfigsFrom(module_path('users', 'Config', 'app'));
22
+		}
23
+	}
24 24
 
25
-    /**
26
-     * Register the module services.
27
-     *
28
-     * @return void
29
-     */
30
-    public function register()
31
-    {
32
-        $this->app->register(RouteServiceProvider::class);
33
-    }
25
+	/**
26
+	 * Register the module services.
27
+	 *
28
+	 * @return void
29
+	 */
30
+	public function register()
31
+	{
32
+		$this->app->register(RouteServiceProvider::class);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
         $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'users');
18 18
 
19 19
         $this->loadMigrationsFrom(module_path('users', 'Database/Migrations', 'app'));
20
-        if (!$this->app->configurationIsCached()) {
20
+        if ( ! $this->app->configurationIsCached()) {
21 21
             $this->loadConfigsFrom(module_path('users', 'Config', 'app'));
22 22
         }
23 23
     }
Please login to merge, or discard this patch.
src/Modules/Users/Http/Resources/AclUser.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -10,35 +10,35 @@
 block discarded – undo
10 10
 
11 11
 class AclUser extends JsonResource
12 12
 {
13
-    /**
14
-     * Transform the resource into an array.
15
-     *
16
-     * @param Request $request
17
-     * @return array
18
-     */
19
-    public function toArray($request)
20
-    {
21
-        if (! $this->resource) {
22
-            return [];
23
-        }
13
+	/**
14
+	 * Transform the resource into an array.
15
+	 *
16
+	 * @param Request $request
17
+	 * @return array
18
+	 */
19
+	public function toArray($request)
20
+	{
21
+		if (! $this->resource) {
22
+			return [];
23
+		}
24 24
 
25
-        return [
26
-            'id' => $this->id,
27
-            'name' => $this->name,
28
-            'email' => $this->email,
29
-            'profilePicture' => $this->profile_picture ? url(\Storage::url($this->profile_picture)) : null,
30
-            'notifications' => NotificationResource::collection($this->whenLoaded('notifications')),
31
-            'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')),
32
-            'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')),
33
-            'roles' => RoleResource::collection($this->whenLoaded('roles')),
34
-            'permissions' => $this->when($this->permissions, function () {
35
-                return PermissionResource::collection($this->permissions);
36
-            }),
37
-            'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')),
38
-            'locale' => $this->locale,
39
-            'timezone' => $this->timezone,
40
-            'created_at' => $this->created_at,
41
-            'updated_at' => $this->updated_at,
42
-        ];
43
-    }
25
+		return [
26
+			'id' => $this->id,
27
+			'name' => $this->name,
28
+			'email' => $this->email,
29
+			'profilePicture' => $this->profile_picture ? url(\Storage::url($this->profile_picture)) : null,
30
+			'notifications' => NotificationResource::collection($this->whenLoaded('notifications')),
31
+			'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')),
32
+			'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')),
33
+			'roles' => RoleResource::collection($this->whenLoaded('roles')),
34
+			'permissions' => $this->when($this->permissions, function () {
35
+				return PermissionResource::collection($this->permissions);
36
+			}),
37
+			'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')),
38
+			'locale' => $this->locale,
39
+			'timezone' => $this->timezone,
40
+			'created_at' => $this->created_at,
41
+			'updated_at' => $this->updated_at,
42
+		];
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      */
19 19
     public function toArray($request)
20 20
     {
21
-        if (! $this->resource) {
21
+        if ( ! $this->resource) {
22 22
             return [];
23 23
         }
24 24
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
             'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')),
32 32
             'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')),
33 33
             'roles' => RoleResource::collection($this->whenLoaded('roles')),
34
-            'permissions' => $this->when($this->permissions, function () {
34
+            'permissions' => $this->when($this->permissions, function() {
35 35
                 return PermissionResource::collection($this->permissions);
36 36
             }),
37 37
             'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')),
Please login to merge, or discard this patch.
src/Modules/Users/Http/Requests/LoginSocial.php 1 patch
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 LoginSocial extends FormRequest
8 8
 {
9
-    /**
10
-     * Determine if the user is authorized to make this request.
11
-     *
12
-     * @return bool
13
-     */
14
-    public function authorize()
15
-    {
16
-        return true;
17
-    }
9
+	/**
10
+	 * Determine if the user is authorized to make this request.
11
+	 *
12
+	 * @return bool
13
+	 */
14
+	public function authorize()
15
+	{
16
+		return true;
17
+	}
18 18
 
19
-    /**
20
-     * Get the validation rules that apply to the request.
21
-     *
22
-     * @return array
23
-     */
24
-    public function rules()
25
-    {
26
-        return [
27
-            'auth_code'    => 'required_without:access_token',
28
-            'access_token' => 'required_without:auth_code',
29
-            'type'         => 'required|in:facebook,google,apple'
30
-        ];
31
-    }
19
+	/**
20
+	 * Get the validation rules that apply to the request.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function rules()
25
+	{
26
+		return [
27
+			'auth_code'    => 'required_without:access_token',
28
+			'access_token' => 'required_without:auth_code',
29
+			'type'         => 'required|in:facebook,google,apple'
30
+		];
31
+	}
32 32
 }
Please login to merge, or discard this patch.
src/Modules/Users/Http/Controllers/UserController.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -20,233 +20,233 @@
 block discarded – undo
20 20
 
21 21
 class UserController extends BaseApiController
22 22
 {
23
-    /**
24
-     * Path of the sotre form request.
25
-     *
26
-     * @var string
27
-     */
28
-    protected $storeFormRequest = 'App\Modules\Users\Http\Requests\StoreUser';
29
-
30
-    /**
31
-     * Path of the model resource.
32
-     *
33
-     * @var string
34
-     */
35
-    protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser';
36
-
37
-    /**
38
-     * List of all route actions that the base api controller
39
-     * will skip permissions check for them.
40
-     * @var array
41
-     */
42
-    protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile'];
43
-
44
-    /**
45
-     * List of all route actions that the base api controller
46
-     * will skip login check for them.
47
-     * @var array
48
-     */
49
-    protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
50
-
51
-    /**
52
-     * Init new object.
53
-     *
54
-     * @param   UserService $service
55
-     * @return  void
56
-     */
57
-    public function __construct(UserService $service)
58
-    {
59
-        parent::__construct($service);
60
-    }
61
-
62
-    /**
63
-     * Return the logged in user account.
64
-     *
65
-     * @param Request $request
66
-     * @return \Illuminate\Http\Response
67
-     */
68
-    public function account(Request $request)
69
-    {
70
-        return new $this->modelResource($this->service->account($request->relations));
71
-    }
72
-
73
-    /**
74
-     * Block the user.
75
-     *
76
-     * @param  integer  $id Id of the user.
77
-     * @return \Illuminate\Http\Response
78
-     */
79
-    public function block($id)
80
-    {
81
-        return new $this->modelResource($this->service->block($id));
82
-    }
83
-
84
-    /**
85
-     * Unblock the user.
86
-     *
87
-     * @param  integer  $id Id of the user.
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function unblock($id)
91
-    {
92
-        return new $this->modelResource($this->service->unblock($id));
93
-    }
94
-
95
-    /**
96
-     * Logout the user.
97
-     *
98
-     * @return \Illuminate\Http\Response
99
-     */
100
-    public function logout()
101
-    {
102
-        return new GeneralResource($this->service->logout());
103
-    }
104
-
105
-    /**
106
-     * Handle the registration request.
107
-     *
108
-     * @param Register $request
109
-     * @return \Illuminate\Http\Response
110
-     */
111
-    public function register(Register $request)
112
-    {
113
-        return new $this->modelResource($this->service->register($request->validated()));
114
-    }
115
-
116
-    /**
117
-     * Handle the login request to the application.
118
-     *
119
-     * @param Login $request
120
-     * @return \Illuminate\Http\Response
121
-     */
122
-    public function login(Login $request)
123
-    {
124
-        $result = $this->service->login($request->get('email'), $request->get('password'));
125
-
126
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
127
-    }
128
-
129
-    /**
130
-     * Handle the social login request the application.
131
-     *
132
-     * @param LoginSocial $request
133
-     * @return \Illuminate\Http\Response
134
-     */
135
-    public function loginSocial(LoginSocial $request)
136
-    {
137
-        $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
138
-
139
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
140
-    }
141
-
142
-    /**
143
-     * Assign the given roles to the given user.
144
-     *
145
-     * @param AssignRoles $request
146
-     * @param integer     $id
147
-     * @return \Illuminate\Http\Response
148
-     */
149
-    public function assignRoles(AssignRoles $request, $id)
150
-    {
151
-        return new $this->modelResource($this->service->assignRoles($id, $request->get('role_ids')));
152
-    }
153
-
154
-    /**
155
-     * Send a reset link to the given user.
156
-     *
157
-     * @param SendReset $request
158
-     * @return \Illuminate\Http\Response
159
-     */
160
-    public function sendReset(SendReset $request)
161
-    {
162
-        return new GeneralResource($this->service->sendReset($request->get('email')));
163
-    }
164
-
165
-    /**
166
-     * Reset the given user's password.
167
-     *
168
-     * @param ResetPassword $request
169
-     * @return \Illuminate\Http\Response
170
-     */
171
-    public function resetPassword(ResetPassword $request)
172
-    {
173
-        return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token')));
174
-    }
175
-
176
-    /**
177
-     * Render reset password page.
178
-     *
179
-     * @param string $resetToken
180
-     * @return \Illuminate\Http\Response
181
-     */
182
-    public function resetPasswordPage($resetToken)
183
-    {
184
-        return view('users::reset_password', ['reset_token' => $resetToken]);
185
-    }
186
-
187
-    /**
188
-     * Change the logged in user password.
189
-     *
190
-     * @param ChangePassword $request
191
-     * @return \Illuminate\Http\Response
192
-     */
193
-    public function changePassword(ChangePassword $request)
194
-    {
195
-        return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password')));
196
-    }
197
-
198
-    /**
199
-     * Confirm email using the confirmation code.
200
-     *
201
-     * @param ConfirmEmail $request
202
-     * @return \Illuminate\Http\Response
203
-     */
204
-    public function confirmEmail(ConfirmEmail $request)
205
-    {
206
-        return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code')));
207
-    }
208
-
209
-    /**
210
-     * Render confirm email page using the confirmation code.
211
-     *
212
-     * @param string $confirmationToken
213
-     * @return \Illuminate\Http\Response
214
-     */
215
-    public function confirmEmailPage($confirmationToken)
216
-    {
217
-        return view('users::confirm_email', ['confirmation_token' => $confirmationToken]);
218
-    }
219
-
220
-    /**
221
-     * Resend the email confirmation mail.
222
-     *
223
-     * @param ResendEmailConfirmation $request
224
-     * @return \Illuminate\Http\Response
225
-     */
226
-    public function resendEmailConfirmation(ResendEmailConfirmation $request)
227
-    {
228
-        return new GeneralResource($this->service->sendConfirmationEmail($request->get('email')));
229
-    }
230
-
231
-    /**
232
-     * Refresh the expired login token.
233
-     *
234
-     * @param RefreshToken $request
235
-     * @return \Illuminate\Http\Response
236
-     */
237
-    public function refreshToken(RefreshToken $request)
238
-    {
239
-        return new GeneralResource($this->service->refreshToken($request->get('refresh_token')));
240
-    }
241
-
242
-    /**
243
-     * Save the given data to the logged in user.
244
-     *
245
-     * @param SaveProfile $request
246
-     * @return \Illuminate\Http\Response
247
-     */
248
-    public function saveProfile(SaveProfile $request)
249
-    {
250
-        return new $this->modelResource($this->service->saveProfile($request->validated()));
251
-    }
23
+	/**
24
+	 * Path of the sotre form request.
25
+	 *
26
+	 * @var string
27
+	 */
28
+	protected $storeFormRequest = 'App\Modules\Users\Http\Requests\StoreUser';
29
+
30
+	/**
31
+	 * Path of the model resource.
32
+	 *
33
+	 * @var string
34
+	 */
35
+	protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser';
36
+
37
+	/**
38
+	 * List of all route actions that the base api controller
39
+	 * will skip permissions check for them.
40
+	 * @var array
41
+	 */
42
+	protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile'];
43
+
44
+	/**
45
+	 * List of all route actions that the base api controller
46
+	 * will skip login check for them.
47
+	 * @var array
48
+	 */
49
+	protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
50
+
51
+	/**
52
+	 * Init new object.
53
+	 *
54
+	 * @param   UserService $service
55
+	 * @return  void
56
+	 */
57
+	public function __construct(UserService $service)
58
+	{
59
+		parent::__construct($service);
60
+	}
61
+
62
+	/**
63
+	 * Return the logged in user account.
64
+	 *
65
+	 * @param Request $request
66
+	 * @return \Illuminate\Http\Response
67
+	 */
68
+	public function account(Request $request)
69
+	{
70
+		return new $this->modelResource($this->service->account($request->relations));
71
+	}
72
+
73
+	/**
74
+	 * Block the user.
75
+	 *
76
+	 * @param  integer  $id Id of the user.
77
+	 * @return \Illuminate\Http\Response
78
+	 */
79
+	public function block($id)
80
+	{
81
+		return new $this->modelResource($this->service->block($id));
82
+	}
83
+
84
+	/**
85
+	 * Unblock the user.
86
+	 *
87
+	 * @param  integer  $id Id of the user.
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function unblock($id)
91
+	{
92
+		return new $this->modelResource($this->service->unblock($id));
93
+	}
94
+
95
+	/**
96
+	 * Logout the user.
97
+	 *
98
+	 * @return \Illuminate\Http\Response
99
+	 */
100
+	public function logout()
101
+	{
102
+		return new GeneralResource($this->service->logout());
103
+	}
104
+
105
+	/**
106
+	 * Handle the registration request.
107
+	 *
108
+	 * @param Register $request
109
+	 * @return \Illuminate\Http\Response
110
+	 */
111
+	public function register(Register $request)
112
+	{
113
+		return new $this->modelResource($this->service->register($request->validated()));
114
+	}
115
+
116
+	/**
117
+	 * Handle the login request to the application.
118
+	 *
119
+	 * @param Login $request
120
+	 * @return \Illuminate\Http\Response
121
+	 */
122
+	public function login(Login $request)
123
+	{
124
+		$result = $this->service->login($request->get('email'), $request->get('password'));
125
+
126
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
127
+	}
128
+
129
+	/**
130
+	 * Handle the social login request the application.
131
+	 *
132
+	 * @param LoginSocial $request
133
+	 * @return \Illuminate\Http\Response
134
+	 */
135
+	public function loginSocial(LoginSocial $request)
136
+	{
137
+		$result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
138
+
139
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
140
+	}
141
+
142
+	/**
143
+	 * Assign the given roles to the given user.
144
+	 *
145
+	 * @param AssignRoles $request
146
+	 * @param integer     $id
147
+	 * @return \Illuminate\Http\Response
148
+	 */
149
+	public function assignRoles(AssignRoles $request, $id)
150
+	{
151
+		return new $this->modelResource($this->service->assignRoles($id, $request->get('role_ids')));
152
+	}
153
+
154
+	/**
155
+	 * Send a reset link to the given user.
156
+	 *
157
+	 * @param SendReset $request
158
+	 * @return \Illuminate\Http\Response
159
+	 */
160
+	public function sendReset(SendReset $request)
161
+	{
162
+		return new GeneralResource($this->service->sendReset($request->get('email')));
163
+	}
164
+
165
+	/**
166
+	 * Reset the given user's password.
167
+	 *
168
+	 * @param ResetPassword $request
169
+	 * @return \Illuminate\Http\Response
170
+	 */
171
+	public function resetPassword(ResetPassword $request)
172
+	{
173
+		return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token')));
174
+	}
175
+
176
+	/**
177
+	 * Render reset password page.
178
+	 *
179
+	 * @param string $resetToken
180
+	 * @return \Illuminate\Http\Response
181
+	 */
182
+	public function resetPasswordPage($resetToken)
183
+	{
184
+		return view('users::reset_password', ['reset_token' => $resetToken]);
185
+	}
186
+
187
+	/**
188
+	 * Change the logged in user password.
189
+	 *
190
+	 * @param ChangePassword $request
191
+	 * @return \Illuminate\Http\Response
192
+	 */
193
+	public function changePassword(ChangePassword $request)
194
+	{
195
+		return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password')));
196
+	}
197
+
198
+	/**
199
+	 * Confirm email using the confirmation code.
200
+	 *
201
+	 * @param ConfirmEmail $request
202
+	 * @return \Illuminate\Http\Response
203
+	 */
204
+	public function confirmEmail(ConfirmEmail $request)
205
+	{
206
+		return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code')));
207
+	}
208
+
209
+	/**
210
+	 * Render confirm email page using the confirmation code.
211
+	 *
212
+	 * @param string $confirmationToken
213
+	 * @return \Illuminate\Http\Response
214
+	 */
215
+	public function confirmEmailPage($confirmationToken)
216
+	{
217
+		return view('users::confirm_email', ['confirmation_token' => $confirmationToken]);
218
+	}
219
+
220
+	/**
221
+	 * Resend the email confirmation mail.
222
+	 *
223
+	 * @param ResendEmailConfirmation $request
224
+	 * @return \Illuminate\Http\Response
225
+	 */
226
+	public function resendEmailConfirmation(ResendEmailConfirmation $request)
227
+	{
228
+		return new GeneralResource($this->service->sendConfirmationEmail($request->get('email')));
229
+	}
230
+
231
+	/**
232
+	 * Refresh the expired login token.
233
+	 *
234
+	 * @param RefreshToken $request
235
+	 * @return \Illuminate\Http\Response
236
+	 */
237
+	public function refreshToken(RefreshToken $request)
238
+	{
239
+		return new GeneralResource($this->service->refreshToken($request->get('refresh_token')));
240
+	}
241
+
242
+	/**
243
+	 * Save the given data to the logged in user.
244
+	 *
245
+	 * @param SaveProfile $request
246
+	 * @return \Illuminate\Http\Response
247
+	 */
248
+	public function saveProfile(SaveProfile $request)
249
+	{
250
+		return new $this->modelResource($this->service->saveProfile($request->validated()));
251
+	}
252 252
 }
Please login to merge, or discard this patch.
src/Modules/Users/Services/UserService.php 2 patches
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -12,360 +12,360 @@
 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;
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']]) && ! $this->repo->deleted(['email' => $user['email']])->count()) {
179
-            $this->register(Arr::get($user, 'name'), $user['email'], '', true);
180
-        }
181
-
182
-        return $this->login($user['email'], config('user.social_pass'));
183
-    }
184
-    /**
185
-     * Handle the registration request.
186
-     *
187
-     * @param  array   $data
188
-     * @param  boolean $skipConfirmEmail
189
-     * @param  integer $roleId
190
-     * @return object
191
-     */
192
-    public function register($data, $skipConfirmEmail = false, $roleId = false)
193
-    {
194
-        $data['confirmed'] = $skipConfirmEmail;
195
-
196
-        if($roleId){
197
-            $data ['roles'] = [['id' => $roleId]];
198
-        }
199
-
200
-        $user = $this->repo->save($data);
201
-
202
-        if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
203
-            $this->sendConfirmationEmail($user->email);
204
-        }
205
-
206
-        return $user;
207
-    }
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;
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']]) && ! $this->repo->deleted(['email' => $user['email']])->count()) {
179
+			$this->register(Arr::get($user, 'name'), $user['email'], '', true);
180
+		}
181
+
182
+		return $this->login($user['email'], config('user.social_pass'));
183
+	}
184
+	/**
185
+	 * Handle the registration request.
186
+	 *
187
+	 * @param  array   $data
188
+	 * @param  boolean $skipConfirmEmail
189
+	 * @param  integer $roleId
190
+	 * @return object
191
+	 */
192
+	public function register($data, $skipConfirmEmail = false, $roleId = false)
193
+	{
194
+		$data['confirmed'] = $skipConfirmEmail;
195
+
196
+		if($roleId){
197
+			$data ['roles'] = [['id' => $roleId]];
198
+		}
199
+
200
+		$user = $this->repo->save($data);
201
+
202
+		if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
203
+			$this->sendConfirmationEmail($user->email);
204
+		}
205
+
206
+		return $user;
207
+	}
208 208
     
209
-    /**
210
-     * Block the user.
211
-     *
212
-     * @param  integer $userId
213
-     * @return object
214
-     */
215
-    public function block($userId)
216
-    {
217
-        if (\Auth::id() == $userId) {
218
-            \Errors::noPermissions();
219
-        }
209
+	/**
210
+	 * Block the user.
211
+	 *
212
+	 * @param  integer $userId
213
+	 * @return object
214
+	 */
215
+	public function block($userId)
216
+	{
217
+		if (\Auth::id() == $userId) {
218
+			\Errors::noPermissions();
219
+		}
220 220
         
221
-        return $this->repo->save(['id' => $userId, 'blocked' => 1]);
222
-    }
223
-
224
-    /**
225
-     * Unblock the user.
226
-     *
227
-     * @param  integer $userId
228
-     * @return object
229
-     */
230
-    public function unblock($userId)
231
-    {
232
-        return $this->repo->save(['id' => $userId, 'blocked' => 0]);
233
-    }
234
-
235
-    /**
236
-     * Send a reset link to the given user.
237
-     *
238
-     * @param  string  $email
239
-     * @return void
240
-     */
241
-    public function sendReset($email)
242
-    {
243
-        if (! $user = $this->repo->first(['email' => $email])) {
244
-            \Errors::notFound('email');
245
-        }
246
-
247
-        $token = \Password::createToken($user);
248
-        $this->notificationService->notify($user, 'ResetPassword', $token);
249
-    }
250
-
251
-    /**
252
-     * Reset the given user's password.
253
-     *
254
-     * @param   string  $email
255
-     * @param   string  $password
256
-     * @param   string  $passwordConfirmation
257
-     * @param   string  $token
258
-     * @return string|void
259
-     */
260
-    public function resetPassword($email, $password, $passwordConfirmation, $token)
261
-    {
262
-        $response = \Password::reset([
263
-            'email'                 => $email,
264
-            'password'              => $password,
265
-            'password_confirmation' => $passwordConfirmation,
266
-            'token'                 => $token
267
-        ], function ($user, $password) {
268
-            $this->repo->save(['id' => $user->id, 'password' => $password]);
269
-        });
270
-
271
-        switch ($response) {
272
-            case \Password::PASSWORD_RESET:
273
-                return 'success';
274
-                break;
275
-
276
-            case \Password::INVALID_TOKEN:
277
-                \Errors::invalidResetToken();
278
-                break;
279
-
280
-            case \Password::INVALID_PASSWORD:
281
-                \Errors::invalidResetPassword();
282
-                break;
283
-
284
-            case \Password::INVALID_USER:
285
-                \Errors::notFound('user');
286
-                break;
287
-        }
288
-    }
289
-
290
-    /**
291
-     * Change the logged in user password.
292
-     *
293
-     * @param  string  $password
294
-     * @param  string  $oldPassword
295
-     * @return void
296
-     */
297
-    public function changePassword($password, $oldPassword)
298
-    {
299
-        $user = \Auth::user();
300
-        if (! \Hash::check($oldPassword, $user->password)) {
301
-            \Errors::invalidOldPassword();
302
-        }
303
-
304
-        $this->repo->save(['id' => $user->id, 'password' => $password]);
305
-    }
306
-
307
-    /**
308
-     * Confirm email using the confirmation code.
309
-     *
310
-     * @param  string $confirmationCode
311
-     * @return void
312
-     */
313
-    public function confirmEmail($confirmationCode)
314
-    {
315
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
316
-            \Errors::invalidConfirmationCode();
317
-        }
318
-
319
-        $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
320
-    }
321
-
322
-    /**
323
-     * Send the confirmation mail.
324
-     *
325
-     * @param  string $email
326
-     * @return void
327
-     */
328
-    public function sendConfirmationEmail($email)
329
-    {
330
-        $user = $this->repo->first(['email' => $email]);
331
-        if ($user->confirmed) {
332
-            \Errors::emailAlreadyConfirmed();
333
-        }
334
-
335
-        $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
336
-        $this->notificationService->notify($user, 'ConfirmEmail');
337
-    }
338
-
339
-    /**
340
-     * Save the given data to the logged in user.
341
-     *
342
-     * @param  array $data
343
-     * @return void
344
-     */
345
-    public function saveProfile($data)
346
-    {
347
-        $data['id'] = \Auth::id();
348
-        return $this->repo->save($data);
349
-    }
350
-
351
-    /**
352
-     * Logs out the user, revoke access token and refresh token.
353
-     *
354
-     * @return void
355
-     */
356
-    public function logout()
357
-    {
358
-        $this->oauthClientService->revokeAccessToken(\Auth::user()->token());
359
-    }
360
-
361
-    /**
362
-     * Attempt to refresh the access token using the given refresh token.
363
-     *
364
-     * @param  string $refreshToken
365
-     * @return array
366
-     */
367
-    public function refreshToken($refreshToken)
368
-    {
369
-        return $this->loginProxy->refreshToken($refreshToken);
370
-    }
221
+		return $this->repo->save(['id' => $userId, 'blocked' => 1]);
222
+	}
223
+
224
+	/**
225
+	 * Unblock the user.
226
+	 *
227
+	 * @param  integer $userId
228
+	 * @return object
229
+	 */
230
+	public function unblock($userId)
231
+	{
232
+		return $this->repo->save(['id' => $userId, 'blocked' => 0]);
233
+	}
234
+
235
+	/**
236
+	 * Send a reset link to the given user.
237
+	 *
238
+	 * @param  string  $email
239
+	 * @return void
240
+	 */
241
+	public function sendReset($email)
242
+	{
243
+		if (! $user = $this->repo->first(['email' => $email])) {
244
+			\Errors::notFound('email');
245
+		}
246
+
247
+		$token = \Password::createToken($user);
248
+		$this->notificationService->notify($user, 'ResetPassword', $token);
249
+	}
250
+
251
+	/**
252
+	 * Reset the given user's password.
253
+	 *
254
+	 * @param   string  $email
255
+	 * @param   string  $password
256
+	 * @param   string  $passwordConfirmation
257
+	 * @param   string  $token
258
+	 * @return string|void
259
+	 */
260
+	public function resetPassword($email, $password, $passwordConfirmation, $token)
261
+	{
262
+		$response = \Password::reset([
263
+			'email'                 => $email,
264
+			'password'              => $password,
265
+			'password_confirmation' => $passwordConfirmation,
266
+			'token'                 => $token
267
+		], function ($user, $password) {
268
+			$this->repo->save(['id' => $user->id, 'password' => $password]);
269
+		});
270
+
271
+		switch ($response) {
272
+			case \Password::PASSWORD_RESET:
273
+				return 'success';
274
+				break;
275
+
276
+			case \Password::INVALID_TOKEN:
277
+				\Errors::invalidResetToken();
278
+				break;
279
+
280
+			case \Password::INVALID_PASSWORD:
281
+				\Errors::invalidResetPassword();
282
+				break;
283
+
284
+			case \Password::INVALID_USER:
285
+				\Errors::notFound('user');
286
+				break;
287
+		}
288
+	}
289
+
290
+	/**
291
+	 * Change the logged in user password.
292
+	 *
293
+	 * @param  string  $password
294
+	 * @param  string  $oldPassword
295
+	 * @return void
296
+	 */
297
+	public function changePassword($password, $oldPassword)
298
+	{
299
+		$user = \Auth::user();
300
+		if (! \Hash::check($oldPassword, $user->password)) {
301
+			\Errors::invalidOldPassword();
302
+		}
303
+
304
+		$this->repo->save(['id' => $user->id, 'password' => $password]);
305
+	}
306
+
307
+	/**
308
+	 * Confirm email using the confirmation code.
309
+	 *
310
+	 * @param  string $confirmationCode
311
+	 * @return void
312
+	 */
313
+	public function confirmEmail($confirmationCode)
314
+	{
315
+		if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
316
+			\Errors::invalidConfirmationCode();
317
+		}
318
+
319
+		$this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
320
+	}
321
+
322
+	/**
323
+	 * Send the confirmation mail.
324
+	 *
325
+	 * @param  string $email
326
+	 * @return void
327
+	 */
328
+	public function sendConfirmationEmail($email)
329
+	{
330
+		$user = $this->repo->first(['email' => $email]);
331
+		if ($user->confirmed) {
332
+			\Errors::emailAlreadyConfirmed();
333
+		}
334
+
335
+		$this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
336
+		$this->notificationService->notify($user, 'ConfirmEmail');
337
+	}
338
+
339
+	/**
340
+	 * Save the given data to the logged in user.
341
+	 *
342
+	 * @param  array $data
343
+	 * @return void
344
+	 */
345
+	public function saveProfile($data)
346
+	{
347
+		$data['id'] = \Auth::id();
348
+		return $this->repo->save($data);
349
+	}
350
+
351
+	/**
352
+	 * Logs out the user, revoke access token and refresh token.
353
+	 *
354
+	 * @return void
355
+	 */
356
+	public function logout()
357
+	{
358
+		$this->oauthClientService->revokeAccessToken(\Auth::user()->token());
359
+	}
360
+
361
+	/**
362
+	 * Attempt to refresh the access token using the given refresh token.
363
+	 *
364
+	 * @param  string $refreshToken
365
+	 * @return array
366
+	 */
367
+	public function refreshToken($refreshToken)
368
+	{
369
+		return $this->loginProxy->refreshToken($refreshToken);
370
+	}
371 371
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 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;
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']]) && ! $this->repo->deleted(['email' => $user['email']])->count()) {
178
+        if ( ! $this->repo->first(['email' => $user['email']]) && ! $this->repo->deleted(['email' => $user['email']])->count()) {
179 179
             $this->register(Arr::get($user, 'name'), $user['email'], '', true);
180 180
         }
181 181
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $data['confirmed'] = $skipConfirmEmail;
195 195
 
196
-        if($roleId){
196
+        if ($roleId) {
197 197
             $data ['roles'] = [['id' => $roleId]];
198 198
         }
199 199
 
200 200
         $user = $this->repo->save($data);
201 201
 
202
-        if (! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
202
+        if ( ! $skipConfirmEmail && ! config('user.disable_confirm_email')) {
203 203
             $this->sendConfirmationEmail($user->email);
204 204
         }
205 205
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      */
241 241
     public function sendReset($email)
242 242
     {
243
-        if (! $user = $this->repo->first(['email' => $email])) {
243
+        if ( ! $user = $this->repo->first(['email' => $email])) {
244 244
             \Errors::notFound('email');
245 245
         }
246 246
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
             'password'              => $password,
265 265
             'password_confirmation' => $passwordConfirmation,
266 266
             'token'                 => $token
267
-        ], function ($user, $password) {
267
+        ], function($user, $password) {
268 268
             $this->repo->save(['id' => $user->id, 'password' => $password]);
269 269
         });
270 270
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     public function changePassword($password, $oldPassword)
298 298
     {
299 299
         $user = \Auth::user();
300
-        if (! \Hash::check($oldPassword, $user->password)) {
300
+        if ( ! \Hash::check($oldPassword, $user->password)) {
301 301
             \Errors::invalidOldPassword();
302 302
         }
303 303
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      */
313 313
     public function confirmEmail($confirmationCode)
314 314
     {
315
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
315
+        if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
316 316
             \Errors::invalidConfirmationCode();
317 317
         }
318 318
 
Please login to merge, or discard this patch.