⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.94
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
dalily.dev-unit.com
/
app
/
Observers
/
View File Name :
BlacklistObserver.php
<?php /* * LaraClassifier - Classified Ads Web Application * Copyright (c) BeDigit. All Rights Reserved * * Website: https://laraclassifier.com * Author: Mayeul Akpovi (BeDigit - https://bedigit.com) * * LICENSE * ------- * This software is provided under a license agreement and may only be used or copied * in accordance with its terms, including the inclusion of the above copyright notice. * As this software is sold exclusively on CodeCanyon, * please review the full license details here: https://codecanyon.net/licenses/standard */ namespace App\Observers; use App\Exceptions\Custom\CustomException; use App\Models\Blacklist; use App\Models\Permission; use App\Models\Post; use App\Models\User; use App\Services\Auth\App\Notifications\AccountBanned; class BlacklistObserver { /** * Listen to the Entry saved event. * * @param Blacklist $blacklist * @return void * @throws \App\Exceptions\Custom\CustomException */ public function saved(Blacklist $blacklist) { // Check if an email address has been banned if ( !empty($blacklist->type) && !empty($blacklist->entry) && $blacklist->type == 'email' ) { // Check if it is a valid email address if (filter_var($blacklist->entry, FILTER_VALIDATE_EMAIL)) { $exceptEmailDomains = [getDomain(), 'domain.tld', 'demosite.com', 'larapen.com']; $blacklistEmailDomain = str($blacklist->entry)->after('@'); // Don't remove banned email address data for the "except" domains if (!in_array($blacklistEmailDomain, $exceptEmailDomains)) { // Delete the banned user related to the email address $user = User::query()->where('email', $blacklist->entry)->first(); $userExistsAndIsNotAdmin = !doesUserHavePermission($user, Permission::getStaffPermissions()); if (!empty($user) && $userExistsAndIsNotAdmin) { // Send a notification to the user $sendNotificationOnUserBan = config('settings.auth.send_notification_on_user_ban'); $sendNotificationOnUserBan = getAsString($sendNotificationOnUserBan, 'none'); if (in_array($sendNotificationOnUserBan, ['send', 'forceToSend'])) { try { $user->notify(new AccountBanned($user)); } catch (\Throwable $e) { if ($sendNotificationOnUserBan == 'forceToSend') { throw new CustomException($e->getMessage()); } } } // Delete the user $user->delete(); } // Delete the banned user's listings related to the email address if (empty($user) || $userExistsAndIsNotAdmin) { $posts = Post::query()->where('email', $blacklist->entry); if ($posts->count() > 0) { foreach ($posts->cursor() as $post) { $post->delete(); } } } } } } // Check if a phone number has been banned if ( !empty($blacklist->type) && !empty($blacklist->entry) && $blacklist->type == 'phone' ) { // Delete the banned user related to the phone number $user = User::query()->where('phone', $blacklist->entry)->first(); $userExistsAndIsNotAdmin = !doesUserHavePermission($user, Permission::getStaffPermissions()); if (!empty($user) && $userExistsAndIsNotAdmin) { // Send a notification to the user $sendNotificationOnUserBan = config('settings.auth.send_notification_on_user_ban'); $sendNotificationOnUserBan = getAsString($sendNotificationOnUserBan, 'none'); if (in_array($sendNotificationOnUserBan, ['send', 'forceToSend'])) { try { $user->notify(new AccountBanned($user)); } catch (\Throwable $e) { if ($sendNotificationOnUserBan == 'forceToSend') { throw new CustomException($e->getMessage()); } } } // Delete the user $user->delete(); } // Delete the banned user's listings related to the phone number if (empty($user) || $userExistsAndIsNotAdmin) { $posts = Post::query()->where('phone', $blacklist->entry); if ($posts->count() > 0) { foreach ($posts->cursor() as $post) { $post->delete(); } } } } } }