Completed
Push — master ( 09a99f...0f3793 )
by Sherif
02:40
created
src/Modules/V1/Core/Utl/ErrorHandler.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -2,81 +2,81 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        $error = ['status' => 401, 'message' => 'Please login before any action'];
8
-        abort($error['status'], $error['message']);
9
-    }
5
+	public function unAuthorized()
6
+	{
7
+		$error = ['status' => 401, 'message' => 'Please login before any action'];
8
+		abort($error['status'], $error['message']);
9
+	}
10 10
 
11
-    public function tokenExpired()
12
-    {
13
-        $error = ['status' => 403, 'message' => 'Login token expired'];
14
-        abort($error['status'], $error['message']);
15
-    }
11
+	public function tokenExpired()
12
+	{
13
+		$error = ['status' => 403, 'message' => 'Login token expired'];
14
+		abort($error['status'], $error['message']);
15
+	}
16 16
 
17
-     public function noPermissions()
18
-    {
19
-        $error = ['status' => 403, 'message' => 'No permissions'];
20
-        abort($error['status'], $error['message']);
21
-    }
17
+	 public function noPermissions()
18
+	{
19
+		$error = ['status' => 403, 'message' => 'No permissions'];
20
+		abort($error['status'], $error['message']);
21
+	}
22 22
 
23
-    public function loginFailed()
24
-    {
25
-        $error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
-        abort($error['status'], $error['message']);
27
-    }
23
+	public function loginFailed()
24
+	{
25
+		$error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
+		abort($error['status'], $error['message']);
27
+	}
28 28
 
29
-    public function redisNotRunning()
30
-    {
31
-        $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
-        abort($error['status'], $error['message']);
33
-    }
29
+	public function redisNotRunning()
30
+	{
31
+		$error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
+		abort($error['status'], $error['message']);
33
+	}
34 34
 
35
-    public function dbQueryError()
36
-    {
37
-        $error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
-        abort($error['status'], $error['message']);
39
-    }
35
+	public function dbQueryError()
36
+	{
37
+		$error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
+		abort($error['status'], $error['message']);
39
+	}
40 40
 
41
-    public function cannotCreateSetting()
42
-    {
43
-        $error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
-        abort($error['status'], $error['message']);
45
-    }
41
+	public function cannotCreateSetting()
42
+	{
43
+		$error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
+		abort($error['status'], $error['message']);
45
+	}
46 46
 
47
-    public function cannotUpdateSettingKey()
48
-    {
49
-        $error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
-        abort($error['status'], $error['message']);
51
-    }
47
+	public function cannotUpdateSettingKey()
48
+	{
49
+		$error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
+		abort($error['status'], $error['message']);
51
+	}
52 52
 
53
-    public function userIsBlocked()
54
-    {
55
-        $error = ['status' => 403, 'message' => 'You have been blocked'];
56
-        abort($error['status'], $error['message']);
57
-    }
53
+	public function userIsBlocked()
54
+	{
55
+		$error = ['status' => 403, 'message' => 'You have been blocked'];
56
+		abort($error['status'], $error['message']);
57
+	}
58 58
 
59
-    public function invalidResetToken()
60
-    {
61
-        $error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
-        abort($error['status'], $error['message']);
63
-    }
59
+	public function invalidResetToken()
60
+	{
61
+		$error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
+		abort($error['status'], $error['message']);
63
+	}
64 64
 
65
-    public function invalidResetPassword()
66
-    {
67
-        $error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
-        abort($error['status'], $error['message']);
69
-    }
65
+	public function invalidResetPassword()
66
+	{
67
+		$error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
+		abort($error['status'], $error['message']);
69
+	}
70 70
 
71
-    public function notFound($text)
72
-    {
73
-        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
-        abort($error['status'], $error['message']);
75
-    }
71
+	public function notFound($text)
72
+	{
73
+		$error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
+		abort($error['status'], $error['message']);
75
+	}
76 76
 
77
-    public function generalError()
78
-    {
79
-        $error = ['status' => 404, 'message' => 'Something went wrong'];
80
-        abort($error['status'], $error['message']);
81
-    }
77
+	public function generalError()
78
+	{
79
+		$error = ['status' => 404, 'message' => 'Something went wrong'];
80
+		abort($error['status'], $error['message']);
81
+	}
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/AclUser.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 block discarded – undo
6 6
 
7 7
 class AclUser extends User {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'users';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
13
-    protected $guarded  = ['id'];
14
-    protected $fillable = ['name', 'email', 'password'];
15
-    protected $appends  = ['permissions'];
9
+	use SoftDeletes;
10
+	protected $table    = 'users';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['password', 'remember_token','deleted_at'];
13
+	protected $guarded  = ['id'];
14
+	protected $fillable = ['name', 'email', 'password'];
15
+	protected $appends  = ['permissions'];
16 16
     
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
+	}
21 21
 
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
-    }
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
+	}
26 26
 
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
-    }
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
+	}
31 31
 
32
-    /**
33
-     * Encrypt the password attribute before
34
-     * saving it in the storage.
35
-     * 
36
-     * @param string $value 
37
-     */
38
-    public function setPasswordAttribute($value)
39
-    {
40
-        $this->attributes['password'] = bcrypt($value);
41
-    }
32
+	/**
33
+	 * Encrypt the password attribute before
34
+	 * saving it in the storage.
35
+	 * 
36
+	 * @param string $value 
37
+	 */
38
+	public function setPasswordAttribute($value)
39
+	{
40
+		$this->attributes['password'] = bcrypt($value);
41
+	}
42 42
 
43
-    public function logs()
44
-    {
45
-        return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id');
46
-    }
43
+	public function logs()
44
+	{
45
+		return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id');
46
+	}
47 47
 
48
-    public function groups()
49
-    {
50
-        return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
-    }
48
+	public function groups()
49
+	{
50
+		return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
+	}
52 52
 
53
-    public function getPermissionsAttribute()
54
-    {
55
-        $permissions = [];
56
-        foreach ($this->groups as $group)
57
-        {
58
-            $group->permissions->each(function ($permission) use (&$permissions){
59
-                $permissions[$permission->model][$permission->id] = $permission->name;
60
-            });
61
-        }
53
+	public function getPermissionsAttribute()
54
+	{
55
+		$permissions = [];
56
+		foreach ($this->groups as $group)
57
+		{
58
+			$group->permissions->each(function ($permission) use (&$permissions){
59
+				$permissions[$permission->model][$permission->id] = $permission->name;
60
+			});
61
+		}
62 62
 
63
-        return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
-    }
63
+		return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
+	}
65 65
 
66
-    public static function boot()
67
-    {
68
-        parent::boot();
69
-        parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
70
-    }
66
+	public static function boot()
67
+	{
68
+		parent::boot();
69
+		parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
70
+	}
71 71
 }
Please login to merge, or discard this patch.
Modules/V1/Acl/Database/Migrations/2015_12_20_124154_password_resets.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,27 +5,27 @@
 block discarded – undo
5 5
 
6 6
 class PasswordResets extends Migration
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function up()
14
-    {
15
-        Schema::create('password_resets', function (Blueprint $table) {
16
-            $table->string('email')->index();
17
-            $table->string('token')->index();
18
-            $table->timestamp('created_at');
19
-        });
20
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function up()
14
+	{
15
+		Schema::create('password_resets', function (Blueprint $table) {
16
+			$table->string('email')->index();
17
+			$table->string('token')->index();
18
+			$table->timestamp('created_at');
19
+		});
20
+	}
21 21
 
22
-    /**
23
-     * Reverse the migrations.
24
-     *
25
-     * @return void
26
-     */
27
-    public function down()
28
-    {
29
-        Schema::drop('password_resets');
30
-    }
22
+	/**
23
+	 * Reverse the migrations.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function down()
28
+	{
29
+		Schema::drop('password_resets');
30
+	}
31 31
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Migrations/2015_12_20_124153_users.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('users', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100)->nullable();
18
-            $table->string('email')->unique();
19
-            $table->string('password', 60);
20
-            $table->boolean('blocked', 0);
21
-            $table->softDeletes();
22
-            $table->rememberToken();
23
-            $table->timestamps();
24
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100)->nullable();
18
+			$table->string('email')->unique();
19
+			$table->string('password', 60);
20
+			$table->boolean('blocked', 0);
21
+			$table->softDeletes();
22
+			$table->rememberToken();
23
+			$table->timestamps();
24
+		});
25 25
 	}
26 26
 
27 27
 	/**
Please login to merge, or discard this patch.
src/ApiSkeletonServiceProvider.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 
7 7
 class ApiSkeletonServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Perform post-registration booting of services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->publishes([
17
-            __DIR__.'/Modules'               => app_path('Modules'),
18
-            __DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
-            ]);
20
-    }
9
+	/**
10
+	 * Perform post-registration booting of services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->publishes([
17
+			__DIR__.'/Modules'               => app_path('Modules'),
18
+			__DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
+			]);
20
+	}
21 21
 
22
-    /**
23
-     * Register any package services.
24
-     *
25
-     * @return void
26
-     */
27
-    public function register()
28
-    {
29
-        //
30
-    }
22
+	/**
23
+	 * Register any package services.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function register()
28
+	{
29
+		//
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/ModelObservers/AclGroupObserver.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -5,65 +5,65 @@
 block discarded – undo
5 5
  */
6 6
 class AclGroupObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12 12
 
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17 17
 
18
-    public function creating($model)
19
-    {
20
-        //
21
-    }
18
+	public function creating($model)
19
+	{
20
+		//
21
+	}
22 22
 
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27 27
 
28
-    /**
29
-     * Prevent updating of the admin group.
30
-     * 
31
-     * @param  object $model the model beign updated.
32
-     * @return void
33
-     */
34
-    public function updating($model)
35
-    {
36
-        if ($model->getOriginal()['name'] == 'Admin') 
37
-        {
38
-            \ErrorHandler::noPermissions();
39
-        }
40
-    }
28
+	/**
29
+	 * Prevent updating of the admin group.
30
+	 * 
31
+	 * @param  object $model the model beign updated.
32
+	 * @return void
33
+	 */
34
+	public function updating($model)
35
+	{
36
+		if ($model->getOriginal()['name'] == 'Admin') 
37
+		{
38
+			\ErrorHandler::noPermissions();
39
+		}
40
+	}
41 41
 
42
-    public function updated($model)
43
-    {
44
-        //
45
-    }
42
+	public function updated($model)
43
+	{
44
+		//
45
+	}
46 46
 
47
-    /**
48
-     * Soft delete the associated permissions to the deleted group
49
-     * and prevent deleting the admin group.
50
-     * 
51
-     * @param  object $model the delted model.
52
-     * @return void
53
-     */
54
-    public function deleting($model)
55
-    {
56
-        if ($model->getOriginal()['name'] == 'Admin') 
57
-        {
58
-            \ErrorHandler::noPermissions();
59
-        }
47
+	/**
48
+	 * Soft delete the associated permissions to the deleted group
49
+	 * and prevent deleting the admin group.
50
+	 * 
51
+	 * @param  object $model the delted model.
52
+	 * @return void
53
+	 */
54
+	public function deleting($model)
55
+	{
56
+		if ($model->getOriginal()['name'] == 'Admin') 
57
+		{
58
+			\ErrorHandler::noPermissions();
59
+		}
60 60
 
61
-        \DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()')));
62
-    }
61
+		\DB::table('groups_permissions')->where('group_id', $model->id)->update(array('deleted_at' => \DB::raw('NOW()')));
62
+	}
63 63
 
64
-    public function deleted($model)
65
-    {
66
-        //
67
-    }
64
+	public function deleted($model)
65
+	{
66
+		//
67
+	}
68 68
 
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -4,244 +4,244 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Check if the logged in user or the given user 
19
-     * has the given permissions on the given model.
20
-     * 
21
-     * @param  string  $nameOfPermission
22
-     * @param  string  $model            
23
-     * @param  boolean $user
24
-     * @return boolean
25
-     */
26
-    public function can($nameOfPermission, $model, $user = false )
27
-    {       
28
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
-        $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
-            $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Check if the logged in user or the given user 
19
+	 * has the given permissions on the given model.
20
+	 * 
21
+	 * @param  string  $nameOfPermission
22
+	 * @param  string  $model            
23
+	 * @param  boolean $user
24
+	 * @return boolean
25
+	 */
26
+	public function can($nameOfPermission, $model, $user = false )
27
+	{       
28
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
+		$permissions = [];
30
+		\Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
+			$permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
+		});
33 33
         
34
-        return in_array($nameOfPermission, $permissions);
35
-    }
36
-
37
-    /**
38
-     * Check if the logged in user has the given group.
39
-     * 
40
-     * @param  string  $groupName
41
-     * @return boolean
42
-     */
43
-    public function hasGroup($groupName)
44
-    {
45
-        $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
-        return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
-    }
48
-
49
-    /**
50
-     * Assign the given group ids to the given user.
51
-     * 
52
-     * @param  integer $user_id    
53
-     * @param  array   $group_ids
54
-     * @return object
55
-     */
56
-    public function assignGroups($user_id, $group_ids)
57
-    {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
59
-            $user = \Core::users()->find($user_id);
60
-            $user->groups()->detach();
61
-            $user->groups()->attach($group_ids);
62
-        });
63
-
64
-        return \Core::users()->find($user_id);
65
-    }
66
-
67
-    /**
68
-     * Handle a login request to the application.
69
-     * 
70
-     * @param  array   $credentials    
71
-     * @param  boolean $adminLogin
72
-     * @return string
73
-     */
74
-    public function login($credentials, $adminLogin = false)
75
-    {
76
-        if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
-        {
78
-            \ErrorHandler::loginFailed();
79
-        }
80
-        else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
-        {
82
-            \ErrorHandler::loginFailed();
83
-        }
84
-        else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
-        {
86
-            \ErrorHandler::loginFailed();
87
-        }
88
-        else if ($user->blocked)
89
-        {
90
-            \ErrorHandler::userIsBlocked();
91
-        }
92
-        else if ($token = \JWTAuth::attempt($credentials))
93
-        {
94
-            return $token;
95
-        }
96
-        else
97
-        {
98
-            \ErrorHandler::loginFailed();
99
-        }
100
-    }
101
-
102
-    /**
103
-     * Handle a registration request.
104
-     * 
105
-     * @param  array $credentials
106
-     * @return string
107
-     */
108
-    public function register($credentials)
109
-    {
110
-        return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
111
-    }
112
-
113
-    /**
114
-     * Logout the user.
115
-     * 
116
-     * @return boolean
117
-     */
118
-    public function logout()
119
-    {
120
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
121
-    }
122
-
123
-    /**
124
-     * Block the user.
125
-     *
126
-     * @param  integer $user_id
127
-     * @return object
128
-     */
129
-    public function block($user_id)
130
-    {
131
-        if ( ! $user = \Core::users()->find($user_id)) 
132
-        {
133
-            \ErrorHandler::notFound('user');
134
-        }
135
-        if ( ! $this->hasGroup('Admin'))
136
-        {
137
-            \ErrorHandler::noPermissions();
138
-        }
139
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
140
-        {
141
-            \ErrorHandler::noPermissions();
142
-        }
143
-        else if ($user->groups->lists('name')->search('Admin', true) !== false) 
144
-        {
145
-            \ErrorHandler::noPermissions();
146
-        }
147
-
148
-        $user->blocked = 1;
149
-        $user->save();
34
+		return in_array($nameOfPermission, $permissions);
35
+	}
36
+
37
+	/**
38
+	 * Check if the logged in user has the given group.
39
+	 * 
40
+	 * @param  string  $groupName
41
+	 * @return boolean
42
+	 */
43
+	public function hasGroup($groupName)
44
+	{
45
+		$groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
+		return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
+	}
48
+
49
+	/**
50
+	 * Assign the given group ids to the given user.
51
+	 * 
52
+	 * @param  integer $user_id    
53
+	 * @param  array   $group_ids
54
+	 * @return object
55
+	 */
56
+	public function assignGroups($user_id, $group_ids)
57
+	{
58
+		\DB::transaction(function () use ($user_id, $group_ids) {
59
+			$user = \Core::users()->find($user_id);
60
+			$user->groups()->detach();
61
+			$user->groups()->attach($group_ids);
62
+		});
63
+
64
+		return \Core::users()->find($user_id);
65
+	}
66
+
67
+	/**
68
+	 * Handle a login request to the application.
69
+	 * 
70
+	 * @param  array   $credentials    
71
+	 * @param  boolean $adminLogin
72
+	 * @return string
73
+	 */
74
+	public function login($credentials, $adminLogin = false)
75
+	{
76
+		if ( ! $user = \Core::users()->first(['email' => $credentials['email']])) 
77
+		{
78
+			\ErrorHandler::loginFailed();
79
+		}
80
+		else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
81
+		{
82
+			\ErrorHandler::loginFailed();
83
+		}
84
+		else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
85
+		{
86
+			\ErrorHandler::loginFailed();
87
+		}
88
+		else if ($user->blocked)
89
+		{
90
+			\ErrorHandler::userIsBlocked();
91
+		}
92
+		else if ($token = \JWTAuth::attempt($credentials))
93
+		{
94
+			return $token;
95
+		}
96
+		else
97
+		{
98
+			\ErrorHandler::loginFailed();
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * Handle a registration request.
104
+	 * 
105
+	 * @param  array $credentials
106
+	 * @return string
107
+	 */
108
+	public function register($credentials)
109
+	{
110
+		return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
111
+	}
112
+
113
+	/**
114
+	 * Logout the user.
115
+	 * 
116
+	 * @return boolean
117
+	 */
118
+	public function logout()
119
+	{
120
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
121
+	}
122
+
123
+	/**
124
+	 * Block the user.
125
+	 *
126
+	 * @param  integer $user_id
127
+	 * @return object
128
+	 */
129
+	public function block($user_id)
130
+	{
131
+		if ( ! $user = \Core::users()->find($user_id)) 
132
+		{
133
+			\ErrorHandler::notFound('user');
134
+		}
135
+		if ( ! $this->hasGroup('Admin'))
136
+		{
137
+			\ErrorHandler::noPermissions();
138
+		}
139
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
140
+		{
141
+			\ErrorHandler::noPermissions();
142
+		}
143
+		else if ($user->groups->lists('name')->search('Admin', true) !== false) 
144
+		{
145
+			\ErrorHandler::noPermissions();
146
+		}
147
+
148
+		$user->blocked = 1;
149
+		$user->save();
150 150
         
151
-        return $user;
152
-    }
153
-
154
-    /**
155
-     * Unblock the user.
156
-     *
157
-     * @param  integer $user_id
158
-     * @return object
159
-     */
160
-    public function unblock($user_id)
161
-    {
162
-        if ( ! $this->hasGroup('Admin'))
163
-        {
164
-            \ErrorHandler::noPermissions();
165
-        }
166
-
167
-        $user          = \Core::users()->find($user_id);
168
-        $user->blocked = 0;
169
-        $user->save();
170
-
171
-        return $user;
172
-    }
173
-
174
-    /**
175
-     * Handle the editing of the user profile.
176
-     * 
177
-     * @param  array $profile
178
-     * @return object
179
-     */
180
-    public function editProfile($profile)
181
-    {
182
-        unset($profile['email']);
183
-        unset($profile['password']);
184
-        $profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
151
+		return $user;
152
+	}
153
+
154
+	/**
155
+	 * Unblock the user.
156
+	 *
157
+	 * @param  integer $user_id
158
+	 * @return object
159
+	 */
160
+	public function unblock($user_id)
161
+	{
162
+		if ( ! $this->hasGroup('Admin'))
163
+		{
164
+			\ErrorHandler::noPermissions();
165
+		}
166
+
167
+		$user          = \Core::users()->find($user_id);
168
+		$user->blocked = 0;
169
+		$user->save();
170
+
171
+		return $user;
172
+	}
173
+
174
+	/**
175
+	 * Handle the editing of the user profile.
176
+	 * 
177
+	 * @param  array $profile
178
+	 * @return object
179
+	 */
180
+	public function editProfile($profile)
181
+	{
182
+		unset($profile['email']);
183
+		unset($profile['password']);
184
+		$profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
185 185
         
186
-        return $this->save($profile);
187
-    }
188
-
189
-    /**
190
-     * Send a reset link to the given user.
191
-     *
192
-     * @param  string  $url
193
-     * @param  string  $email
194
-     * @return void
195
-     */
196
-    public function sendReset($email, $url)
197
-    {
198
-        view()->composer('auth.emails.password', function($view) use ($url) {
199
-            $view->with(['url' => $url]);
200
-        });
201
-
202
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
203
-            $message->subject('Your Password Reset Link');
204
-        });
205
-
206
-        switch ($response) 
207
-        {
208
-            case \Password::INVALID_USER:
209
-                \ErrorHandler::notFound('email');
210
-        }
211
-    }
212
-
213
-    /**
214
-     * Reset the given user's password.
215
-     *
216
-     * @param  array  $credentials
217
-     * @return integer
218
-     */
219
-    public function resetPassword($credentials)
220
-    {
221
-        $token    = false;
222
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
223
-            $user->password = bcrypt($password);
224
-            $user->save();
225
-
226
-            $token = \JWTAuth::fromUser($user);
227
-        });
228
-
229
-
230
-        switch ($response) {
231
-            case \Password::PASSWORD_RESET:
232
-                return $token;
186
+		return $this->save($profile);
187
+	}
188
+
189
+	/**
190
+	 * Send a reset link to the given user.
191
+	 *
192
+	 * @param  string  $url
193
+	 * @param  string  $email
194
+	 * @return void
195
+	 */
196
+	public function sendReset($email, $url)
197
+	{
198
+		view()->composer('auth.emails.password', function($view) use ($url) {
199
+			$view->with(['url' => $url]);
200
+		});
201
+
202
+		$response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
203
+			$message->subject('Your Password Reset Link');
204
+		});
205
+
206
+		switch ($response) 
207
+		{
208
+			case \Password::INVALID_USER:
209
+				\ErrorHandler::notFound('email');
210
+		}
211
+	}
212
+
213
+	/**
214
+	 * Reset the given user's password.
215
+	 *
216
+	 * @param  array  $credentials
217
+	 * @return integer
218
+	 */
219
+	public function resetPassword($credentials)
220
+	{
221
+		$token    = false;
222
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
223
+			$user->password = bcrypt($password);
224
+			$user->save();
225
+
226
+			$token = \JWTAuth::fromUser($user);
227
+		});
228
+
229
+
230
+		switch ($response) {
231
+			case \Password::PASSWORD_RESET:
232
+				return $token;
233 233
                 
234
-            case \Password::INVALID_TOKEN:
235
-                \ErrorHandler::invalidResetToken('token');
234
+			case \Password::INVALID_TOKEN:
235
+				\ErrorHandler::invalidResetToken('token');
236 236
 
237
-            case \Password::INVALID_PASSWORD:
238
-                \ErrorHandler::invalidResetPassword('email');
237
+			case \Password::INVALID_PASSWORD:
238
+				\ErrorHandler::invalidResetPassword('email');
239 239
 
240
-            case \Password::INVALID_USER:
241
-                \ErrorHandler::notFound('user');
240
+			case \Password::INVALID_USER:
241
+				\ErrorHandler::notFound('user');
242 242
 
243
-            default:
244
-                \ErrorHandler::generalError();
245
-        }
246
-    }
243
+			default:
244
+				\ErrorHandler::generalError();
245
+		}
246
+	}
247 247
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/ModelObservers/SettingsObserver.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -5,59 +5,59 @@
 block discarded – undo
5 5
  */
6 6
 class SettingsObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    /**
19
-     * Prevent the creating of the settings.
20
-     * 
21
-     * @param  object $model the model beign created.
22
-     * @return void
23
-     */
24
-    public function creating($model)
25
-    {
26
-        \ErrorHandler::cannotCreateSetting();
27
-    }
28
-
29
-    public function created($model)
30
-    {
31
-        //
32
-    }
33
-
34
-    /**
35
-     * Prevent updating of the setting key.
36
-     * 
37
-     * @param  object $model the model beign updated.
38
-     * @return void
39
-     */
40
-    public function updating($model)
41
-    {
42
-        if ($model->getOriginal()['key'] !== $model->key) 
43
-        {
44
-            \ErrorHandler::cannotUpdateSettingKey();
45
-        }
46
-    }
47
-
48
-    public function updated($model)
49
-    {
50
-        //
51
-    }
52
-
53
-    public function deleting($model)
54
-    {
55
-        //
56
-    }
57
-
58
-    public function deleted($model)
59
-    {
60
-        //
61
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	/**
19
+	 * Prevent the creating of the settings.
20
+	 * 
21
+	 * @param  object $model the model beign created.
22
+	 * @return void
23
+	 */
24
+	public function creating($model)
25
+	{
26
+		\ErrorHandler::cannotCreateSetting();
27
+	}
28
+
29
+	public function created($model)
30
+	{
31
+		//
32
+	}
33
+
34
+	/**
35
+	 * Prevent updating of the setting key.
36
+	 * 
37
+	 * @param  object $model the model beign updated.
38
+	 * @return void
39
+	 */
40
+	public function updating($model)
41
+	{
42
+		if ($model->getOriginal()['key'] !== $model->key) 
43
+		{
44
+			\ErrorHandler::cannotUpdateSettingKey();
45
+		}
46
+	}
47
+
48
+	public function updated($model)
49
+	{
50
+		//
51
+	}
52
+
53
+	public function deleting($model)
54
+	{
55
+		//
56
+	}
57
+
58
+	public function deleted($model)
59
+	{
60
+		//
61
+	}
62 62
 
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Notifications/Repositories/NotificationRepository.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,23 +15,23 @@
 block discarded – undo
15 15
 	}
16 16
 
17 17
 	/**
18
-     * Set the notification notified to true.
19
-     * 
20
-     * @param  integer  $id
21
-     * @return object
22
-     */
23
-    public function notified($id)
24
-    {
25
-        return $this->save(['id' => $id, 'notified' => 1]);
26
-    }
18
+	 * Set the notification notified to true.
19
+	 * 
20
+	 * @param  integer  $id
21
+	 * @return object
22
+	 */
23
+	public function notified($id)
24
+	{
25
+		return $this->save(['id' => $id, 'notified' => 1]);
26
+	}
27 27
 
28
-    /**
29
-     * Set the notification notified to all.
30
-     * 
31
-     * @return void
32
-     */
33
-    public function notifyAll()
34
-    {
35
-        \Core::notifications()->update(false, ['notified' => 1], 'notified');
36
-    }
28
+	/**
29
+	 * Set the notification notified to all.
30
+	 * 
31
+	 * @return void
32
+	 */
33
+	public function notifyAll()
34
+	{
35
+		\Core::notifications()->update(false, ['notified' => 1], 'notified');
36
+	}
37 37
 }
Please login to merge, or discard this patch.