Completed
Push — master ( eb2586...ec2395 )
by Sherif
01:59
created
src/Modules/Notifications/Database/Seeds/NotificationsTableSeeder.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -6,46 +6,46 @@
 block discarded – undo
6 6
 
7 7
 class NotificationsTableSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        /**
17
-         * Insert the permissions related to settings table.
18
-         */
19
-        \DB::table('permissions')->insert(
20
-            [
21
-                /**
22
-                 * notifications model permissions.
23
-                 */
24
-                [
25
-                'name'       => 'all',
26
-                'model'      => 'notification',
27
-                'created_at' => \DB::raw('NOW()'),
28
-                'updated_at' => \DB::raw('NOW()')
29
-                ],
30
-                [
31
-                'name'       => 'unread',
32
-                'model'      => 'notification',
33
-                'created_at' => \DB::raw('NOW()'),
34
-                'updated_at' => \DB::raw('NOW()')
35
-                ],
36
-                [
37
-                'name'       => 'markAsRead',
38
-                'model'      => 'notification',
39
-                'created_at' => \DB::raw('NOW()'),
40
-                'updated_at' => \DB::raw('NOW()')
41
-                ],
42
-                [
43
-                'name'       => 'markAllAsRead',
44
-                'model'      => 'notification',
45
-                'created_at' => \DB::raw('NOW()'),
46
-                'updated_at' => \DB::raw('NOW()')
47
-                ]
48
-            ]
49
-        );
50
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		/**
17
+		 * Insert the permissions related to settings table.
18
+		 */
19
+		\DB::table('permissions')->insert(
20
+			[
21
+				/**
22
+				 * notifications model permissions.
23
+				 */
24
+				[
25
+				'name'       => 'all',
26
+				'model'      => 'notification',
27
+				'created_at' => \DB::raw('NOW()'),
28
+				'updated_at' => \DB::raw('NOW()')
29
+				],
30
+				[
31
+				'name'       => 'unread',
32
+				'model'      => 'notification',
33
+				'created_at' => \DB::raw('NOW()'),
34
+				'updated_at' => \DB::raw('NOW()')
35
+				],
36
+				[
37
+				'name'       => 'markAsRead',
38
+				'model'      => 'notification',
39
+				'created_at' => \DB::raw('NOW()'),
40
+				'updated_at' => \DB::raw('NOW()')
41
+				],
42
+				[
43
+				'name'       => 'markAllAsRead',
44
+				'model'      => 'notification',
45
+				'created_at' => \DB::raw('NOW()'),
46
+				'updated_at' => \DB::raw('NOW()')
47
+				]
48
+			]
49
+		);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
src/Modules/Notifications/Database/Seeds/AssignRelationsSeeder.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 AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin group.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function ($permission) use ($adminGroupId) {
22
-            \DB::table('groups_permissions')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'group_id'      => $adminGroupId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin group.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function ($permission) use ($adminGroupId) {
22
+			\DB::table('groups_permissions')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'group_id'      => $adminGroupId,
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.
src/Modules/Notifications/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', ['notification', 'pushNotificationDevice']);
17
-        \DB::table('groups_permissions')->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', ['notification', 'pushNotificationDevice']);
17
+		\DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.
Modules/Notifications/Database/Seeds/PushNotificationDevicesTableSeeder.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -6,64 +6,64 @@
 block discarded – undo
6 6
 
7 7
 class PushNotificationDevicesTableSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        /**
17
-         * Insert the permissions related to settings table.
18
-         */
19
-        \DB::table('permissions')->insert(
20
-            [
21
-                /**
22
-                 * pushNotificationDevices model permissions.
23
-                 */
24
-                [
25
-                'name'       => 'index',
26
-                'model'      => 'pushNotificationDevice',
27
-                'created_at' => \DB::raw('NOW()'),
28
-                'updated_at' => \DB::raw('NOW()')
29
-                ],
30
-                [
31
-                'name'       => 'find',
32
-                'model'      => 'pushNotificationDevice',
33
-                'created_at' => \DB::raw('NOW()'),
34
-                'updated_at' => \DB::raw('NOW()')
35
-                ],
36
-                [
37
-                'name'       => 'insert',
38
-                'model'      => 'pushNotificationDevice',
39
-                'created_at' => \DB::raw('NOW()'),
40
-                'updated_at' => \DB::raw('NOW()')
41
-                ],
42
-                [
43
-                'name'       => 'update',
44
-                'model'      => 'pushNotificationDevice',
45
-                'created_at' => \DB::raw('NOW()'),
46
-                'updated_at' => \DB::raw('NOW()')
47
-                ],
48
-                [
49
-                'name'       => 'delete',
50
-                'model'      => 'pushNotificationDevice',
51
-                'created_at' => \DB::raw('NOW()'),
52
-                'updated_at' => \DB::raw('NOW()')
53
-                ],
54
-                [
55
-                'name'       => 'deleted',
56
-                'model'      => 'pushNotificationDevice',
57
-                'created_at' => \DB::raw('NOW()'),
58
-                'updated_at' => \DB::raw('NOW()')
59
-                ],
60
-                [
61
-                'name'       => 'restore',
62
-                'model'      => 'pushNotificationDevice',
63
-                'created_at' => \DB::raw('NOW()'),
64
-                'updated_at' => \DB::raw('NOW()')
65
-                ]
66
-            ]
67
-        );
68
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		/**
17
+		 * Insert the permissions related to settings table.
18
+		 */
19
+		\DB::table('permissions')->insert(
20
+			[
21
+				/**
22
+				 * pushNotificationDevices model permissions.
23
+				 */
24
+				[
25
+				'name'       => 'index',
26
+				'model'      => 'pushNotificationDevice',
27
+				'created_at' => \DB::raw('NOW()'),
28
+				'updated_at' => \DB::raw('NOW()')
29
+				],
30
+				[
31
+				'name'       => 'find',
32
+				'model'      => 'pushNotificationDevice',
33
+				'created_at' => \DB::raw('NOW()'),
34
+				'updated_at' => \DB::raw('NOW()')
35
+				],
36
+				[
37
+				'name'       => 'insert',
38
+				'model'      => 'pushNotificationDevice',
39
+				'created_at' => \DB::raw('NOW()'),
40
+				'updated_at' => \DB::raw('NOW()')
41
+				],
42
+				[
43
+				'name'       => 'update',
44
+				'model'      => 'pushNotificationDevice',
45
+				'created_at' => \DB::raw('NOW()'),
46
+				'updated_at' => \DB::raw('NOW()')
47
+				],
48
+				[
49
+				'name'       => 'delete',
50
+				'model'      => 'pushNotificationDevice',
51
+				'created_at' => \DB::raw('NOW()'),
52
+				'updated_at' => \DB::raw('NOW()')
53
+				],
54
+				[
55
+				'name'       => 'deleted',
56
+				'model'      => 'pushNotificationDevice',
57
+				'created_at' => \DB::raw('NOW()'),
58
+				'updated_at' => \DB::raw('NOW()')
59
+				],
60
+				[
61
+				'name'       => 'restore',
62
+				'model'      => 'pushNotificationDevice',
63
+				'created_at' => \DB::raw('NOW()'),
64
+				'updated_at' => \DB::raw('NOW()')
65
+				]
66
+			]
67
+		);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
Database/Migrations/2016_01_24_111942_push_notification_devices.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -5,31 +5,31 @@
 block discarded – undo
5 5
 
6 6
 class PushNotificationDevices extends Migration
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function up()
14
-    {
15
-        Schema::create('push_notification_devices', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('device_token');
18
-            $table->integer('user_id');
19
-            $table->text('access_token')->nullable();
20
-            $table->unique(array('device_token', 'user_id'));
21
-            $table->softDeletes();
22
-            $table->timestamps();
23
-        });
24
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function up()
14
+	{
15
+		Schema::create('push_notification_devices', function (Blueprint $table) {
16
+			$table->increments('id');
17
+			$table->string('device_token');
18
+			$table->integer('user_id');
19
+			$table->text('access_token')->nullable();
20
+			$table->unique(array('device_token', 'user_id'));
21
+			$table->softDeletes();
22
+			$table->timestamps();
23
+		});
24
+	}
25 25
 
26
-    /**
27
-     * Reverse the migrations.
28
-     *
29
-     * @return void
30
-     */
31
-    public function down()
32
-    {
33
-        Schema::dropIfExists('push_notifications_devices');
34
-    }
26
+	/**
27
+	 * Reverse the migrations.
28
+	 *
29
+	 * @return void
30
+	 */
31
+	public function down()
32
+	{
33
+		Schema::dropIfExists('push_notifications_devices');
34
+	}
35 35
 }
Please login to merge, or discard this patch.
src/Modules/Acl/AclPermission.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,37 +6,37 @@
 block discarded – undo
6 6
 class AclPermission extends Model
7 7
 {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'permissions';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['deleted_at'];
13
-    protected $guarded  = ['id'];
14
-    protected $fillable = ['name', 'model'];
15
-    public $searchable  = ['name', 'model'];
9
+	use SoftDeletes;
10
+	protected $table    = 'permissions';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['deleted_at'];
13
+	protected $guarded  = ['id'];
14
+	protected $fillable = ['name', 'model'];
15
+	public $searchable  = ['name', 'model'];
16 16
 
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
20
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
20
+	}
21 21
 
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
25
-    }
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
25
+	}
26 26
 
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
30
-    }
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
30
+	}
31 31
     
32
-    public function groups()
33
-    {
34
-        return $this->belongsToMany('App\Modules\Acl\AclGroup', 'groups_permissions', 'permission_id', 'group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
35
-    }
32
+	public function groups()
33
+	{
34
+		return $this->belongsToMany('App\Modules\Acl\AclGroup', 'groups_permissions', 'permission_id', 'group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps();
35
+	}
36 36
 
37
-    public static function boot()
38
-    {
39
-        parent::boot();
40
-        AclPermission::observe(\App::make('App\Modules\Acl\ModelObservers\AclPermissionObserver'));
41
-    }
37
+	public static function boot()
38
+	{
39
+		parent::boot();
40
+		AclPermission::observe(\App::make('App\Modules\Acl\ModelObservers\AclPermissionObserver'));
41
+	}
42 42
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Proxy/LoginProxy.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -2,77 +2,77 @@
 block discarded – undo
2 2
 
3 3
 class LoginProxy
4 4
 {
5
-    /**
6
-     * Attempt to create an access token using user credentials.
7
-     *
8
-     * @param  array   $credentials
9
-     * @param  boolean $adminLogin
10
-     * @return array
11
-     */
12
-    public function login($credentials, $adminLogin = false)
13
-    {
14
-        $user = \Core::users()->login($credentials, $adminLogin);
15
-        $tokens = $this->proxy('password', [
16
-            'username' => $credentials['email'],
17
-            'password' => $credentials['password']
18
-        ]);
5
+	/**
6
+	 * Attempt to create an access token using user credentials.
7
+	 *
8
+	 * @param  array   $credentials
9
+	 * @param  boolean $adminLogin
10
+	 * @return array
11
+	 */
12
+	public function login($credentials, $adminLogin = false)
13
+	{
14
+		$user = \Core::users()->login($credentials, $adminLogin);
15
+		$tokens = $this->proxy('password', [
16
+			'username' => $credentials['email'],
17
+			'password' => $credentials['password']
18
+		]);
19 19
 
20
-        return compact('user', 'tokens');
21
-    }
20
+		return compact('user', 'tokens');
21
+	}
22 22
 
23
-    /**
24
-     * Attempt to refresh the access token useing the given refresh token.
25
-     *
26
-     * @param  string $refreshToken
27
-     * @return array
28
-     */
29
-    public function refreshToken($refreshToken)
30
-    {
31
-        return $this->proxy('refresh_token', [
32
-            'refresh_token' => $refreshToken
33
-        ]);
34
-    }
23
+	/**
24
+	 * Attempt to refresh the access token useing the given refresh token.
25
+	 *
26
+	 * @param  string $refreshToken
27
+	 * @return array
28
+	 */
29
+	public function refreshToken($refreshToken)
30
+	{
31
+		return $this->proxy('refresh_token', [
32
+			'refresh_token' => $refreshToken
33
+		]);
34
+	}
35 35
 
36
-    /**
37
-     * Proxy a request to the OAuth server.
38
-     *
39
-     * @param string $grantType what type of grant type should be proxied
40
-     * @param array
41
-     */
42
-    public function proxy($grantType, array $data = [])
43
-    {
44
-        $data = array_merge($data, [
45
-            'client_id'     => config('skeleton.passport_client_id'),
46
-            'client_secret' => config('skeleton.passport_client_secret'),
47
-            'grant_type'    => $grantType
48
-        ]);
36
+	/**
37
+	 * Proxy a request to the OAuth server.
38
+	 *
39
+	 * @param string $grantType what type of grant type should be proxied
40
+	 * @param array
41
+	 */
42
+	public function proxy($grantType, array $data = [])
43
+	{
44
+		$data = array_merge($data, [
45
+			'client_id'     => config('skeleton.passport_client_id'),
46
+			'client_secret' => config('skeleton.passport_client_secret'),
47
+			'grant_type'    => $grantType
48
+		]);
49 49
 
50
-        $response = \ApiConsumer::post('/oauth/token', $data);
50
+		$response = \ApiConsumer::post('/oauth/token', $data);
51 51
 
52
-        if (! $response->isSuccessful()) {
53
-            if ($grantType == 'refresh_token') {
54
-                \ErrorHandler::invalidRefreshToken();
55
-            }
52
+		if (! $response->isSuccessful()) {
53
+			if ($grantType == 'refresh_token') {
54
+				\ErrorHandler::invalidRefreshToken();
55
+			}
56 56
 
57
-            \ErrorHandler::loginFailed();
58
-        }
57
+			\ErrorHandler::loginFailed();
58
+		}
59 59
 
60
-        $data = json_decode($response->getContent());
60
+		$data = json_decode($response->getContent());
61 61
 
62
-        return [
63
-            'access_token'  => $data->access_token,
64
-            'refresh_token' => $data->refresh_token,
65
-            'expires_in'    => $data->expires_in
66
-        ];
67
-    }
62
+		return [
63
+			'access_token'  => $data->access_token,
64
+			'refresh_token' => $data->refresh_token,
65
+			'expires_in'    => $data->expires_in
66
+		];
67
+	}
68 68
 
69
-    /**
70
-     * Logs out the user. We revoke access token and refresh token.
71
-     *
72
-     * @return void
73
-     */
74
-    public function logout()
75
-    {
76
-        \Core::users()->revokeAccessToken(\Auth::user()->token());
77
-    }
69
+	/**
70
+	 * Logs out the user. We revoke access token and refresh token.
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function logout()
75
+	{
76
+		\Core::users()->revokeAccessToken(\Auth::user()->token());
77
+	}
78 78
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Repositories/UserRepository.php 1 patch
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -6,391 +6,391 @@
 block discarded – undo
6 6
 
7 7
 class UserRepository extends BaseRepository
8 8
 {
9
-    /**
10
-     * Init new object.
11
-     *
12
-     * @param   AclUser $model
13
-     * @return  void
14
-     */
15
-    public function __construct(AclUser $model)
16
-    {
17
-        parent::__construct($model);
18
-    }
19
-
20
-    /**
21
-     * Return the logged in user account.
22
-     *
23
-     * @param  array   $relations
24
-     * @return boolean
25
-     */
26
-    public function account($relations = [])
27
-    {
28
-        $permissions = [];
29
-        $user        = $this->find(\Auth::id(), $relations);
30
-        foreach ($user->groups()->get() as $group) {
31
-            $group->permissions->each(function ($permission) use (&$permissions) {
32
-                $permissions[$permission->model][$permission->id] = $permission->name;
33
-            });
34
-        }
35
-        $user->permissions = $permissions;
36
-
37
-        return $user;
38
-    }
39
-
40
-    /**
41
-     * Check if the logged in user or the given user
42
-     * has the given permissions on the given model.
43
-     *
44
-     * @param  string $nameOfPermission
45
-     * @param  string $model
46
-     * @param  mixed  $user
47
-     * @return boolean
48
-     */
49
-    public function can($nameOfPermission, $model, $user = false)
50
-    {
51
-        $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
-        $permissions = [];
53
-
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) {
55
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray());
56
-        });
57
-
58
-        return in_array($nameOfPermission, $permissions);
59
-    }
60
-
61
-    /**
62
-     * Check if the logged in user has the given group.
63
-     *
64
-     * @param  string[] $groups
65
-     * @param  mixed $user
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groups, $user = false)
69
-    {
70
-        $user = $user ?: $this->find(\Auth::id());
71
-        return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
-    }
73
-
74
-    /**
75
-     * Assign the given group ids to the given user.
76
-     *
77
-     * @param  integer $userId
78
-     * @param  array   $groupIds
79
-     * @return object
80
-     */
81
-    public function assignGroups($userId, $groupIds)
82
-    {
83
-        \DB::transaction(function () use ($userId, $groupIds) {
84
-            $user = $this->find($userId);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($groupIds);
87
-        });
88
-
89
-        return $this->find($userId);
90
-    }
91
-
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     *
96
-     * @param  array   $credentials
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if (! $user = $this->first(['email' => $credentials['email']])) {
103
-            \ErrorHandler::loginFailed();
104
-        } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
-            \ErrorHandler::loginFailed();
106
-        } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
-            \ErrorHandler::loginFailed();
108
-        } elseif ($user->blocked) {
109
-            \ErrorHandler::userIsBlocked();
110
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
-            \ErrorHandler::emailNotConfirmed();
112
-        }
113
-
114
-        return $user;
115
-    }
116
-
117
-    /**
118
-     * Handle a social login request of the none admin to the application.
119
-     *
120
-     * @param  string $authCode
121
-     * @param  string $accessToken
122
-     * @param  string $type
123
-     * @return array
124
-     */
125
-    public function loginSocial($authCode, $accessToken, $type)
126
-    {
127
-        $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
129
-
130
-        if (! $user->email) {
131
-            \ErrorHandler::noSocialEmail();
132
-        }
133
-
134
-        if (! $this->model->where('email', $user->email)->first()) {
135
-            $this->register(['email' => $user->email, 'password' => ''], true);
136
-        }
137
-
138
-        $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
139
-        return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
-    }
9
+	/**
10
+	 * Init new object.
11
+	 *
12
+	 * @param   AclUser $model
13
+	 * @return  void
14
+	 */
15
+	public function __construct(AclUser $model)
16
+	{
17
+		parent::__construct($model);
18
+	}
19
+
20
+	/**
21
+	 * Return the logged in user account.
22
+	 *
23
+	 * @param  array   $relations
24
+	 * @return boolean
25
+	 */
26
+	public function account($relations = [])
27
+	{
28
+		$permissions = [];
29
+		$user        = $this->find(\Auth::id(), $relations);
30
+		foreach ($user->groups()->get() as $group) {
31
+			$group->permissions->each(function ($permission) use (&$permissions) {
32
+				$permissions[$permission->model][$permission->id] = $permission->name;
33
+			});
34
+		}
35
+		$user->permissions = $permissions;
36
+
37
+		return $user;
38
+	}
39
+
40
+	/**
41
+	 * Check if the logged in user or the given user
42
+	 * has the given permissions on the given model.
43
+	 *
44
+	 * @param  string $nameOfPermission
45
+	 * @param  string $model
46
+	 * @param  mixed  $user
47
+	 * @return boolean
48
+	 */
49
+	public function can($nameOfPermission, $model, $user = false)
50
+	{
51
+		$user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
+		$permissions = [];
53
+
54
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) {
55
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray());
56
+		});
57
+
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 *
64
+	 * @param  string[] $groups
65
+	 * @param  mixed $user
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groups, $user = false)
69
+	{
70
+		$user = $user ?: $this->find(\Auth::id());
71
+		return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
+	}
73
+
74
+	/**
75
+	 * Assign the given group ids to the given user.
76
+	 *
77
+	 * @param  integer $userId
78
+	 * @param  array   $groupIds
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($userId, $groupIds)
82
+	{
83
+		\DB::transaction(function () use ($userId, $groupIds) {
84
+			$user = $this->find($userId);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($groupIds);
87
+		});
88
+
89
+		return $this->find($userId);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 *
96
+	 * @param  array   $credentials
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if (! $user = $this->first(['email' => $credentials['email']])) {
103
+			\ErrorHandler::loginFailed();
104
+		} elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
+			\ErrorHandler::loginFailed();
106
+		} elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
+			\ErrorHandler::loginFailed();
108
+		} elseif ($user->blocked) {
109
+			\ErrorHandler::userIsBlocked();
110
+		} elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
+			\ErrorHandler::emailNotConfirmed();
112
+		}
113
+
114
+		return $user;
115
+	}
116
+
117
+	/**
118
+	 * Handle a social login request of the none admin to the application.
119
+	 *
120
+	 * @param  string $authCode
121
+	 * @param  string $accessToken
122
+	 * @param  string $type
123
+	 * @return array
124
+	 */
125
+	public function loginSocial($authCode, $accessToken, $type)
126
+	{
127
+		$access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
129
+
130
+		if (! $user->email) {
131
+			\ErrorHandler::noSocialEmail();
132
+		}
133
+
134
+		if (! $this->model->where('email', $user->email)->first()) {
135
+			$this->register(['email' => $user->email, 'password' => ''], true);
136
+		}
137
+
138
+		$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
139
+		return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
+	}
141 141
     
142
-    /**
143
-     * Handle a registration request.
144
-     *
145
-     * @param  array   $credentials
146
-     * @param  boolean $skipConfirmEmail
147
-     * @return array
148
-     */
149
-    public function register($credentials, $skipConfirmEmail = false)
150
-    {
151
-        $user = $this->save($credentials);
152
-
153
-        if ($skipConfirmEmail) {
154
-            $user->confirmed = 1;
155
-            $user->save();
156
-        } elseif (! config('skeleton.disable_confirm_email')) {
157
-            $this->sendConfirmationEmail($user->email);
158
-        }
159
-
160
-        return $user;
161
-    }
142
+	/**
143
+	 * Handle a registration request.
144
+	 *
145
+	 * @param  array   $credentials
146
+	 * @param  boolean $skipConfirmEmail
147
+	 * @return array
148
+	 */
149
+	public function register($credentials, $skipConfirmEmail = false)
150
+	{
151
+		$user = $this->save($credentials);
152
+
153
+		if ($skipConfirmEmail) {
154
+			$user->confirmed = 1;
155
+			$user->save();
156
+		} elseif (! config('skeleton.disable_confirm_email')) {
157
+			$this->sendConfirmationEmail($user->email);
158
+		}
159
+
160
+		return $user;
161
+	}
162 162
     
163
-    /**
164
-     * Block the user.
165
-     *
166
-     * @param  integer $userId
167
-     * @return object
168
-     */
169
-    public function block($userId)
170
-    {
171
-        if (! $user = $this->find($userId)) {
172
-            \ErrorHandler::notFound('user');
173
-        }
174
-        if (! $this->hasGroup(['Admin'])) {
175
-            \ErrorHandler::noPermissions();
176
-        } elseif (\Auth::id() == $userId) {
177
-            \ErrorHandler::noPermissions();
178
-        } elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
-            \ErrorHandler::noPermissions();
180
-        }
181
-
182
-        $user->blocked = 1;
183
-        $user->save();
163
+	/**
164
+	 * Block the user.
165
+	 *
166
+	 * @param  integer $userId
167
+	 * @return object
168
+	 */
169
+	public function block($userId)
170
+	{
171
+		if (! $user = $this->find($userId)) {
172
+			\ErrorHandler::notFound('user');
173
+		}
174
+		if (! $this->hasGroup(['Admin'])) {
175
+			\ErrorHandler::noPermissions();
176
+		} elseif (\Auth::id() == $userId) {
177
+			\ErrorHandler::noPermissions();
178
+		} elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
+			\ErrorHandler::noPermissions();
180
+		}
181
+
182
+		$user->blocked = 1;
183
+		$user->save();
184 184
         
185
-        return $user;
186
-    }
187
-
188
-    /**
189
-     * Unblock the user.
190
-     *
191
-     * @param  integer $userId
192
-     * @return object
193
-     */
194
-    public function unblock($userId)
195
-    {
196
-        if (! $this->hasGroup(['Admin'])) {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user          = $this->find($userId);
201
-        $user->blocked = 0;
202
-        $user->save();
203
-
204
-        return $user;
205
-    }
206
-
207
-    /**
208
-     * Send a reset link to the given user.
209
-     *
210
-     * @param  string  $email
211
-     * @return void
212
-     */
213
-    public function sendReset($email)
214
-    {
215
-        if (! $user = $this->model->where('email', $email)->first()) {
216
-            \ErrorHandler::notFound('email');
217
-        }
218
-
219
-        $token = \Password::getRepository()->create($user);
220
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
221
-    }
222
-
223
-    /**
224
-     * Reset the given user's password.
225
-     *
226
-     * @param  array  $credentials
227
-     * @return string|null
228
-     */
229
-    public function resetPassword($credentials)
230
-    {
231
-        $response = \Password::reset($credentials, function ($user, $password) {
232
-            $user->password = $password;
233
-            $user->save();
234
-        });
235
-
236
-        switch ($response) {
237
-            case \Password::PASSWORD_RESET:
238
-                return 'success';
239
-
240
-            case \Password::INVALID_TOKEN:
241
-                \ErrorHandler::invalidResetToken('token');
242
-                //no break
243
-
244
-            case \Password::INVALID_PASSWORD:
245
-                \ErrorHandler::invalidResetPassword('email');
246
-                //no break
247
-
248
-            case \Password::INVALID_USER:
249
-                \ErrorHandler::notFound('user');
250
-                //no break
251
-
252
-            default:
253
-                \ErrorHandler::generalError();
254
-        }
255
-    }
256
-
257
-    /**
258
-     * Change the logged in user password.
259
-     *
260
-     * @param  array  $credentials
261
-     * @return void
262
-     */
263
-    public function changePassword($credentials)
264
-    {
265
-        $user = \Auth::user();
266
-        if (! \Hash::check($credentials['old_password'], $user->password)) {
267
-            \ErrorHandler::invalidOldPassword();
268
-        }
269
-
270
-        $user->password = $credentials['password'];
271
-        $user->save();
272
-    }
273
-
274
-    /**
275
-     * Confirm email using the confirmation code.
276
-     *
277
-     * @param  string $confirmationCode
278
-     * @return void
279
-     */
280
-    public function confirmEmail($confirmationCode)
281
-    {
282
-        if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
-            \ErrorHandler::invalidConfirmationCode();
284
-        }
285
-
286
-        $user->confirmed         = 1;
287
-        $user->confirmation_code = null;
288
-        $user->save();
289
-    }
290
-
291
-    /**
292
-     * Send the confirmation mail.
293
-     *
294
-     * @param  string $email
295
-     * @return void
296
-     */
297
-    public function sendConfirmationEmail($email)
298
-    {
299
-        $user = $this->first(['email' => $email]);
300
-        if ($user->confirmed) {
301
-            \ErrorHandler::emailAlreadyConfirmed();
302
-        }
303
-
304
-        $user->confirmed         = 0;
305
-        $user->confirmation_code = sha1(microtime());
306
-        $user->save();
307
-        \Core::notifications()->notify($user, 'ConfirmEmail');
308
-    }
309
-
310
-    /**
311
-     * Paginate all users in the given group based on the given conditions.
312
-     *
313
-     * @param  string  $groupName
314
-     * @param  array   $relations
315
-     * @param  integer $perPage
316
-     * @param  string  $sortBy
317
-     * @param  boolean $desc
318
-     * @return \Illuminate\Http\Response
319
-     */
320
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
-    {
322
-        unset($conditions['page']);
323
-        $conditions = $this->constructConditions($conditions, $this->model);
324
-        $sort       = $desc ? 'desc' : 'asc';
325
-        $model      = $this->model->with($relations);
326
-
327
-        $model->whereHas('groups', function ($q) use ($groupName) {
328
-            $q->where('name', $groupName);
329
-        });
185
+		return $user;
186
+	}
187
+
188
+	/**
189
+	 * Unblock the user.
190
+	 *
191
+	 * @param  integer $userId
192
+	 * @return object
193
+	 */
194
+	public function unblock($userId)
195
+	{
196
+		if (! $this->hasGroup(['Admin'])) {
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user          = $this->find($userId);
201
+		$user->blocked = 0;
202
+		$user->save();
203
+
204
+		return $user;
205
+	}
206
+
207
+	/**
208
+	 * Send a reset link to the given user.
209
+	 *
210
+	 * @param  string  $email
211
+	 * @return void
212
+	 */
213
+	public function sendReset($email)
214
+	{
215
+		if (! $user = $this->model->where('email', $email)->first()) {
216
+			\ErrorHandler::notFound('email');
217
+		}
218
+
219
+		$token = \Password::getRepository()->create($user);
220
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
221
+	}
222
+
223
+	/**
224
+	 * Reset the given user's password.
225
+	 *
226
+	 * @param  array  $credentials
227
+	 * @return string|null
228
+	 */
229
+	public function resetPassword($credentials)
230
+	{
231
+		$response = \Password::reset($credentials, function ($user, $password) {
232
+			$user->password = $password;
233
+			$user->save();
234
+		});
235
+
236
+		switch ($response) {
237
+			case \Password::PASSWORD_RESET:
238
+				return 'success';
239
+
240
+			case \Password::INVALID_TOKEN:
241
+				\ErrorHandler::invalidResetToken('token');
242
+				//no break
243
+
244
+			case \Password::INVALID_PASSWORD:
245
+				\ErrorHandler::invalidResetPassword('email');
246
+				//no break
247
+
248
+			case \Password::INVALID_USER:
249
+				\ErrorHandler::notFound('user');
250
+				//no break
251
+
252
+			default:
253
+				\ErrorHandler::generalError();
254
+		}
255
+	}
256
+
257
+	/**
258
+	 * Change the logged in user password.
259
+	 *
260
+	 * @param  array  $credentials
261
+	 * @return void
262
+	 */
263
+	public function changePassword($credentials)
264
+	{
265
+		$user = \Auth::user();
266
+		if (! \Hash::check($credentials['old_password'], $user->password)) {
267
+			\ErrorHandler::invalidOldPassword();
268
+		}
269
+
270
+		$user->password = $credentials['password'];
271
+		$user->save();
272
+	}
273
+
274
+	/**
275
+	 * Confirm email using the confirmation code.
276
+	 *
277
+	 * @param  string $confirmationCode
278
+	 * @return void
279
+	 */
280
+	public function confirmEmail($confirmationCode)
281
+	{
282
+		if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
+			\ErrorHandler::invalidConfirmationCode();
284
+		}
285
+
286
+		$user->confirmed         = 1;
287
+		$user->confirmation_code = null;
288
+		$user->save();
289
+	}
290
+
291
+	/**
292
+	 * Send the confirmation mail.
293
+	 *
294
+	 * @param  string $email
295
+	 * @return void
296
+	 */
297
+	public function sendConfirmationEmail($email)
298
+	{
299
+		$user = $this->first(['email' => $email]);
300
+		if ($user->confirmed) {
301
+			\ErrorHandler::emailAlreadyConfirmed();
302
+		}
303
+
304
+		$user->confirmed         = 0;
305
+		$user->confirmation_code = sha1(microtime());
306
+		$user->save();
307
+		\Core::notifications()->notify($user, 'ConfirmEmail');
308
+	}
309
+
310
+	/**
311
+	 * Paginate all users in the given group based on the given conditions.
312
+	 *
313
+	 * @param  string  $groupName
314
+	 * @param  array   $relations
315
+	 * @param  integer $perPage
316
+	 * @param  string  $sortBy
317
+	 * @param  boolean $desc
318
+	 * @return \Illuminate\Http\Response
319
+	 */
320
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
+	{
322
+		unset($conditions['page']);
323
+		$conditions = $this->constructConditions($conditions, $this->model);
324
+		$sort       = $desc ? 'desc' : 'asc';
325
+		$model      = $this->model->with($relations);
326
+
327
+		$model->whereHas('groups', function ($q) use ($groupName) {
328
+			$q->where('name', $groupName);
329
+		});
330 330
 
331 331
         
332
-        if (count($conditions['conditionValues'])) {
333
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
-        }
335
-
336
-        if ($perPage) {
337
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
-        }
339
-
340
-        return $model->orderBy($sortBy, $sort)->get();
341
-    }
342
-
343
-    /**
344
-     * Save the given data to the logged in user.
345
-     *
346
-     * @param  array $data
347
-     * @return void
348
-     */
349
-    public function saveProfile($data)
350
-    {
351
-        if (Arr::has($data, 'profile_picture')) {
352
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
-        }
332
+		if (count($conditions['conditionValues'])) {
333
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
+		}
335
+
336
+		if ($perPage) {
337
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
+		}
339
+
340
+		return $model->orderBy($sortBy, $sort)->get();
341
+	}
342
+
343
+	/**
344
+	 * Save the given data to the logged in user.
345
+	 *
346
+	 * @param  array $data
347
+	 * @return void
348
+	 */
349
+	public function saveProfile($data)
350
+	{
351
+		if (Arr::has($data, 'profile_picture')) {
352
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
+		}
354 354
         
355
-        $data['id'] = \Auth::id();
356
-        return $this->save($data);
357
-    }
358
-
359
-    /**
360
-     * Ensure access token hasn't expired or revoked.
361
-     *
362
-     * @param  string $accessToken
363
-     * @return boolean
364
-     */
365
-    public function accessTokenExpiredOrRevoked($accessToken)
366
-    {
367
-        $accessTokenId = json_decode($accessToken, true)['id'];
368
-        $accessToken   = \DB::table('oauth_access_tokens')
369
-                ->where('id', $accessTokenId)
370
-                ->first();
355
+		$data['id'] = \Auth::id();
356
+		return $this->save($data);
357
+	}
358
+
359
+	/**
360
+	 * Ensure access token hasn't expired or revoked.
361
+	 *
362
+	 * @param  string $accessToken
363
+	 * @return boolean
364
+	 */
365
+	public function accessTokenExpiredOrRevoked($accessToken)
366
+	{
367
+		$accessTokenId = json_decode($accessToken, true)['id'];
368
+		$accessToken   = \DB::table('oauth_access_tokens')
369
+				->where('id', $accessTokenId)
370
+				->first();
371 371
         
372
-        if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
-            return true;
374
-        }
375
-
376
-        return false;
377
-    }
378
-
379
-    /**
380
-     * Revoke the given access token and all
381
-     * associated refresh tokens.
382
-     *
383
-     * @param  oject $accessToken
384
-     * @return void
385
-     */
386
-    public function revokeAccessToken($accessToken)
387
-    {
388
-        \DB::table('oauth_refresh_tokens')
389
-            ->where('access_token_id', $accessToken->id)
390
-            ->update([
391
-                'revoked' => true
392
-            ]);
393
-
394
-        $accessToken->revoke();
395
-    }
372
+		if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
+			return true;
374
+		}
375
+
376
+		return false;
377
+	}
378
+
379
+	/**
380
+	 * Revoke the given access token and all
381
+	 * associated refresh tokens.
382
+	 *
383
+	 * @param  oject $accessToken
384
+	 * @return void
385
+	 */
386
+	public function revokeAccessToken($accessToken)
387
+	{
388
+		\DB::table('oauth_refresh_tokens')
389
+			->where('access_token_id', $accessToken->id)
390
+			->update([
391
+				'revoked' => true
392
+			]);
393
+
394
+		$accessToken->revoke();
395
+	}
396 396
 }
Please login to merge, or discard this patch.
src/Modules/Acl/Http/Resources/AclPermission.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@
 block discarded – undo
7 7
 
8 8
 class AclPermission extends JsonResource
9 9
 {
10
-    /**
11
-     * Transform the resource into an array.
12
-     *
13
-     * @param Request $request
14
-     * @return array
15
-     */
16
-    public function toArray($request)
17
-    {
18
-        return [
19
-            'id' => $this->id,
20
-            'name' => $this->name,
21
-            'groups' => GroupResource::collection($this->whenLoaded('groups')),
22
-            'created_at' => $this->created_at,
23
-            'updated_at' => $this->updated_at,
24
-        ];
25
-    }
10
+	/**
11
+	 * Transform the resource into an array.
12
+	 *
13
+	 * @param Request $request
14
+	 * @return array
15
+	 */
16
+	public function toArray($request)
17
+	{
18
+		return [
19
+			'id' => $this->id,
20
+			'name' => $this->name,
21
+			'groups' => GroupResource::collection($this->whenLoaded('groups')),
22
+			'created_at' => $this->created_at,
23
+			'updated_at' => $this->updated_at,
24
+		];
25
+	}
26 26
 }
Please login to merge, or discard this patch.