@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | use App\User; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 5 | -use Illuminate\Notifications\Notifiable; |
|
| 6 | 5 | use Laravel\Passport\HasApiTokens; |
| 7 | 6 | |
| 8 | 7 | class AclUser extends User { |
@@ -67,8 +67,7 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $tokens[] = $device->device_token; |
| 70 | - } |
|
| 71 | - catch (\Exception $e) |
|
| 70 | + } catch (\Exception $e) |
|
| 72 | 71 | { |
| 73 | 72 | $device->forceDelete(); |
| 74 | 73 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Get the profile picture url. |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 33 | + /** |
|
| 34 | + * Get the profile picture url. |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | 37 | public function getProfilePictureAttribute($value) |
| 38 | 38 | { |
| 39 | 39 | return url(\Storage::url($value)); |
@@ -89,30 +89,30 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | - public function routeNotificationForFCM() |
|
| 93 | - { |
|
| 94 | - $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
| 95 | - $tokens = []; |
|
| 96 | - |
|
| 97 | - foreach ($devices as $device) |
|
| 98 | - { |
|
| 99 | - try |
|
| 100 | - { |
|
| 101 | - if (\Core::users()->accessTokenExpiredOrRevoked($device->access_token)) |
|
| 102 | - { |
|
| 103 | - continue; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $tokens[] = $device->device_token; |
|
| 107 | - } |
|
| 108 | - catch (\Exception $e) |
|
| 109 | - { |
|
| 110 | - $device->forceDelete(); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $tokens; |
|
| 115 | - } |
|
| 92 | + public function routeNotificationForFCM() |
|
| 93 | + { |
|
| 94 | + $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
| 95 | + $tokens = []; |
|
| 96 | + |
|
| 97 | + foreach ($devices as $device) |
|
| 98 | + { |
|
| 99 | + try |
|
| 100 | + { |
|
| 101 | + if (\Core::users()->accessTokenExpiredOrRevoked($device->access_token)) |
|
| 102 | + { |
|
| 103 | + continue; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $tokens[] = $device->device_token; |
|
| 107 | + } |
|
| 108 | + catch (\Exception $e) |
|
| 109 | + { |
|
| 110 | + $device->forceDelete(); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $tokens; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * The channels the user receives notification broadcasts on. |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace App\Modules\Acl\Repositories; |
| 2 | 2 | |
| 3 | 3 | use App\Modules\Core\AbstractRepositories\AbstractRepository; |
| 4 | -use Lcobucci\JWT\ValidationData; |
|
| 5 | 4 | use Illuminate\Support\Arr; |
| 6 | 5 | |
| 7 | 6 | class UserRepository extends AbstractRepository |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | public function confirmEmail($confirmationCode) |
| 295 | 295 | { |
| 296 | - if ( ! $user = $this->first(['confirmation_code' => $confirmationCode])) |
|
| 297 | - { |
|
| 298 | - \ErrorHandler::invalidConfirmationCode(); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $user->confirmed = 1; |
|
| 302 | - $user->confirmation_code = null; |
|
| 303 | - $user->save(); |
|
| 296 | + if ( ! $user = $this->first(['confirmation_code' => $confirmationCode])) |
|
| 297 | + { |
|
| 298 | + \ErrorHandler::invalidConfirmationCode(); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $user->confirmed = 1; |
|
| 302 | + $user->confirmation_code = null; |
|
| 303 | + $user->save(); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -375,23 +375,23 @@ discard block |
||
| 375 | 375 | $this->save($data); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Ensure access token hasn't expired or revoked. |
|
| 380 | - * |
|
| 381 | - * @param string $accessToken |
|
| 382 | - * @return boolean |
|
| 383 | - */ |
|
| 384 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
| 385 | - { |
|
| 386 | - $accessToken = json_decode($accessToken, true); |
|
| 378 | + /** |
|
| 379 | + * Ensure access token hasn't expired or revoked. |
|
| 380 | + * |
|
| 381 | + * @param string $accessToken |
|
| 382 | + * @return boolean |
|
| 383 | + */ |
|
| 384 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
| 385 | + { |
|
| 386 | + $accessToken = json_decode($accessToken, true); |
|
| 387 | 387 | |
| 388 | - if (\Carbon\Carbon::parse($accessToken['expires_at'])->isPast() || $accessToken['revoked']) |
|
| 389 | - { |
|
| 390 | - return true; |
|
| 391 | - } |
|
| 388 | + if (\Carbon\Carbon::parse($accessToken['expires_at'])->isPast() || $accessToken['revoked']) |
|
| 389 | + { |
|
| 390 | + return true; |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - return false; |
|
| 394 | - } |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * Revoke the given access token and all |
@@ -13,26 +13,26 @@ discard block |
||
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | 15 | Schema::create('users', function(Blueprint $table) { |
| 16 | - $table->increments('id'); |
|
| 17 | - $table->string('profile_picture', 150)->nullable(); |
|
| 18 | - $table->string('name', 100)->nullable(); |
|
| 19 | - $table->string('email')->unique(); |
|
| 20 | - $table->string('password', 60)->nullable(); |
|
| 21 | - $table->boolean('blocked')->default(0); |
|
| 22 | - $table->boolean('confirmed')->default(0); |
|
| 23 | - $table->string('confirmation_code')->nullable(); |
|
| 24 | - $table->string('locale', 2)->default('en'); |
|
| 25 | - $table->string('timezone', 50)->default('Africa/Cairo'); |
|
| 26 | - $table->softDeletes(); |
|
| 27 | - $table->rememberToken(); |
|
| 28 | - $table->timestamps(); |
|
| 29 | - }); |
|
| 16 | + $table->increments('id'); |
|
| 17 | + $table->string('profile_picture', 150)->nullable(); |
|
| 18 | + $table->string('name', 100)->nullable(); |
|
| 19 | + $table->string('email')->unique(); |
|
| 20 | + $table->string('password', 60)->nullable(); |
|
| 21 | + $table->boolean('blocked')->default(0); |
|
| 22 | + $table->boolean('confirmed')->default(0); |
|
| 23 | + $table->string('confirmation_code')->nullable(); |
|
| 24 | + $table->string('locale', 2)->default('en'); |
|
| 25 | + $table->string('timezone', 50)->default('Africa/Cairo'); |
|
| 26 | + $table->softDeletes(); |
|
| 27 | + $table->rememberToken(); |
|
| 28 | + $table->timestamps(); |
|
| 29 | + }); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Create Default users. |
| 33 | 33 | */ |
| 34 | 34 | \DB::table('users')->insertGetId( |
| 35 | - [ |
|
| 35 | + [ |
|
| 36 | 36 | 'name' => 'Admin', |
| 37 | 37 | 'email' => '[email protected]', |
| 38 | 38 | 'password' => bcrypt('123456'), |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | 'created_at' => \DB::raw('NOW()'), |
| 41 | 41 | 'updated_at' => \DB::raw('NOW()') |
| 42 | 42 | ] |
| 43 | - ); |
|
| 43 | + ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function saving($model) |
| 9 | 9 | { |
| 10 | - if ($model->isDirty('profile_picture')) |
|
| 11 | - { |
|
| 12 | - \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | - } |
|
| 10 | + if ($model->isDirty('profile_picture')) |
|
| 11 | + { |
|
| 12 | + \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | + } |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function saved($model) |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | return $next($request); |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | - $this->setSessions(); |
|
| 47 | - $this->checkPermission($route); |
|
| 48 | - $this->setRelations($route); |
|
| 46 | + $this->setSessions(); |
|
| 47 | + $this->checkPermission($route); |
|
| 48 | + $this->setRelations($route); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $user = \Auth::user(); |
| 222 | 222 | $permission = $permission !== 'index' ? $permission : 'list'; |
| 223 | 223 | $isPasswordClient = $user->token()->client->password_client; |
| 224 | - $this->updateLocaleAndTimezone($user); |
|
| 224 | + $this->updateLocaleAndTimezone($user); |
|
| 225 | 225 | |
| 226 | 226 | if ($user->blocked) |
| 227 | 227 | { |
@@ -287,32 +287,32 @@ discard block |
||
| 287 | 287 | $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Update the logged in user locale and time zone. |
|
| 292 | - * |
|
| 293 | - * @param object $user |
|
| 294 | - * @return void |
|
| 295 | - */ |
|
| 296 | - private function updateLocaleAndTimezone($user) |
|
| 297 | - { |
|
| 298 | - $update = false; |
|
| 299 | - $locale = \Session::get('locale'); |
|
| 300 | - $timezone = \Session::get('time-zone'); |
|
| 301 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) |
|
| 302 | - { |
|
| 303 | - $user->locale = $locale; |
|
| 304 | - $update = true; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - if ($timezone && $timezone !== $user->timezone) |
|
| 308 | - { |
|
| 309 | - $user->timezone = $timezone; |
|
| 310 | - $update = true; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if ($update) |
|
| 314 | - { |
|
| 315 | - $user->save(); |
|
| 316 | - } |
|
| 317 | - } |
|
| 290 | + /** |
|
| 291 | + * Update the logged in user locale and time zone. |
|
| 292 | + * |
|
| 293 | + * @param object $user |
|
| 294 | + * @return void |
|
| 295 | + */ |
|
| 296 | + private function updateLocaleAndTimezone($user) |
|
| 297 | + { |
|
| 298 | + $update = false; |
|
| 299 | + $locale = \Session::get('locale'); |
|
| 300 | + $timezone = \Session::get('time-zone'); |
|
| 301 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) |
|
| 302 | + { |
|
| 303 | + $user->locale = $locale; |
|
| 304 | + $update = true; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + if ($timezone && $timezone !== $user->timezone) |
|
| 308 | + { |
|
| 309 | + $user->timezone = $timezone; |
|
| 310 | + $update = true; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if ($update) |
|
| 314 | + { |
|
| 315 | + $user->save(); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | 318 | } |
@@ -307,7 +307,7 @@ |
||
| 307 | 307 | if ($timezone && $timezone !== $user->timezone) |
| 308 | 308 | { |
| 309 | 309 | $user->timezone = $timezone; |
| 310 | - $update = true; |
|
| 310 | + $update = true; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | if ($update) |
@@ -2,63 +2,63 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Media |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * Upload the given image. |
|
| 7 | - * |
|
| 8 | - * @param object $image |
|
| 9 | - * @param string $dir |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - public function uploadImage($image, $dir) |
|
| 13 | - { |
|
| 14 | - $image = \Image::make($image); |
|
| 15 | - return $this->saveImage($image, $dir); |
|
| 16 | - } |
|
| 5 | + /** |
|
| 6 | + * Upload the given image. |
|
| 7 | + * |
|
| 8 | + * @param object $image |
|
| 9 | + * @param string $dir |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + public function uploadImage($image, $dir) |
|
| 13 | + { |
|
| 14 | + $image = \Image::make($image); |
|
| 15 | + return $this->saveImage($image, $dir); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Upload the given image. |
|
| 20 | - * |
|
| 21 | - * @param object $image |
|
| 22 | - * @param string $dir |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function uploadImageBas64($image, $dir) |
|
| 26 | - { |
|
| 27 | - if ( ! strlen($image)) |
|
| 28 | - { |
|
| 29 | - return null; |
|
| 30 | - } |
|
| 18 | + /** |
|
| 19 | + * Upload the given image. |
|
| 20 | + * |
|
| 21 | + * @param object $image |
|
| 22 | + * @param string $dir |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function uploadImageBas64($image, $dir) |
|
| 26 | + { |
|
| 27 | + if ( ! strlen($image)) |
|
| 28 | + { |
|
| 29 | + return null; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
| 33 | - $image = \Image::make($base); |
|
| 32 | + $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
| 33 | + $image = \Image::make($base); |
|
| 34 | 34 | |
| 35 | - return $this->saveImage($image, $dir); |
|
| 36 | - } |
|
| 35 | + return $this->saveImage($image, $dir); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Delete the given image. |
|
| 40 | - * |
|
| 41 | - * @param object $path |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function deleteImage($path) |
|
| 45 | - { |
|
| 46 | - \Storage::delete($path); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Delete the given image. |
|
| 40 | + * |
|
| 41 | + * @param object $path |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function deleteImage($path) |
|
| 45 | + { |
|
| 46 | + \Storage::delete($path); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Save the given image. |
|
| 51 | - * |
|
| 52 | - * @param object $image |
|
| 53 | - * @param string $dir |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - protected function saveImage($image, $dir) |
|
| 57 | - { |
|
| 58 | - $imageName = 'image'.uniqid().time().'.jpg'; |
|
| 59 | - $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
| 60 | - \Storage::put($path, $image->stream()); |
|
| 49 | + /** |
|
| 50 | + * Save the given image. |
|
| 51 | + * |
|
| 52 | + * @param object $image |
|
| 53 | + * @param string $dir |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + protected function saveImage($image, $dir) |
|
| 57 | + { |
|
| 58 | + $imageName = 'image'.uniqid().time().'.jpg'; |
|
| 59 | + $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
| 60 | + \Storage::put($path, $image->stream()); |
|
| 61 | 61 | |
| 62 | - return $path; |
|
| 63 | - } |
|
| 62 | + return $path; |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -104,11 +104,11 @@ |
||
| 104 | 104 | abort($error['status'], $error['message']); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function invalidConfirmationCode() |
|
| 108 | - { |
|
| 109 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | - abort($error['status'], $error['message']); |
|
| 111 | - } |
|
| 107 | + public function invalidConfirmationCode() |
|
| 108 | + { |
|
| 109 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | + abort($error['status'], $error['message']); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | public function notFound($text) |
| 114 | 114 | { |
@@ -12,5 +12,5 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Broadcast::channel('users.{id}', function ($user, $id) { |
| 15 | - return (int) $user->id === (int) $id; |
|
| 15 | + return (int) $user->id === (int) $id; |
|
| 16 | 16 | }); |
@@ -11,6 +11,6 @@ |
||
| 11 | 11 | | |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -Broadcast::channel('users.{id}', function ($user, $id) { |
|
| 14 | +Broadcast::channel('users.{id}', function($user, $id) { |
|
| 15 | 15 | return (int) $user->id === (int) $id; |
| 16 | 16 | }); |