@@ -28,7 +28,7 @@ |
||
| 28 | 28 | * Get the notification's delivery channels. |
| 29 | 29 | * |
| 30 | 30 | * @param mixed $notifiable |
| 31 | - * @return array |
|
| 31 | + * @return string[] |
|
| 32 | 32 | */ |
| 33 | 33 | public function via($notifiable) |
| 34 | 34 | { |
@@ -6,7 +6,6 @@ |
||
| 6 | 6 | use Illuminate\Notifications\Notification; |
| 7 | 7 | use Illuminate\Contracts\Queue\ShouldQueue; |
| 8 | 8 | use Illuminate\Notifications\Messages\MailMessage; |
| 9 | -use Illuminate\Notifications\Messages\BroadcastMessage; |
|
| 10 | 9 | |
| 11 | 10 | class ResetPassword extends Notification implements ShouldQueue |
| 12 | 11 | { |
@@ -10,43 +10,43 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ResetPassword extends Notification implements ShouldQueue |
| 12 | 12 | { |
| 13 | - use Queueable; |
|
| 13 | + use Queueable; |
|
| 14 | 14 | |
| 15 | - protected $token; |
|
| 15 | + protected $token; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Create a new notification instance. |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - public function __construct($token) |
|
| 23 | - { |
|
| 24 | - $this->$token = $token; |
|
| 25 | - } |
|
| 17 | + /** |
|
| 18 | + * Create a new notification instance. |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + public function __construct($token) |
|
| 23 | + { |
|
| 24 | + $this->$token = $token; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Get the notification's delivery channels. |
|
| 29 | - * |
|
| 30 | - * @param mixed $notifiable |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function via($notifiable) |
|
| 34 | - { |
|
| 35 | - return ['mail']; |
|
| 36 | - } |
|
| 27 | + /** |
|
| 28 | + * Get the notification's delivery channels. |
|
| 29 | + * |
|
| 30 | + * @param mixed $notifiable |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function via($notifiable) |
|
| 34 | + { |
|
| 35 | + return ['mail']; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Get the mail representation of the notification. |
|
| 40 | - * |
|
| 41 | - * @param mixed $notifiable |
|
| 42 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 43 | - */ |
|
| 44 | - public function toMail($notifiable) |
|
| 45 | - { |
|
| 46 | - return (new MailMessage) |
|
| 47 | - ->subject('Reset passowrd') |
|
| 48 | - ->line('Reset passowrd') |
|
| 49 | - ->line('To reset your password click on the button below') |
|
| 50 | - ->action('Reset password', env('RESET_PASSWORD_URL') . '/' . $this->token); |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * Get the mail representation of the notification. |
|
| 40 | + * |
|
| 41 | + * @param mixed $notifiable |
|
| 42 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 43 | + */ |
|
| 44 | + public function toMail($notifiable) |
|
| 45 | + { |
|
| 46 | + return (new MailMessage) |
|
| 47 | + ->subject('Reset passowrd') |
|
| 48 | + ->line('Reset passowrd') |
|
| 49 | + ->line('To reset your password click on the button below') |
|
| 50 | + ->action('Reset password', env('RESET_PASSWORD_URL') . '/' . $this->token); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -47,6 +47,6 @@ |
||
| 47 | 47 | ->subject('Reset passowrd') |
| 48 | 48 | ->line('Reset passowrd') |
| 49 | 49 | ->line('To reset your password click on the button below') |
| 50 | - ->action('Reset password', env('RESET_PASSWORD_URL') . '/' . $this->token); |
|
| 50 | + ->action('Reset password', env('RESET_PASSWORD_URL').'/'.$this->token); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -2,27 +2,27 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * List of error messages used in core module. |
|
| 7 | - */ |
|
| 8 | - 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
| 9 | - 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
| 10 | - 'noPermissions' => 'لا توجد صلاحية', |
|
| 11 | - 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
| 12 | - 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
| 13 | - 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
| 14 | - 'connectionError' => 'خطأ في الاتصال', |
|
| 15 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 16 | - 'dbQueryError' => 'خطا في البيانات', |
|
| 17 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 18 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 19 | - 'userIsBlocked' => 'لقد تم حظرك', |
|
| 20 | - 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
| 21 | - 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
| 22 | - 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
| 23 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
| 24 | - 'generalError' => 'حدث خطا ما', |
|
| 25 | - 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
| 26 | - 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
| 5 | + /** |
|
| 6 | + * List of error messages used in core module. |
|
| 7 | + */ |
|
| 8 | + 'unAuthorized' => 'من فضلك قم بتسجيل الدخول', |
|
| 9 | + 'invalidRefreshToken' => 'رمز التحديث غير صالح', |
|
| 10 | + 'noPermissions' => 'لا توجد صلاحية', |
|
| 11 | + 'loginFailed' => 'خطأ في البريد لاكتروني او كلمة المرور', |
|
| 12 | + 'noSocialEmail' => 'لا يمكن الحصول علي تابريد الاكتروني', |
|
| 13 | + 'userAlreadyRegistered' => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر', |
|
| 14 | + 'connectionError' => 'خطأ في الاتصال', |
|
| 15 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 16 | + 'dbQueryError' => 'خطا في البيانات', |
|
| 17 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 18 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 19 | + 'userIsBlocked' => 'لقد تم حظرك', |
|
| 20 | + 'invalidResetToken' => 'رمز تعديل كلمة المرور خطا', |
|
| 21 | + 'invalidResetPassword' => 'خطا في نعديل كلمة المرور', |
|
| 22 | + 'invalidOldPassword' => 'كلمة السر القديمه خطا', |
|
| 23 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
| 24 | + 'generalError' => 'حدث خطا ما', |
|
| 25 | + 'emailNotConfirmed' => 'بريدك الاكتروني غير مفعل', |
|
| 26 | + 'emailAlreadyConfirmed' => 'البريد الاكتروني مفع بالقعل' |
|
| 27 | 27 | |
| 28 | 28 | ]; |
| 29 | 29 | \ No newline at end of file |
@@ -2,27 +2,27 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * List of error messages used in core module. |
|
| 7 | - */ |
|
| 8 | - 'unAuthorized' => 'Please login before any action', |
|
| 9 | - 'invalidRefreshToken' => 'Invalid refresh token', |
|
| 10 | - 'noPermissions' => 'No permissions', |
|
| 11 | - 'loginFailed' => 'Wrong mail or password', |
|
| 12 | - 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
| 13 | - 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
| 14 | - 'connectionError' => 'Connection error', |
|
| 15 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 16 | - 'dbQueryError' => 'Please check the given inputes', |
|
| 17 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 18 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 19 | - 'userIsBlocked' => 'You have been blocked', |
|
| 20 | - 'invalidResetToken' => 'Reset password token is invalid', |
|
| 21 | - 'invalidResetPassword' => 'Reset password is invalid', |
|
| 22 | - 'invalidOldPassword' => 'Old password is invalid', |
|
| 23 | - 'notFound' => 'The requested :replace not found', |
|
| 24 | - 'generalError' => 'Something went wrong', |
|
| 25 | - 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
| 26 | - 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
| 5 | + /** |
|
| 6 | + * List of error messages used in core module. |
|
| 7 | + */ |
|
| 8 | + 'unAuthorized' => 'Please login before any action', |
|
| 9 | + 'invalidRefreshToken' => 'Invalid refresh token', |
|
| 10 | + 'noPermissions' => 'No permissions', |
|
| 11 | + 'loginFailed' => 'Wrong mail or password', |
|
| 12 | + 'noSocialEmail' => 'Couldn\'t retrieve email', |
|
| 13 | + 'userAlreadyRegistered' => 'User already registered. Please login using email and password', |
|
| 14 | + 'connectionError' => 'Connection error', |
|
| 15 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 16 | + 'dbQueryError' => 'Please check the given inputes', |
|
| 17 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 18 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 19 | + 'userIsBlocked' => 'You have been blocked', |
|
| 20 | + 'invalidResetToken' => 'Reset password token is invalid', |
|
| 21 | + 'invalidResetPassword' => 'Reset password is invalid', |
|
| 22 | + 'invalidOldPassword' => 'Old password is invalid', |
|
| 23 | + 'notFound' => 'The requested :replace not found', |
|
| 24 | + 'generalError' => 'Something went wrong', |
|
| 25 | + 'emailNotConfirmed' => 'Your email isn\'t confirmed', |
|
| 26 | + 'emailAlreadyConfirmed' => 'Your email is already confirmed' |
|
| 27 | 27 | |
| 28 | 28 | ]; |
| 29 | 29 | \ No newline at end of file |
@@ -13,31 +13,31 @@ |
||
| 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(1); |
|
| 23 | - $table->string('confirmation_code')->nullable(); |
|
| 24 | - $table->softDeletes(); |
|
| 25 | - $table->rememberToken(); |
|
| 26 | - $table->timestamps(); |
|
| 27 | - }); |
|
| 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(1); |
|
| 23 | + $table->string('confirmation_code')->nullable(); |
|
| 24 | + $table->softDeletes(); |
|
| 25 | + $table->rememberToken(); |
|
| 26 | + $table->timestamps(); |
|
| 27 | + }); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Create Default users. |
| 31 | 31 | */ |
| 32 | 32 | \DB::table('users')->insertGetId( |
| 33 | - [ |
|
| 33 | + [ |
|
| 34 | 34 | 'name' => 'Admin', |
| 35 | 35 | 'email' => '[email protected]', |
| 36 | 36 | 'password' => bcrypt('123456'), |
| 37 | 37 | 'created_at' => \DB::raw('NOW()'), |
| 38 | 38 | 'updated_at' => \DB::raw('NOW()') |
| 39 | 39 | ] |
| 40 | - ); |
|
| 40 | + ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('users', function (Blueprint $table) { |
|
| 15 | + Schema::create('users', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | 17 | $table->string('profile_picture', 150)->nullable(); |
| 18 | 18 | $table->string('name', 100)->nullable(); |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\V1\Acl\AclUser::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 4 | + return [ |
|
| 5 | 5 | 'profile_picture' => 'http://lorempixel.com/400/200/', |
| 6 | 6 | 'name' => $faker->name(), |
| 7 | 7 | 'email' => $faker->safeEmail(), |
| 8 | 8 | 'password' => bcrypt(123456), |
| 9 | 9 | 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
| 10 | 10 | 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
| 11 | - ]; |
|
| 11 | + ]; |
|
| 12 | 12 | }); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$factory->define(App\Modules\V1\Acl\AclUser::class, function (Faker\Generator $faker) { |
|
| 3 | +$factory->define(App\Modules\V1\Acl\AclUser::class, function(Faker\Generator $faker) { |
|
| 4 | 4 | return [ |
| 5 | 5 | 'profile_picture' => 'http://lorempixel.com/400/200/', |
| 6 | 6 | 'name' => $faker->name(), |
@@ -8,281 +8,281 @@ |
||
| 8 | 8 | |
| 9 | 9 | class UsersController extends BaseApiController |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name of the model that is used by the base api controller |
|
| 13 | - * to preform actions like (add, edit ... etc). |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $model = 'users'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * List of all route actions that the base api controller |
|
| 20 | - * will skip permissions check for them. |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * List of all route actions that the base api controller |
|
| 27 | - * will skip login check for them. |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The validations rules used by the base api controller |
|
| 34 | - * to check before add. |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $validationRules = [ |
|
| 38 | - 'name' => 'nullable|string', |
|
| 39 | - 'email' => 'required|email|unique:users,email,{id}', |
|
| 40 | - 'password' => 'nullable|min:6' |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * The loginProxy implementation. |
|
| 45 | - * |
|
| 46 | - * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
| 47 | - */ |
|
| 48 | - protected $loginProxy; |
|
| 49 | - |
|
| 50 | - public function __construct(LoginProxy $loginProxy) |
|
| 51 | - { |
|
| 52 | - $this->loginProxy = $loginProxy; |
|
| 53 | - parent::__construct(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Return the logged in user account. |
|
| 58 | - * |
|
| 59 | - * @return \Illuminate\Http\Response |
|
| 60 | - */ |
|
| 61 | - public function account() |
|
| 62 | - { |
|
| 63 | - return \Response::json($this->repo->account($this->relations), 200); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Block the user. |
|
| 68 | - * |
|
| 69 | - * @param integer $id Id of the user. |
|
| 70 | - * @return \Illuminate\Http\Response |
|
| 71 | - */ |
|
| 72 | - public function block($id) |
|
| 73 | - { |
|
| 74 | - return \Response::json($this->repo->block($id), 200); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Unblock the user. |
|
| 79 | - * |
|
| 80 | - * @param integer $id Id of the user. |
|
| 81 | - * @return \Illuminate\Http\Response |
|
| 82 | - */ |
|
| 83 | - public function unblock($id) |
|
| 84 | - { |
|
| 85 | - return \Response::json($this->repo->unblock($id), 200); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Logout the user. |
|
| 90 | - * |
|
| 91 | - * @return \Illuminate\Http\Response |
|
| 92 | - */ |
|
| 93 | - public function logout() |
|
| 94 | - { |
|
| 95 | - return \Response::json($this->loginProxy->logout(), 200); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Handle a registration request. |
|
| 100 | - * |
|
| 101 | - * @param \Illuminate\Http\Request $request |
|
| 102 | - * @return \Illuminate\Http\Response |
|
| 103 | - */ |
|
| 104 | - public function register(Request $request) |
|
| 105 | - { |
|
| 106 | - $this->validate($request, [ |
|
| 107 | - 'name' => 'nullable|string', |
|
| 108 | - 'email' => 'required|email|unique:users,email,{id}', |
|
| 109 | - 'password' => 'required|min:6' |
|
| 110 | - ]); |
|
| 111 | - |
|
| 112 | - return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Handle a login request to the application. |
|
| 117 | - * |
|
| 118 | - * @param \Illuminate\Http\Request $request |
|
| 119 | - * @return \Illuminate\Http\Response |
|
| 120 | - */ |
|
| 121 | - public function login(Request $request) |
|
| 122 | - { |
|
| 123 | - $this->validate($request, [ |
|
| 124 | - 'email' => 'required|email', |
|
| 125 | - 'password' => 'required|min:6' |
|
| 126 | - ]); |
|
| 127 | - |
|
| 128 | - return \Response::json($this->loginProxy->login($request->only('email', 'password')), 200); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Handle a social login request of the none admin to the application. |
|
| 133 | - * |
|
| 134 | - * @param \Illuminate\Http\Request $request |
|
| 135 | - * @return \Illuminate\Http\Response |
|
| 136 | - */ |
|
| 137 | - public function loginSocial(Request $request) |
|
| 138 | - { |
|
| 139 | - $this->validate($request, [ |
|
| 140 | - 'auth_code' => 'required_without:access_token', |
|
| 141 | - 'access_token' => 'required_without:auth_code', |
|
| 142 | - 'type' => 'required|in:facebook,google' |
|
| 143 | - ]); |
|
| 144 | - |
|
| 145 | - return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Assign the given groups to the given user. |
|
| 150 | - * |
|
| 151 | - * @param \Illuminate\Http\Request $request |
|
| 152 | - * @return \Illuminate\Http\Response |
|
| 153 | - */ |
|
| 154 | - public function assigngroups(Request $request) |
|
| 155 | - { |
|
| 156 | - $this->validate($request, [ |
|
| 157 | - 'group_ids' => 'required|exists:groups,id', |
|
| 158 | - 'user_id' => 'required|exists:users,id' |
|
| 159 | - ]); |
|
| 160 | - |
|
| 161 | - return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Send a reset link to the given user. |
|
| 166 | - * |
|
| 167 | - * @param \Illuminate\Http\Request $request |
|
| 168 | - * @return \Illuminate\Http\Response |
|
| 169 | - */ |
|
| 170 | - public function sendreset(Request $request) |
|
| 171 | - { |
|
| 172 | - $this->validate($request, ['email' => 'required|email']); |
|
| 173 | - |
|
| 174 | - return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Reset the given user's password. |
|
| 179 | - * |
|
| 180 | - * @param \Illuminate\Http\Request $request |
|
| 181 | - * @return \Illuminate\Http\Response |
|
| 182 | - */ |
|
| 183 | - public function resetpassword(Request $request) |
|
| 184 | - { |
|
| 185 | - $this->validate($request, [ |
|
| 186 | - 'token' => 'required', |
|
| 187 | - 'email' => 'required|email', |
|
| 188 | - 'password' => 'required|confirmed|min:6', |
|
| 189 | - 'password_confirmation' => 'required', |
|
| 190 | - ]); |
|
| 191 | - |
|
| 192 | - return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Change the logged in user password. |
|
| 197 | - * |
|
| 198 | - * @param \Illuminate\Http\Request $request |
|
| 199 | - * @return \Illuminate\Http\Response |
|
| 200 | - */ |
|
| 201 | - public function changePassword(Request $request) |
|
| 202 | - { |
|
| 203 | - $this->validate($request, [ |
|
| 204 | - 'old_password' => 'required', |
|
| 205 | - 'password' => 'required|confirmed|min:6', |
|
| 206 | - 'password_confirmation' => 'required', |
|
| 207 | - ]); |
|
| 208 | - |
|
| 209 | - return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Confirm email using the confirmation code. |
|
| 214 | - * |
|
| 215 | - * @param \Illuminate\Http\Request $request |
|
| 216 | - * @return \Illuminate\Http\Response |
|
| 217 | - */ |
|
| 218 | - public function confirmEmail(Request $request) |
|
| 219 | - { |
|
| 220 | - $this->validate($request, [ |
|
| 221 | - 'confirmation_code' => 'required|string|exists:users,confirmation_code' |
|
| 222 | - ]); |
|
| 223 | - |
|
| 224 | - return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Resend the email confirmation mail. |
|
| 229 | - * |
|
| 230 | - * @param \Illuminate\Http\Request $request |
|
| 231 | - * @return \Illuminate\Http\Response |
|
| 232 | - */ |
|
| 233 | - public function resendEmailConfirmation(Request $request) |
|
| 234 | - { |
|
| 235 | - $this->validate($request, [ |
|
| 236 | - 'email' => 'required|exists:users,email' |
|
| 237 | - ]); |
|
| 238 | - |
|
| 239 | - return \Response::json($this->repo->sendConfirmationEmail($request->only('email')), 200); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Refresh the expired login token. |
|
| 244 | - * |
|
| 245 | - * @param \Illuminate\Http\Request $request |
|
| 246 | - * @return \Illuminate\Http\Response |
|
| 247 | - */ |
|
| 248 | - public function refreshtoken(Request $request) |
|
| 249 | - { |
|
| 250 | - $this->validate($request, [ |
|
| 251 | - 'refreshtoken' => 'required', |
|
| 252 | - ]); |
|
| 253 | - |
|
| 254 | - return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Paginate all users with in the given group. |
|
| 259 | - * |
|
| 260 | - * @param \Illuminate\Http\Request $request |
|
| 261 | - * @param string $groupName The name of the requested group. |
|
| 262 | - * @param integer $perPage Number of rows per page default 15. |
|
| 263 | - * @param string $sortBy The name of the column to sort by. |
|
| 264 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
| 265 | - * @return \Illuminate\Http\Response |
|
| 266 | - */ |
|
| 267 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
| 268 | - { |
|
| 269 | - return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Save the given data to the logged in user. |
|
| 274 | - * |
|
| 275 | - * @param \Illuminate\Http\Request $request |
|
| 276 | - * @return \Illuminate\Http\Response |
|
| 277 | - */ |
|
| 278 | - public function saveProfile(Request $request) |
|
| 279 | - { |
|
| 280 | - $this->validate($request, [ |
|
| 281 | - 'profile_picture' => 'nullable|base64image', |
|
| 282 | - 'name' => 'nullable|string', |
|
| 283 | - 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
| 284 | - ]); |
|
| 285 | - |
|
| 286 | - return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
|
| 287 | - } |
|
| 11 | + /** |
|
| 12 | + * The name of the model that is used by the base api controller |
|
| 13 | + * to preform actions like (add, edit ... etc). |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $model = 'users'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * List of all route actions that the base api controller |
|
| 20 | + * will skip permissions check for them. |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * List of all route actions that the base api controller |
|
| 27 | + * will skip login check for them. |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The validations rules used by the base api controller |
|
| 34 | + * to check before add. |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $validationRules = [ |
|
| 38 | + 'name' => 'nullable|string', |
|
| 39 | + 'email' => 'required|email|unique:users,email,{id}', |
|
| 40 | + 'password' => 'nullable|min:6' |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * The loginProxy implementation. |
|
| 45 | + * |
|
| 46 | + * @var \App\Modules\V1\Acl\Proxy\LoginProxy |
|
| 47 | + */ |
|
| 48 | + protected $loginProxy; |
|
| 49 | + |
|
| 50 | + public function __construct(LoginProxy $loginProxy) |
|
| 51 | + { |
|
| 52 | + $this->loginProxy = $loginProxy; |
|
| 53 | + parent::__construct(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Return the logged in user account. |
|
| 58 | + * |
|
| 59 | + * @return \Illuminate\Http\Response |
|
| 60 | + */ |
|
| 61 | + public function account() |
|
| 62 | + { |
|
| 63 | + return \Response::json($this->repo->account($this->relations), 200); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Block the user. |
|
| 68 | + * |
|
| 69 | + * @param integer $id Id of the user. |
|
| 70 | + * @return \Illuminate\Http\Response |
|
| 71 | + */ |
|
| 72 | + public function block($id) |
|
| 73 | + { |
|
| 74 | + return \Response::json($this->repo->block($id), 200); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Unblock the user. |
|
| 79 | + * |
|
| 80 | + * @param integer $id Id of the user. |
|
| 81 | + * @return \Illuminate\Http\Response |
|
| 82 | + */ |
|
| 83 | + public function unblock($id) |
|
| 84 | + { |
|
| 85 | + return \Response::json($this->repo->unblock($id), 200); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Logout the user. |
|
| 90 | + * |
|
| 91 | + * @return \Illuminate\Http\Response |
|
| 92 | + */ |
|
| 93 | + public function logout() |
|
| 94 | + { |
|
| 95 | + return \Response::json($this->loginProxy->logout(), 200); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Handle a registration request. |
|
| 100 | + * |
|
| 101 | + * @param \Illuminate\Http\Request $request |
|
| 102 | + * @return \Illuminate\Http\Response |
|
| 103 | + */ |
|
| 104 | + public function register(Request $request) |
|
| 105 | + { |
|
| 106 | + $this->validate($request, [ |
|
| 107 | + 'name' => 'nullable|string', |
|
| 108 | + 'email' => 'required|email|unique:users,email,{id}', |
|
| 109 | + 'password' => 'required|min:6' |
|
| 110 | + ]); |
|
| 111 | + |
|
| 112 | + return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Handle a login request to the application. |
|
| 117 | + * |
|
| 118 | + * @param \Illuminate\Http\Request $request |
|
| 119 | + * @return \Illuminate\Http\Response |
|
| 120 | + */ |
|
| 121 | + public function login(Request $request) |
|
| 122 | + { |
|
| 123 | + $this->validate($request, [ |
|
| 124 | + 'email' => 'required|email', |
|
| 125 | + 'password' => 'required|min:6' |
|
| 126 | + ]); |
|
| 127 | + |
|
| 128 | + return \Response::json($this->loginProxy->login($request->only('email', 'password')), 200); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Handle a social login request of the none admin to the application. |
|
| 133 | + * |
|
| 134 | + * @param \Illuminate\Http\Request $request |
|
| 135 | + * @return \Illuminate\Http\Response |
|
| 136 | + */ |
|
| 137 | + public function loginSocial(Request $request) |
|
| 138 | + { |
|
| 139 | + $this->validate($request, [ |
|
| 140 | + 'auth_code' => 'required_without:access_token', |
|
| 141 | + 'access_token' => 'required_without:auth_code', |
|
| 142 | + 'type' => 'required|in:facebook,google' |
|
| 143 | + ]); |
|
| 144 | + |
|
| 145 | + return \Response::json($this->repo->loginSocial($request->only('auth_code', 'access_token', 'type')), 200); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Assign the given groups to the given user. |
|
| 150 | + * |
|
| 151 | + * @param \Illuminate\Http\Request $request |
|
| 152 | + * @return \Illuminate\Http\Response |
|
| 153 | + */ |
|
| 154 | + public function assigngroups(Request $request) |
|
| 155 | + { |
|
| 156 | + $this->validate($request, [ |
|
| 157 | + 'group_ids' => 'required|exists:groups,id', |
|
| 158 | + 'user_id' => 'required|exists:users,id' |
|
| 159 | + ]); |
|
| 160 | + |
|
| 161 | + return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Send a reset link to the given user. |
|
| 166 | + * |
|
| 167 | + * @param \Illuminate\Http\Request $request |
|
| 168 | + * @return \Illuminate\Http\Response |
|
| 169 | + */ |
|
| 170 | + public function sendreset(Request $request) |
|
| 171 | + { |
|
| 172 | + $this->validate($request, ['email' => 'required|email']); |
|
| 173 | + |
|
| 174 | + return \Response::json($this->repo->sendReset($request->only('email')), 200); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Reset the given user's password. |
|
| 179 | + * |
|
| 180 | + * @param \Illuminate\Http\Request $request |
|
| 181 | + * @return \Illuminate\Http\Response |
|
| 182 | + */ |
|
| 183 | + public function resetpassword(Request $request) |
|
| 184 | + { |
|
| 185 | + $this->validate($request, [ |
|
| 186 | + 'token' => 'required', |
|
| 187 | + 'email' => 'required|email', |
|
| 188 | + 'password' => 'required|confirmed|min:6', |
|
| 189 | + 'password_confirmation' => 'required', |
|
| 190 | + ]); |
|
| 191 | + |
|
| 192 | + return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Change the logged in user password. |
|
| 197 | + * |
|
| 198 | + * @param \Illuminate\Http\Request $request |
|
| 199 | + * @return \Illuminate\Http\Response |
|
| 200 | + */ |
|
| 201 | + public function changePassword(Request $request) |
|
| 202 | + { |
|
| 203 | + $this->validate($request, [ |
|
| 204 | + 'old_password' => 'required', |
|
| 205 | + 'password' => 'required|confirmed|min:6', |
|
| 206 | + 'password_confirmation' => 'required', |
|
| 207 | + ]); |
|
| 208 | + |
|
| 209 | + return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Confirm email using the confirmation code. |
|
| 214 | + * |
|
| 215 | + * @param \Illuminate\Http\Request $request |
|
| 216 | + * @return \Illuminate\Http\Response |
|
| 217 | + */ |
|
| 218 | + public function confirmEmail(Request $request) |
|
| 219 | + { |
|
| 220 | + $this->validate($request, [ |
|
| 221 | + 'confirmation_code' => 'required|string|exists:users,confirmation_code' |
|
| 222 | + ]); |
|
| 223 | + |
|
| 224 | + return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Resend the email confirmation mail. |
|
| 229 | + * |
|
| 230 | + * @param \Illuminate\Http\Request $request |
|
| 231 | + * @return \Illuminate\Http\Response |
|
| 232 | + */ |
|
| 233 | + public function resendEmailConfirmation(Request $request) |
|
| 234 | + { |
|
| 235 | + $this->validate($request, [ |
|
| 236 | + 'email' => 'required|exists:users,email' |
|
| 237 | + ]); |
|
| 238 | + |
|
| 239 | + return \Response::json($this->repo->sendConfirmationEmail($request->only('email')), 200); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Refresh the expired login token. |
|
| 244 | + * |
|
| 245 | + * @param \Illuminate\Http\Request $request |
|
| 246 | + * @return \Illuminate\Http\Response |
|
| 247 | + */ |
|
| 248 | + public function refreshtoken(Request $request) |
|
| 249 | + { |
|
| 250 | + $this->validate($request, [ |
|
| 251 | + 'refreshtoken' => 'required', |
|
| 252 | + ]); |
|
| 253 | + |
|
| 254 | + return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Paginate all users with in the given group. |
|
| 259 | + * |
|
| 260 | + * @param \Illuminate\Http\Request $request |
|
| 261 | + * @param string $groupName The name of the requested group. |
|
| 262 | + * @param integer $perPage Number of rows per page default 15. |
|
| 263 | + * @param string $sortBy The name of the column to sort by. |
|
| 264 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
| 265 | + * @return \Illuminate\Http\Response |
|
| 266 | + */ |
|
| 267 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
| 268 | + { |
|
| 269 | + return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Save the given data to the logged in user. |
|
| 274 | + * |
|
| 275 | + * @param \Illuminate\Http\Request $request |
|
| 276 | + * @return \Illuminate\Http\Response |
|
| 277 | + */ |
|
| 278 | + public function saveProfile(Request $request) |
|
| 279 | + { |
|
| 280 | + $this->validate($request, [ |
|
| 281 | + 'profile_picture' => 'nullable|base64image', |
|
| 282 | + 'name' => 'nullable|string', |
|
| 283 | + 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
| 284 | + ]); |
|
| 285 | + |
|
| 286 | + return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
|
| 287 | + } |
|
| 288 | 288 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * to preform actions like (add, edit ... etc). |
| 14 | 14 | * @var string |
| 15 | 15 | */ |
| 16 | - protected $model = 'users'; |
|
| 16 | + protected $model = 'users'; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * List of all route actions that the base api controller |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | * will skip login check for them. |
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The validations rules used by the base api controller |
| 34 | 34 | * to check before add. |
| 35 | 35 | * @var array |
| 36 | 36 | */ |
| 37 | - protected $validationRules = [ |
|
| 37 | + protected $validationRules = [ |
|
| 38 | 38 | 'name' => 'nullable|string', |
| 39 | 39 | 'email' => 'required|email|unique:users,email,{id}', |
| 40 | 40 | 'password' => 'nullable|min:6' |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $this->validate($request, [ |
| 281 | 281 | 'profile_picture' => 'nullable|base64image', |
| 282 | 282 | 'name' => 'nullable|string', |
| 283 | - 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
| 283 | + 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
| 284 | 284 | ]); |
| 285 | 285 | |
| 286 | 286 | return \Response::json($this->repo->saveProfile($request->only('name', 'email')), 200); |
@@ -7,119 +7,119 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AclUser extends User { |
| 9 | 9 | |
| 10 | - use SoftDeletes, HasApiTokens; |
|
| 11 | - protected $table = 'users'; |
|
| 12 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 13 | - protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
| 14 | - protected $guarded = ['id']; |
|
| 15 | - protected $fillable = ['profile_picture', 'name', 'email', 'password']; |
|
| 16 | - public $searchable = ['name', 'email']; |
|
| 10 | + use SoftDeletes, HasApiTokens; |
|
| 11 | + protected $table = 'users'; |
|
| 12 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 13 | + protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
| 14 | + protected $guarded = ['id']; |
|
| 15 | + protected $fillable = ['profile_picture', 'name', 'email', 'password']; |
|
| 16 | + public $searchable = ['name', 'email']; |
|
| 17 | 17 | |
| 18 | - public function getCreatedAtAttribute($value) |
|
| 19 | - { |
|
| 20 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function getUpdatedAtAttribute($value) |
|
| 24 | - { |
|
| 25 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function getDeletedAtAttribute($value) |
|
| 29 | - { |
|
| 30 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Encrypt the password attribute before |
|
| 35 | - * saving it in the storage. |
|
| 36 | - * |
|
| 37 | - * @param string $value |
|
| 38 | - */ |
|
| 39 | - public function setPasswordAttribute($value) |
|
| 40 | - { |
|
| 41 | - $this->attributes['password'] = bcrypt($value); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Get the entity's notifications. |
|
| 46 | - */ |
|
| 47 | - public function notifications() |
|
| 48 | - { |
|
| 49 | - return $this->morphMany('\App\Modules\V1\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Get the entity's read notifications. |
|
| 54 | - */ |
|
| 55 | - public function readNotifications() |
|
| 56 | - { |
|
| 57 | - return $this->notifications()->whereNotNull('read_at'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Get the entity's unread notifications. |
|
| 62 | - */ |
|
| 63 | - public function unreadNotifications() |
|
| 64 | - { |
|
| 65 | - return $this->notifications()->whereNull('read_at'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function groups() |
|
| 69 | - { |
|
| 70 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function oauthClients() |
|
| 74 | - { |
|
| 75 | - return $this->hasMany('App\Modules\V1\Acl\OauthClient', 'user_id'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 80 | - * |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function routeNotificationForFCM() |
|
| 84 | - { |
|
| 85 | - $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
| 86 | - $tokens = []; |
|
| 87 | - |
|
| 88 | - foreach ($devices as $device) |
|
| 89 | - { |
|
| 90 | - $accessToken = decrypt($device->access_token); |
|
| 91 | - |
|
| 92 | - try |
|
| 93 | - { |
|
| 94 | - if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
| 95 | - { |
|
| 96 | - continue; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $tokens[] = $device->device_token; |
|
| 100 | - } |
|
| 101 | - catch (\Exception $e) |
|
| 102 | - { |
|
| 103 | - $device->forceDelete(); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $tokens; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * The channels the user receives notification broadcasts on. |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function receivesBroadcastNotificationsOn() |
|
| 116 | - { |
|
| 117 | - return 'users.' . $this->id; |
|
| 118 | - } |
|
| 18 | + public function getCreatedAtAttribute($value) |
|
| 19 | + { |
|
| 20 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function getUpdatedAtAttribute($value) |
|
| 24 | + { |
|
| 25 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function getDeletedAtAttribute($value) |
|
| 29 | + { |
|
| 30 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Encrypt the password attribute before |
|
| 35 | + * saving it in the storage. |
|
| 36 | + * |
|
| 37 | + * @param string $value |
|
| 38 | + */ |
|
| 39 | + public function setPasswordAttribute($value) |
|
| 40 | + { |
|
| 41 | + $this->attributes['password'] = bcrypt($value); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Get the entity's notifications. |
|
| 46 | + */ |
|
| 47 | + public function notifications() |
|
| 48 | + { |
|
| 49 | + return $this->morphMany('\App\Modules\V1\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Get the entity's read notifications. |
|
| 54 | + */ |
|
| 55 | + public function readNotifications() |
|
| 56 | + { |
|
| 57 | + return $this->notifications()->whereNotNull('read_at'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Get the entity's unread notifications. |
|
| 62 | + */ |
|
| 63 | + public function unreadNotifications() |
|
| 64 | + { |
|
| 65 | + return $this->notifications()->whereNull('read_at'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function groups() |
|
| 69 | + { |
|
| 70 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function oauthClients() |
|
| 74 | + { |
|
| 75 | + return $this->hasMany('App\Modules\V1\Acl\OauthClient', 'user_id'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 80 | + * |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function routeNotificationForFCM() |
|
| 84 | + { |
|
| 85 | + $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
| 86 | + $tokens = []; |
|
| 87 | + |
|
| 88 | + foreach ($devices as $device) |
|
| 89 | + { |
|
| 90 | + $accessToken = decrypt($device->access_token); |
|
| 91 | + |
|
| 92 | + try |
|
| 93 | + { |
|
| 94 | + if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
| 95 | + { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $tokens[] = $device->device_token; |
|
| 100 | + } |
|
| 101 | + catch (\Exception $e) |
|
| 102 | + { |
|
| 103 | + $device->forceDelete(); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $tokens; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * The channels the user receives notification broadcasts on. |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function receivesBroadcastNotificationsOn() |
|
| 116 | + { |
|
| 117 | + return 'users.' . $this->id; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - public static function boot() |
|
| 121 | - { |
|
| 122 | - parent::boot(); |
|
| 123 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
| 124 | - } |
|
| 120 | + public static function boot() |
|
| 121 | + { |
|
| 122 | + parent::boot(); |
|
| 123 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | use SoftDeletes, HasApiTokens; |
| 11 | 11 | protected $table = 'users'; |
| 12 | 12 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
| 13 | - protected $hidden = ['password', 'remember_token','deleted_at', 'two_factor_code']; |
|
| 13 | + protected $hidden = ['password', 'remember_token', 'deleted_at', 'two_factor_code']; |
|
| 14 | 14 | protected $guarded = ['id']; |
| 15 | 15 | protected $fillable = ['profile_picture', 'name', 'email', 'password']; |
| 16 | 16 | public $searchable = ['name', 'email']; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | public function groups() |
| 69 | 69 | { |
| 70 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 70 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function oauthClients() |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function receivesBroadcastNotificationsOn() |
| 116 | 116 | { |
| 117 | - return 'users.' . $this->id; |
|
| 117 | + return 'users.'.$this->id; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public static function boot() |
@@ -5,394 +5,394 @@ |
||
| 5 | 5 | |
| 6 | 6 | class UserRepository extends AbstractRepository |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Return the model full namespace. |
|
| 10 | - * |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - protected function getModel() |
|
| 14 | - { |
|
| 15 | - return 'App\Modules\V1\Acl\AclUser'; |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Return the logged in user account. |
|
| 21 | - * |
|
| 22 | - * @param array $relations |
|
| 23 | - * @return boolean |
|
| 24 | - */ |
|
| 25 | - public function account($relations = []) |
|
| 26 | - { |
|
| 27 | - $permissions = []; |
|
| 28 | - $user = \Core::users()->find(\Auth::id(), $relations); |
|
| 29 | - foreach ($user->groups()->get() as $group) |
|
| 30 | - { |
|
| 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 boolean $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 | - }); |
|
| 8 | + /** |
|
| 9 | + * Return the model full namespace. |
|
| 10 | + * |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + protected function getModel() |
|
| 14 | + { |
|
| 15 | + return 'App\Modules\V1\Acl\AclUser'; |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Return the logged in user account. |
|
| 21 | + * |
|
| 22 | + * @param array $relations |
|
| 23 | + * @return boolean |
|
| 24 | + */ |
|
| 25 | + public function account($relations = []) |
|
| 26 | + { |
|
| 27 | + $permissions = []; |
|
| 28 | + $user = \Core::users()->find(\Auth::id(), $relations); |
|
| 29 | + foreach ($user->groups()->get() as $group) |
|
| 30 | + { |
|
| 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 boolean $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 | 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 $groupName |
|
| 65 | - * @param integer $userId |
|
| 66 | - * @return boolean |
|
| 67 | - */ |
|
| 68 | - public function hasGroup($groupName, $userId = false) |
|
| 69 | - { |
|
| 70 | - $userId = $userId ?: \Auth::id(); |
|
| 71 | - $groups = $this->find($userId)->groups; |
|
| 72 | - return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Assign the given group ids to the given user. |
|
| 77 | - * |
|
| 78 | - * @param integer $user_id |
|
| 79 | - * @param array $group_ids |
|
| 80 | - * @return object |
|
| 81 | - */ |
|
| 82 | - public function assignGroups($user_id, $group_ids) |
|
| 83 | - { |
|
| 84 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 85 | - $user = $this->find($user_id); |
|
| 86 | - $user->groups()->detach(); |
|
| 87 | - $user->groups()->attach($group_ids); |
|
| 88 | - }); |
|
| 89 | - |
|
| 90 | - return $this->find($user_id); |
|
| 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 | - { |
|
| 104 | - \ErrorHandler::loginFailed(); |
|
| 105 | - } |
|
| 106 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 107 | - { |
|
| 108 | - \ErrorHandler::loginFailed(); |
|
| 109 | - } |
|
| 110 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 111 | - { |
|
| 112 | - \ErrorHandler::loginFailed(); |
|
| 113 | - } |
|
| 114 | - else if ($user->blocked) |
|
| 115 | - { |
|
| 116 | - \ErrorHandler::userIsBlocked(); |
|
| 117 | - } |
|
| 118 | - else if ( ! $user->confirmed) |
|
| 119 | - { |
|
| 120 | - \ErrorHandler::emailNotConfirmed(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $user; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Handle a social login request of the none admin to the application. |
|
| 128 | - * |
|
| 129 | - * @param array $credentials |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function loginSocial($credentials) |
|
| 133 | - { |
|
| 134 | - $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
| 135 | - $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
| 136 | - |
|
| 137 | - if ( ! $user->email) |
|
| 138 | - { |
|
| 139 | - \ErrorHandler::noSocialEmail(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
| 143 | - { |
|
| 144 | - $data = ['email' => $user->email, 'password' => '']; |
|
| 145 | - return $this->register($data); |
|
| 146 | - } |
|
| 147 | - else |
|
| 148 | - { |
|
| 149 | - if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
| 150 | - { |
|
| 151 | - \ErrorHandler::userAlreadyRegistered(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 155 | - return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
| 156 | - } |
|
| 157 | - } |
|
| 58 | + return in_array($nameOfPermission, $permissions); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Check if the logged in user has the given group. |
|
| 63 | + * |
|
| 64 | + * @param string $groupName |
|
| 65 | + * @param integer $userId |
|
| 66 | + * @return boolean |
|
| 67 | + */ |
|
| 68 | + public function hasGroup($groupName, $userId = false) |
|
| 69 | + { |
|
| 70 | + $userId = $userId ?: \Auth::id(); |
|
| 71 | + $groups = $this->find($userId)->groups; |
|
| 72 | + return $groups->pluck('name')->search($groupName, true) === false ? false : true; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Assign the given group ids to the given user. |
|
| 77 | + * |
|
| 78 | + * @param integer $user_id |
|
| 79 | + * @param array $group_ids |
|
| 80 | + * @return object |
|
| 81 | + */ |
|
| 82 | + public function assignGroups($user_id, $group_ids) |
|
| 83 | + { |
|
| 84 | + \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 85 | + $user = $this->find($user_id); |
|
| 86 | + $user->groups()->detach(); |
|
| 87 | + $user->groups()->attach($group_ids); |
|
| 88 | + }); |
|
| 89 | + |
|
| 90 | + return $this->find($user_id); |
|
| 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 | + { |
|
| 104 | + \ErrorHandler::loginFailed(); |
|
| 105 | + } |
|
| 106 | + else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 107 | + { |
|
| 108 | + \ErrorHandler::loginFailed(); |
|
| 109 | + } |
|
| 110 | + else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 111 | + { |
|
| 112 | + \ErrorHandler::loginFailed(); |
|
| 113 | + } |
|
| 114 | + else if ($user->blocked) |
|
| 115 | + { |
|
| 116 | + \ErrorHandler::userIsBlocked(); |
|
| 117 | + } |
|
| 118 | + else if ( ! $user->confirmed) |
|
| 119 | + { |
|
| 120 | + \ErrorHandler::emailNotConfirmed(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $user; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Handle a social login request of the none admin to the application. |
|
| 128 | + * |
|
| 129 | + * @param array $credentials |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function loginSocial($credentials) |
|
| 133 | + { |
|
| 134 | + $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token']; |
|
| 135 | + $user = \Socialite::driver($credentials['type'])->userFromToken($access_token); |
|
| 136 | + |
|
| 137 | + if ( ! $user->email) |
|
| 138 | + { |
|
| 139 | + \ErrorHandler::noSocialEmail(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) |
|
| 143 | + { |
|
| 144 | + $data = ['email' => $user->email, 'password' => '']; |
|
| 145 | + return $this->register($data); |
|
| 146 | + } |
|
| 147 | + else |
|
| 148 | + { |
|
| 149 | + if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
|
| 150 | + { |
|
| 151 | + \ErrorHandler::userAlreadyRegistered(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy'); |
|
| 155 | + return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Handle a registration request. |
|
| 161 | - * |
|
| 162 | - * @param array $credentials |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function register($credentials) |
|
| 166 | - { |
|
| 167 | - $user = $this->model->create($credentials); |
|
| 168 | - |
|
| 169 | - if ( ! env('DISABLE_CONFIRM_EMAIL')) |
|
| 170 | - { |
|
| 171 | - $this->sendConfirmationEmail($user->email); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Block the user. |
|
| 177 | - * |
|
| 178 | - * @param integer $user_id |
|
| 179 | - * @return object |
|
| 180 | - */ |
|
| 181 | - public function block($user_id) |
|
| 182 | - { |
|
| 183 | - if ( ! $user = $this->find($user_id)) |
|
| 184 | - { |
|
| 185 | - \ErrorHandler::notFound('user'); |
|
| 186 | - } |
|
| 187 | - if ( ! $this->hasGroup('Admin')) |
|
| 188 | - { |
|
| 189 | - \ErrorHandler::noPermissions(); |
|
| 190 | - } |
|
| 191 | - else if (\Auth::id() == $user_id) |
|
| 192 | - { |
|
| 193 | - \ErrorHandler::noPermissions(); |
|
| 194 | - } |
|
| 195 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 196 | - { |
|
| 197 | - \ErrorHandler::noPermissions(); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $user->blocked = 1; |
|
| 201 | - $user->save(); |
|
| 159 | + /** |
|
| 160 | + * Handle a registration request. |
|
| 161 | + * |
|
| 162 | + * @param array $credentials |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function register($credentials) |
|
| 166 | + { |
|
| 167 | + $user = $this->model->create($credentials); |
|
| 168 | + |
|
| 169 | + if ( ! env('DISABLE_CONFIRM_EMAIL')) |
|
| 170 | + { |
|
| 171 | + $this->sendConfirmationEmail($user->email); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Block the user. |
|
| 177 | + * |
|
| 178 | + * @param integer $user_id |
|
| 179 | + * @return object |
|
| 180 | + */ |
|
| 181 | + public function block($user_id) |
|
| 182 | + { |
|
| 183 | + if ( ! $user = $this->find($user_id)) |
|
| 184 | + { |
|
| 185 | + \ErrorHandler::notFound('user'); |
|
| 186 | + } |
|
| 187 | + if ( ! $this->hasGroup('Admin')) |
|
| 188 | + { |
|
| 189 | + \ErrorHandler::noPermissions(); |
|
| 190 | + } |
|
| 191 | + else if (\Auth::id() == $user_id) |
|
| 192 | + { |
|
| 193 | + \ErrorHandler::noPermissions(); |
|
| 194 | + } |
|
| 195 | + else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 196 | + { |
|
| 197 | + \ErrorHandler::noPermissions(); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $user->blocked = 1; |
|
| 201 | + $user->save(); |
|
| 202 | 202 | |
| 203 | - return $user; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Unblock the user. |
|
| 208 | - * |
|
| 209 | - * @param integer $user_id |
|
| 210 | - * @return object |
|
| 211 | - */ |
|
| 212 | - public function unblock($user_id) |
|
| 213 | - { |
|
| 214 | - if ( ! $this->hasGroup('Admin')) |
|
| 215 | - { |
|
| 216 | - \ErrorHandler::noPermissions(); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $user = $this->find($user_id); |
|
| 220 | - $user->blocked = 0; |
|
| 221 | - $user->save(); |
|
| 222 | - |
|
| 223 | - return $user; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Send a reset link to the given user. |
|
| 228 | - * |
|
| 229 | - * @param string $email |
|
| 230 | - * @return void |
|
| 231 | - */ |
|
| 232 | - public function sendReset($email) |
|
| 233 | - { |
|
| 234 | - if ( ! $user = $this->model->where('email', $email)->first()) |
|
| 235 | - { |
|
| 236 | - \ErrorHandler::notFound('email'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $token = \Password::getRepository()->create($user); |
|
| 240 | - \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Reset the given user's password. |
|
| 245 | - * |
|
| 246 | - * @param array $credentials |
|
| 247 | - * @return array |
|
| 248 | - */ |
|
| 249 | - public function resetPassword($credentials) |
|
| 250 | - { |
|
| 251 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
| 252 | - $user->password = $password; |
|
| 253 | - $user->save(); |
|
| 254 | - }); |
|
| 255 | - |
|
| 256 | - switch ($response) { |
|
| 257 | - case \Password::PASSWORD_RESET: |
|
| 258 | - return 'success'; |
|
| 203 | + return $user; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Unblock the user. |
|
| 208 | + * |
|
| 209 | + * @param integer $user_id |
|
| 210 | + * @return object |
|
| 211 | + */ |
|
| 212 | + public function unblock($user_id) |
|
| 213 | + { |
|
| 214 | + if ( ! $this->hasGroup('Admin')) |
|
| 215 | + { |
|
| 216 | + \ErrorHandler::noPermissions(); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $user = $this->find($user_id); |
|
| 220 | + $user->blocked = 0; |
|
| 221 | + $user->save(); |
|
| 222 | + |
|
| 223 | + return $user; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Send a reset link to the given user. |
|
| 228 | + * |
|
| 229 | + * @param string $email |
|
| 230 | + * @return void |
|
| 231 | + */ |
|
| 232 | + public function sendReset($email) |
|
| 233 | + { |
|
| 234 | + if ( ! $user = $this->model->where('email', $email)->first()) |
|
| 235 | + { |
|
| 236 | + \ErrorHandler::notFound('email'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $token = \Password::getRepository()->create($user); |
|
| 240 | + \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Reset the given user's password. |
|
| 245 | + * |
|
| 246 | + * @param array $credentials |
|
| 247 | + * @return array |
|
| 248 | + */ |
|
| 249 | + public function resetPassword($credentials) |
|
| 250 | + { |
|
| 251 | + $response = \Password::reset($credentials, function ($user, $password) { |
|
| 252 | + $user->password = $password; |
|
| 253 | + $user->save(); |
|
| 254 | + }); |
|
| 255 | + |
|
| 256 | + switch ($response) { |
|
| 257 | + case \Password::PASSWORD_RESET: |
|
| 258 | + return 'success'; |
|
| 259 | 259 | |
| 260 | - case \Password::INVALID_TOKEN: |
|
| 261 | - \ErrorHandler::invalidResetToken('token'); |
|
| 262 | - |
|
| 263 | - case \Password::INVALID_PASSWORD: |
|
| 264 | - \ErrorHandler::invalidResetPassword('email'); |
|
| 265 | - |
|
| 266 | - case \Password::INVALID_USER: |
|
| 267 | - \ErrorHandler::notFound('user'); |
|
| 268 | - |
|
| 269 | - default: |
|
| 270 | - \ErrorHandler::generalError(); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Change the logged in user password. |
|
| 276 | - * |
|
| 277 | - * @param array $credentials |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - public function changePassword($credentials) |
|
| 281 | - { |
|
| 282 | - $user = \Auth::user(); |
|
| 283 | - if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
| 284 | - { |
|
| 285 | - \ErrorHandler::invalidOldPassword(); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $user->password = $credentials['password']; |
|
| 289 | - $user->save(); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Confirm email using the confirmation code. |
|
| 294 | - * |
|
| 295 | - * @param string $confirmationCode |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function confirmEmail($confirmationCode) |
|
| 299 | - { |
|
| 300 | - $user = $this->first(['confirmation_code' => $confirmationCode]); |
|
| 301 | - $user->confirmed = 1; |
|
| 302 | - $user->confirmation_code = null; |
|
| 303 | - $user->save(); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Send the confirmation mail. |
|
| 308 | - * |
|
| 309 | - * @param string $email |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - public function sendConfirmationEmail($email) |
|
| 313 | - { |
|
| 314 | - $user = $this->first(['email' => $email]); |
|
| 315 | - if ($user->confirmed) |
|
| 316 | - { |
|
| 317 | - \ErrorHandler::emailAlreadyConfirmed(); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $user->confirmed = 0; |
|
| 321 | - $user->confirmation_code = sha1(microtime()); |
|
| 322 | - $user->save(); |
|
| 323 | - \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Paginate all users in the given group based on the given conditions. |
|
| 328 | - * |
|
| 329 | - * @param string $groupName |
|
| 330 | - * @param array $relations |
|
| 331 | - * @param integer $perPage |
|
| 332 | - * @param string $sortBy |
|
| 333 | - * @param boolean $desc |
|
| 334 | - * @return \Illuminate\Http\Response |
|
| 335 | - */ |
|
| 336 | - public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
| 337 | - { |
|
| 338 | - unset($conditions['page']); |
|
| 339 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
| 340 | - $sort = $desc ? 'desc' : 'asc'; |
|
| 341 | - $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 342 | - |
|
| 343 | - $model->whereHas('groups', function($q) use ($groupName){ |
|
| 344 | - $q->where('name', $groupName); |
|
| 345 | - }); |
|
| 260 | + case \Password::INVALID_TOKEN: |
|
| 261 | + \ErrorHandler::invalidResetToken('token'); |
|
| 262 | + |
|
| 263 | + case \Password::INVALID_PASSWORD: |
|
| 264 | + \ErrorHandler::invalidResetPassword('email'); |
|
| 265 | + |
|
| 266 | + case \Password::INVALID_USER: |
|
| 267 | + \ErrorHandler::notFound('user'); |
|
| 268 | + |
|
| 269 | + default: |
|
| 270 | + \ErrorHandler::generalError(); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Change the logged in user password. |
|
| 276 | + * |
|
| 277 | + * @param array $credentials |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + public function changePassword($credentials) |
|
| 281 | + { |
|
| 282 | + $user = \Auth::user(); |
|
| 283 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) |
|
| 284 | + { |
|
| 285 | + \ErrorHandler::invalidOldPassword(); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $user->password = $credentials['password']; |
|
| 289 | + $user->save(); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Confirm email using the confirmation code. |
|
| 294 | + * |
|
| 295 | + * @param string $confirmationCode |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function confirmEmail($confirmationCode) |
|
| 299 | + { |
|
| 300 | + $user = $this->first(['confirmation_code' => $confirmationCode]); |
|
| 301 | + $user->confirmed = 1; |
|
| 302 | + $user->confirmation_code = null; |
|
| 303 | + $user->save(); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Send the confirmation mail. |
|
| 308 | + * |
|
| 309 | + * @param string $email |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + public function sendConfirmationEmail($email) |
|
| 313 | + { |
|
| 314 | + $user = $this->first(['email' => $email]); |
|
| 315 | + if ($user->confirmed) |
|
| 316 | + { |
|
| 317 | + \ErrorHandler::emailAlreadyConfirmed(); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $user->confirmed = 0; |
|
| 321 | + $user->confirmation_code = sha1(microtime()); |
|
| 322 | + $user->save(); |
|
| 323 | + \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Paginate all users in the given group based on the given conditions. |
|
| 328 | + * |
|
| 329 | + * @param string $groupName |
|
| 330 | + * @param array $relations |
|
| 331 | + * @param integer $perPage |
|
| 332 | + * @param string $sortBy |
|
| 333 | + * @param boolean $desc |
|
| 334 | + * @return \Illuminate\Http\Response |
|
| 335 | + */ |
|
| 336 | + public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
| 337 | + { |
|
| 338 | + unset($conditions['page']); |
|
| 339 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
| 340 | + $sort = $desc ? 'desc' : 'asc'; |
|
| 341 | + $model = call_user_func_array("{$this->getModel()}::with", array($relations)); |
|
| 342 | + |
|
| 343 | + $model->whereHas('groups', function($q) use ($groupName){ |
|
| 344 | + $q->where('name', $groupName); |
|
| 345 | + }); |
|
| 346 | 346 | |
| 347 | 347 | |
| 348 | - if (count($conditions['conditionValues'])) |
|
| 349 | - { |
|
| 350 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if ($perPage) |
|
| 354 | - { |
|
| 355 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $model->orderBy($sortBy, $sort)->get(); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Save the given data to the logged in user. |
|
| 363 | - * |
|
| 364 | - * @param array $credentials |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - public function saveProfile($data) |
|
| 368 | - { |
|
| 369 | - if (array_key_exists('profile_picture', $data)) |
|
| 370 | - { |
|
| 371 | - $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
| 372 | - } |
|
| 348 | + if (count($conditions['conditionValues'])) |
|
| 349 | + { |
|
| 350 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if ($perPage) |
|
| 354 | + { |
|
| 355 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $model->orderBy($sortBy, $sort)->get(); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Save the given data to the logged in user. |
|
| 363 | + * |
|
| 364 | + * @param array $credentials |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + public function saveProfile($data) |
|
| 368 | + { |
|
| 369 | + if (array_key_exists('profile_picture', $data)) |
|
| 370 | + { |
|
| 371 | + $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $data['id'] = \Auth::id(); |
|
| 375 | - $this->save($data); |
|
| 376 | - } |
|
| 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 | - |
|
| 387 | - $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
| 388 | - $data = new ValidationData(); |
|
| 389 | - $data->setCurrentTime(time()); |
|
| 390 | - |
|
| 391 | - if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
| 392 | - { |
|
| 393 | - return true; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - return false; |
|
| 397 | - } |
|
| 374 | + $data['id'] = \Auth::id(); |
|
| 375 | + $this->save($data); |
|
| 376 | + } |
|
| 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 | + |
|
| 387 | + $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface'); |
|
| 388 | + $data = new ValidationData(); |
|
| 389 | + $data->setCurrentTime(time()); |
|
| 390 | + |
|
| 391 | + if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) |
|
| 392 | + { |
|
| 393 | + return true; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 398 | 398 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $user = \Core::users()->find(\Auth::id(), $relations); |
| 29 | 29 | foreach ($user->groups()->get() as $group) |
| 30 | 30 | { |
| 31 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 31 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
| 32 | 32 | $permissions[$permission->model][$permission->id] = $permission->name; |
| 33 | 33 | }); |
| 34 | 34 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
| 52 | 52 | $permissions = []; |
| 53 | 53 | |
| 54 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 54 | + $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){ |
|
| 55 | 55 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
| 56 | 56 | }); |
| 57 | 57 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function assignGroups($user_id, $group_ids) |
| 83 | 83 | { |
| 84 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 84 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
| 85 | 85 | $user = $this->find($user_id); |
| 86 | 86 | $user->groups()->detach(); |
| 87 | 87 | $user->groups()->attach($group_ids); |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function resetPassword($credentials) |
| 250 | 250 | { |
| 251 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
| 251 | + $response = \Password::reset($credentials, function($user, $password) { |
|
| 252 | 252 | $user->password = $password; |
| 253 | 253 | $user->save(); |
| 254 | 254 | }); |
@@ -102,20 +102,16 @@ discard block |
||
| 102 | 102 | if ( ! $user = $this->first(['email' => $credentials['email']])) |
| 103 | 103 | { |
| 104 | 104 | \ErrorHandler::loginFailed(); |
| 105 | - } |
|
| 106 | - else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 105 | + } else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) |
|
| 107 | 106 | { |
| 108 | 107 | \ErrorHandler::loginFailed(); |
| 109 | - } |
|
| 110 | - else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 108 | + } else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 111 | 109 | { |
| 112 | 110 | \ErrorHandler::loginFailed(); |
| 113 | - } |
|
| 114 | - else if ($user->blocked) |
|
| 111 | + } else if ($user->blocked) |
|
| 115 | 112 | { |
| 116 | 113 | \ErrorHandler::userIsBlocked(); |
| 117 | - } |
|
| 118 | - else if ( ! $user->confirmed) |
|
| 114 | + } else if ( ! $user->confirmed) |
|
| 119 | 115 | { |
| 120 | 116 | \ErrorHandler::emailNotConfirmed(); |
| 121 | 117 | } |
@@ -143,8 +139,7 @@ discard block |
||
| 143 | 139 | { |
| 144 | 140 | $data = ['email' => $user->email, 'password' => '']; |
| 145 | 141 | return $this->register($data); |
| 146 | - } |
|
| 147 | - else |
|
| 142 | + } else |
|
| 148 | 143 | { |
| 149 | 144 | if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => ''])) |
| 150 | 145 | { |
@@ -187,12 +182,10 @@ discard block |
||
| 187 | 182 | if ( ! $this->hasGroup('Admin')) |
| 188 | 183 | { |
| 189 | 184 | \ErrorHandler::noPermissions(); |
| 190 | - } |
|
| 191 | - else if (\Auth::id() == $user_id) |
|
| 185 | + } else if (\Auth::id() == $user_id) |
|
| 192 | 186 | { |
| 193 | 187 | \ErrorHandler::noPermissions(); |
| 194 | - } |
|
| 195 | - else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 188 | + } else if ($user->groups->pluck('name')->search('Admin', true) !== false) |
|
| 196 | 189 | { |
| 197 | 190 | \ErrorHandler::noPermissions(); |
| 198 | 191 | } |
@@ -7,75 +7,75 @@ |
||
| 7 | 7 | class ModuleServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | - * Bootstrap the module services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 10 | + * Bootstrap the module services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 18 | 18 | |
| 19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
| 21 | - } |
|
| 19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Register the module services. |
|
| 25 | - * |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function register() |
|
| 29 | - { |
|
| 30 | - //Bind Core Facade to the IoC Container |
|
| 31 | - \App::bind('Core', function() |
|
| 32 | - { |
|
| 33 | - return new \App\Modules\V1\Core\Core; |
|
| 34 | - }); |
|
| 23 | + /** |
|
| 24 | + * Register the module services. |
|
| 25 | + * |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function register() |
|
| 29 | + { |
|
| 30 | + //Bind Core Facade to the IoC Container |
|
| 31 | + \App::bind('Core', function() |
|
| 32 | + { |
|
| 33 | + return new \App\Modules\V1\Core\Core; |
|
| 34 | + }); |
|
| 35 | 35 | |
| 36 | - //Bind ErrorHandler Facade to the IoC Container |
|
| 37 | - \App::bind('ErrorHandler', function() |
|
| 38 | - { |
|
| 39 | - return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
| 40 | - }); |
|
| 36 | + //Bind ErrorHandler Facade to the IoC Container |
|
| 37 | + \App::bind('ErrorHandler', function() |
|
| 38 | + { |
|
| 39 | + return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
| 40 | + }); |
|
| 41 | 41 | |
| 42 | - //Bind CoreConfig Facade to the IoC Container |
|
| 43 | - \App::bind('CoreConfig', function() |
|
| 44 | - { |
|
| 45 | - return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
| 46 | - }); |
|
| 42 | + //Bind CoreConfig Facade to the IoC Container |
|
| 43 | + \App::bind('CoreConfig', function() |
|
| 44 | + { |
|
| 45 | + return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
| 46 | + }); |
|
| 47 | 47 | |
| 48 | - //Bind Mpgs Facade to the IoC Container |
|
| 49 | - \App::bind('Media', function() |
|
| 50 | - { |
|
| 51 | - return new \App\Modules\V1\Core\Utl\Media; |
|
| 52 | - }); |
|
| 48 | + //Bind Mpgs Facade to the IoC Container |
|
| 49 | + \App::bind('Media', function() |
|
| 50 | + { |
|
| 51 | + return new \App\Modules\V1\Core\Utl\Media; |
|
| 52 | + }); |
|
| 53 | 53 | |
| 54 | - \Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) { |
|
| 55 | - $explode = explode(',', $value); |
|
| 56 | - $allow = ['png', 'jpg', 'svg']; |
|
| 57 | - $format = str_replace( |
|
| 58 | - [ |
|
| 59 | - 'data:image/', |
|
| 60 | - ';', |
|
| 61 | - 'base64', |
|
| 62 | - ], |
|
| 63 | - [ |
|
| 64 | - '', '', '', |
|
| 65 | - ], |
|
| 66 | - $explode[0] |
|
| 67 | - ); |
|
| 68 | - // check file format |
|
| 69 | - if (!in_array($format, $allow)) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - // check base64 format |
|
| 73 | - if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - return true; |
|
| 77 | - }); |
|
| 54 | + \Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) { |
|
| 55 | + $explode = explode(',', $value); |
|
| 56 | + $allow = ['png', 'jpg', 'svg']; |
|
| 57 | + $format = str_replace( |
|
| 58 | + [ |
|
| 59 | + 'data:image/', |
|
| 60 | + ';', |
|
| 61 | + 'base64', |
|
| 62 | + ], |
|
| 63 | + [ |
|
| 64 | + '', '', '', |
|
| 65 | + ], |
|
| 66 | + $explode[0] |
|
| 67 | + ); |
|
| 68 | + // check file format |
|
| 69 | + if (!in_array($format, $allow)) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + // check base64 format |
|
| 73 | + if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + return true; |
|
| 77 | + }); |
|
| 78 | 78 | |
| 79 | - $this->app->register(RouteServiceProvider::class); |
|
| 80 | - } |
|
| 79 | + $this->app->register(RouteServiceProvider::class); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | return new \App\Modules\V1\Core\Utl\Media; |
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | - \Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) { |
|
| 54 | + \Validator::extend('base64image', function($attribute, $value, $parameters, $validator) { |
|
| 55 | 55 | $explode = explode(',', $value); |
| 56 | 56 | $allow = ['png', 'jpg', 'svg']; |
| 57 | 57 | $format = str_replace( |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | $explode[0] |
| 67 | 67 | ); |
| 68 | 68 | // check file format |
| 69 | - if (!in_array($format, $allow)) { |
|
| 69 | + if ( ! in_array($format, $allow)) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | // check base64 format |
| 73 | - if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) { |
|
| 73 | + if ( ! preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | return true; |