Skip to content

Commit

Permalink
File Management
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunetsiz committed Feb 16, 2025
1 parent eab51f5 commit f1f0fd3
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ MONERO_ADDRESS_EXPIRATION_TIME=1440

# Marketplace Settings
MARKETPLACE_REQUIRE_REFERENCE=false
MARKETPLACE_SHOW_JS_WARNING=true
MARKETPLACE_SHOW_JS_WARNING=false
MARKETPLACE_COMMISSION_PERCENTAGE=2
5 changes: 2 additions & 3 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,14 +989,13 @@ public function denyVendorApplication(VendorPayment $application)
// Calculate refund amount
$refundAmount = $application->total_received * ($refundPercentage / 100);

// Get random verified return address
// Get random return address
$returnAddress = $application->user->returnAddresses()
->where('is_verified', true)
->inRandomOrder()
->first();

if (!$returnAddress) {
throw new \Exception('No verified return address found for user');
throw new \Exception('No return address found for user');
}

// First update application status
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function showPgp2FAChallenge()
return redirect()->route('login')->with('error', 'Could not generate 2FA challenge. Please contact support team.');
}

$message = 'PGP' . Str::random(10) . 'KEY';
$message = 'PGP-' . Str::random(10) . '-KEY';
$encryptedMessage = $this->encryptMessage($message, $pgpKey->public_key);

if ($encryptedMessage === false) {
Expand Down
10 changes: 3 additions & 7 deletions app/Http/Controllers/BecomeVendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public function index(Request $request)
$hasPgpVerified = $user->pgpKey->verified;
}

// Check if the user has at least one verified Monero return address.
$hasMoneroAddress = $user->returnAddresses()
->where('is_verified', true)
->exists();
// Check if the user has at least one Monero return address.
$hasMoneroAddress = $user->returnAddresses()->exists();

// Get the latest vendor payment
$vendorPayment = VendorPayment::where('user_id', $user->id)
Expand All @@ -76,9 +74,7 @@ public function payment(Request $request)
$hasPgpVerified = $user->pgpKey->verified;
}

$hasMoneroAddress = $user->returnAddresses()
->where('is_verified', true)
->exists();
$hasMoneroAddress = $user->returnAddresses()->exists();

// Check if user has a processed application
$existingPayment = VendorPayment::where('user_id', $user->id)
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function index()
$user = Auth::user();
$profile = $user->profile ?? $user->profile()->create();

return view('profile', compact('user', 'profile'));
return view('profile.index', compact('user', 'profile'));
}

public function update(Request $request)
Expand Down Expand Up @@ -236,7 +236,7 @@ public function showPgpConfirmationForm()
Log::info('PGP Key ID: ' . $pgpKey->id);
Log::info('PGP Key User ID: ' . $pgpKey->user_id);

$message = 'PGP' . mt_rand(1000000000, 9999999999) . 'KEY';
$message = 'PGP-' . mt_rand(1000000000, 9999999999) . '-KEY';
$encryptedMessage = '';

// Create a unique temporary directory
Expand Down Expand Up @@ -283,7 +283,7 @@ public function showPgpConfirmationForm()
'pgp_confirmation_expiry' => $expirationTime
]);

return view('confirm-pgp-key', compact('encryptedMessage', 'expirationTime'));
return view('profile.confirm-pgp-key', compact('encryptedMessage', 'expirationTime'));
}

/**
Expand Down
53 changes: 13 additions & 40 deletions app/Http/Controllers/ReturnAddressController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
use App\Models\ReturnAddress;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Rule;

class ReturnAddressController extends Controller
{
/**
* The regex pattern for validating Monero addresses
* The regex pattern for validating Monero addresses.
*/
private const MONERO_ADDRESS_REGEX = "/^(4[1-9AB][1-9A-HJ-NP-Za-km-z]{93}|8[2-9ABC][1-9A-HJ-NP-Za-km-z]{93})$/";

Expand Down Expand Up @@ -41,63 +39,37 @@ public function store(Request $request)
],
]);

$isValid = false;
$apiError = false;

// Try validating using the external API first
try {
$response = Http::timeout(5)->post('https://api.checkcryptoaddress.com/wallet-checks', [
'address' => $request->monero_address,
'network' => 'xmr',
]);

if ($response->successful()) {
$isValid = $response->json('valid');
} else {
$apiError = true;
Log::warning('Monero address API validation failed with status: ' . $response->status());
}
} catch (\Exception $e) {
$apiError = true;
// Only log the exception message to avoid stack traces
Log::warning('Monero address API error: ' . $e->getMessage());
}

// If API validation failed, use regex as fallback
if ($apiError) {
$isValid = preg_match(self::MONERO_ADDRESS_REGEX, $request->monero_address) === 1;
Log::info('Using regex fallback for Monero address validation');
}
// Validate the address using regex.
$isValid = preg_match(self::MONERO_ADDRESS_REGEX, $request->monero_address) === 1;

if ($isValid) {
$user = Auth::user();
// Check if the user has reached the limit of 4 return addresses
if ($user->returnAddresses()->count() >= 4) {

// Check if the user has reached the limit of 8 return addresses.
if ($user->returnAddresses()->count() >= 8) {
return redirect()->route('return-addresses.index')
->with('error', 'You can add a maximum of 4 return addresses.');
->with('error', 'You can add a maximum of 8 return addresses.');
}

ReturnAddress::create([
'user_id' => $user->id,
'monero_address' => $request->monero_address,
'is_verified' => true,
]);

return redirect()->route('return-addresses.index')
->with('success', 'Return address successfully added.');
} else {
return redirect()->route('return-addresses.index')
->with('error', 'Invalid Monero address. Please try again.');
}

return redirect()->route('return-addresses.index')
->with('error', 'Invalid Monero address. Please try again.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy(ReturnAddress $returnAddress)
{
// Check if the return address belongs to the authenticated user
// Check if the return address belongs to the authenticated user.
if ($returnAddress->user_id !== Auth::id()) {
abort(403, 'Unauthorized action.');
}
Expand All @@ -107,4 +79,5 @@ public function destroy(ReturnAddress $returnAddress)
return redirect()->route('return-addresses.index')
->with('success', 'Return address successfully deleted.');
}
}
}

5 changes: 0 additions & 5 deletions app/Models/ReturnAddress.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class ReturnAddress extends Model
protected $fillable = [
'user_id',
'monero_address',
'is_verified',
];

protected $casts = [
'is_verified' => 'boolean',
];

public function user()
Expand Down
4 changes: 2 additions & 2 deletions config/marketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| When false, the reference code becomes optional.
|
*/
'require_reference_code' => env('MARKETPLACE_REQUIRE_REFERENCE', true),
'require_reference_code' => env('MARKETPLACE_REQUIRE_REFERENCE', false),

/*
|--------------------------------------------------------------------------
Expand All @@ -23,7 +23,7 @@
| When false, the warning will be hidden.
|
*/
'show_javascript_warning' => env('MARKETPLACE_SHOW_JS_WARNING', true),
'show_javascript_warning' => env('MARKETPLACE_SHOW_JS_WARNING', false),

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion database/migrations/2025_01_01_000019_create_return_addresses_table.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function up(): void
$table->id();
$table->foreignUuid('user_id')->constrained()->onDelete('cascade');
$table->string('monero_address');
$table->boolean('is_verified')->default(false);
$table->timestamps();
});
}
Expand Down
44 changes: 26 additions & 18 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,31 @@ margin:0 auto;
padding:0 20px 40px
}

.rules-section h2,.rules-section h3,.rules-title {
.rules-section h2,.rules-section h3 {
color:#bb86fc;
margin-bottom:20px;
text-align:center
}

.rules-title {
font-size:32px;
margin-top:-20px
background-color:#2c2c2c;
border:2px solid #bb86fc;
color:#bb86fc;
padding:16px 32px;
border-radius:36px;
font-size:28px;
font-weight:700;
text-transform:uppercase;
letter-spacing:1px;
transition:all .3s ease;
display:inline-block;
margin:30px 0 20px;
margin-top:0
}

.rules-title:hover {
transform:translateY(-2px);
box-shadow:0 4px 15px #bb86fc33
}

.rules-section {
Expand Down Expand Up @@ -835,11 +851,11 @@ margin-top:30px;
color:#e0e0e0
}

.rule-item {
.rules-item {
margin-bottom:30px
}

.rule-item:last-child {
.rules-item:last-child {
margin-bottom:0
}

Expand Down Expand Up @@ -1135,7 +1151,7 @@ font-weight:700
}

.pgp-confirm-textarea {
width:22%;
width:24%;
height:70%;
padding:12px 15px;
background-color:#1e1e1e;
Expand Down Expand Up @@ -1325,7 +1341,8 @@ background-color:#1e1e1e;
border-radius:8px;
padding:30px;
box-shadow:0 4px 20px #0000004d;
border:1px solid #3c3c3c
border:1px solid #3c3c3c;
margin-top:-40px
}

.become-vendor-index-title {
Expand Down Expand Up @@ -2459,7 +2476,8 @@ margin-bottom:20px;
color:#e0e0e0;
font-size:.9em;
line-height:1.4;
border-radius:4px
border-radius:4px;
margin-top:-20px
}

.return-addresses-card {
Expand Down Expand Up @@ -2552,16 +2570,6 @@ color:#e0e0e0;
text-align:center
}

.return-addresses-verified {
color:#4caf50;
font-weight:700
}

.return-addresses-unverified {
color:#ffc107;
font-weight:700
}

.return-addresses-delete-btn {
background-color:#cf6679;
color:#121212;
Expand Down
Loading

0 comments on commit f1f0fd3

Please # to comment.