mirror of
https://repo.getmonero.org/AnonDev/xmrmemes.git
synced 2025-07-20 05:32:02 -04:00
Finish rough draft of website
Update the payment code so everything is working now Improve DB structure Improve design Add API Validate XMR Address upon registration And Much More... Still Need to work on: - SEO - Dropdown in menu (bug, not dropping down)
This commit is contained in:
parent
dbfda5cf9e
commit
821fb9b1ed
30 changed files with 186 additions and 261 deletions
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Address;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Address $address
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Address $address)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Address $address
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Address $address)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Address $address
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Address $address)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Address $address
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Address $address)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ class ApiController extends Controller
|
|||
public function documentation()
|
||||
{
|
||||
$data = [
|
||||
'memes_example' => json_encode(Meme::get(), JSON_PRETTY_PRINT),
|
||||
'memes_example' => json_encode(Meme::limit(1)->get(), JSON_PRETTY_PRINT),
|
||||
'memes_endpoint' => url('api/memes'),
|
||||
];
|
||||
return view('api', ['data' => $data]);
|
||||
|
|
14
app/Http/Controllers/ContactController.php
Normal file
14
app/Http/Controllers/ContactController.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$data = [];
|
||||
return view('contact', ['data' => $data]);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ use App\Models\User;
|
|||
use App\Models\Address;
|
||||
use Illuminate\Http\Request;
|
||||
use chillerlan\QRCode\{QRCode, QROptions};
|
||||
use MoneroIntegrations\MoneroPhp\walletRPC;
|
||||
|
||||
class MemeController extends Controller
|
||||
{
|
||||
|
@ -77,11 +78,8 @@ class MemeController extends Controller
|
|||
'image' => ['required', 'image'],
|
||||
]);
|
||||
$user = \Auth::user();
|
||||
$used_ids = Meme::pluck('address_id')->toArray();
|
||||
$address = Address::whereNotIn('id', $used_ids)->first('id');
|
||||
return Meme::create([
|
||||
Meme::create([
|
||||
'user_id' => $user->id,
|
||||
'address_id' => $address->id,
|
||||
'title' => $request->input('title'),
|
||||
'caption' => $request->input('caption'),
|
||||
'image' => $request->file('image'),
|
||||
|
@ -96,7 +94,7 @@ class MemeController extends Controller
|
|||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$meme = Meme::where('id', $id)->with(['user', 'tips', 'address'])->firstOrFail();
|
||||
$meme = Meme::where('id', $id)->with(['user', 'tips'])->firstOrFail();
|
||||
|
||||
$share = \Share::page(url()->current(), $meme->title, ['class' => 'fa-lg', 'target' => '_blank'])
|
||||
->facebook()
|
||||
|
@ -108,7 +106,7 @@ class MemeController extends Controller
|
|||
|
||||
$data = [
|
||||
'meme' => $meme,
|
||||
'qr' => (new QRCode)->render($meme->address->address),
|
||||
'qr' => (new QRCode)->render($meme->address),
|
||||
'share' => preg_replace("/<a(.*?)>/", "<a$1 target=\"_blank\">", $share),
|
||||
];
|
||||
|
||||
|
@ -141,10 +139,19 @@ class MemeController extends Controller
|
|||
public function approve($id)
|
||||
{
|
||||
if (\Auth::user()->is_admin === 1) {
|
||||
$meme = Meme::withoutGlobalScope('approved')->find($id);
|
||||
$meme->is_approved = 1;
|
||||
$meme->save();
|
||||
return redirect()->away(url()->previous());
|
||||
try {
|
||||
$walletRPC = new walletRPC(config('app.xmr_daemon_ip'), config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$open_wallet = $walletRPC->open_wallet(config('app.xmr_wallet_name'), '');
|
||||
$account = $walletRPC->create_account();
|
||||
$meme = Meme::withoutGlobalScope('approved')->find($id);
|
||||
$meme->is_approved = 1;
|
||||
$meme->account_index = $account['account_index'];
|
||||
$meme->address = $account['address'];
|
||||
$meme->save();
|
||||
return redirect()->away(url()->previous());
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,15 +14,12 @@ use App\Models\Address;
|
|||
use App\Models\Meme;
|
||||
use MoneroIntegrations\MoneroPhp\walletRPC;
|
||||
|
||||
// Can put code below inside functions to debug the Monero library
|
||||
// ini_set('display_errors', 1);
|
||||
// ini_set('display_startup_errors', 1);
|
||||
// error_reporting(E_ALL);
|
||||
|
||||
class ProcessPayments implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 3600;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
|
@ -47,23 +44,26 @@ class ProcessPayments implements ShouldQueue
|
|||
public function get_transactions()
|
||||
{
|
||||
try {
|
||||
$walletRPC = new walletRPC('127.0.0.1', config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$walletRPC = new walletRPC(config('app.xmr_daemon_ip'), config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$open_wallet = $walletRPC->open_wallet(config('app.xmr_wallet_name'), '');
|
||||
$get_transfers = $walletRPC->get_transfers('all', true);
|
||||
if (isset($get_transfers['in'])) {
|
||||
foreach ($get_transfers['in'] as $transfer) {
|
||||
$address = Address::where('address', $transfer['address'])->first();
|
||||
$tip_exists = Tip::where('txid', $transfer['txid'])->first();
|
||||
if ($address && !$tip_exists) {
|
||||
$tip = new Tip();
|
||||
$tip->address_id = $address->id;
|
||||
$tip->amount = $transfer['amount'];
|
||||
$tip->txid = $transfer['txid'];
|
||||
$tip->is_deposit = 1;
|
||||
$tip->save();
|
||||
$meme = Meme::where('address_id', $address->id)->firstOrFail();
|
||||
$meme->payment_pending = 1;
|
||||
$meme->save();
|
||||
$account_indexes = Meme::pluck('account_index')->toArray();
|
||||
foreach ($account_indexes as $account_index) {
|
||||
$get_transfers = $walletRPC->get_transfers('in', $account_index);
|
||||
if (isset($get_transfers['in'])) {
|
||||
foreach ($get_transfers['in'] as $transfer) {
|
||||
$meme = Meme::where('address', $transfer['address'])->first();
|
||||
$tip_exists = Tip::where('txid', $transfer['txid'])->first();
|
||||
if ($meme && !$tip_exists) {
|
||||
$tip = new Tip();
|
||||
$tip->meme_id = $meme->id;
|
||||
$tip->amount = $transfer['amount'];
|
||||
$tip->txid = $transfer['txid'];
|
||||
$tip->is_deposit = 1;
|
||||
$tip->save();
|
||||
$meme = Meme::where('address', $transfer['address'])->firstOrFail();
|
||||
$meme->payment_pending = 1;
|
||||
$meme->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,20 +76,23 @@ class ProcessPayments implements ShouldQueue
|
|||
public function payout()
|
||||
{
|
||||
try {
|
||||
$walletRPC = new walletRPC('127.0.0.1', config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$walletRPC = new walletRPC(config('app.xmr_daemon_ip'), config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$open_wallet = $walletRPC->open_wallet(config('app.xmr_wallet_name'), '');
|
||||
$meme = Meme::where('payment_pending', 1)->firstOrFail();
|
||||
if ($meme->user->address) {
|
||||
$send_funds = $walletRPC->sweep_all($meme->user->address, $meme->address->address_index);
|
||||
if ($send_funds['amount_list']) {
|
||||
$tip = new Tip;
|
||||
$tip->address_id = $meme->address_id;
|
||||
$tip->amount = $send_funds['amount_list'][0];
|
||||
$tip->txid = $send_funds['tx_hash_list'][0];
|
||||
$tip->is_deposit = 0;
|
||||
$tip->save();
|
||||
$meme->payment_pending = 0;
|
||||
$meme->save();
|
||||
$memes = Meme::where('payment_pending', 1)->get();
|
||||
foreach ($memes as $meme) {
|
||||
$balance = $walletRPC->get_balance($meme->account_index);
|
||||
if ($balance['balance'] === $balance['unlocked_balance']) {
|
||||
$send_funds = $walletRPC->sweep_all($meme->user->address, '', $meme->account_index);
|
||||
if ($send_funds['amount_list']) {
|
||||
$tip = new Tip;
|
||||
$tip->meme_id = $meme->id;
|
||||
$tip->amount = $send_funds['amount_list'][0];
|
||||
$tip->txid = $send_funds['tx_hash_list'][0];
|
||||
$tip->is_deposit = 0;
|
||||
$tip->save();
|
||||
$meme->payment_pending = 0;
|
||||
$meme->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$walletRPC->close_wallet();
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
|
@ -14,7 +14,14 @@ class Meme extends Model
|
|||
use SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $appends = ['meme_tips_total'];
|
||||
protected $appends = ['meme_tips_total', 'image_url'];
|
||||
protected $hidden = [
|
||||
'payment_pending',
|
||||
'account_index',
|
||||
'is_approved',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
|
@ -28,14 +35,9 @@ class Meme extends Model
|
|||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function address()
|
||||
{
|
||||
return $this->belongsTo(Address::class);
|
||||
}
|
||||
|
||||
public function tips()
|
||||
{
|
||||
return $this->hasManyThrough(Tip::class, Address::class, 'id', 'address_id', 'address_id', 'id')->orderBy('created_at', 'DESC');
|
||||
return $this->hasMany(Tip::class)->orderByDesc('created_at');
|
||||
}
|
||||
|
||||
public function getMemeTipsTotalAttribute()
|
||||
|
@ -43,6 +45,11 @@ class Meme extends Model
|
|||
return $this->tips->where('is_deposit', 1)->sum('amount_formatted');
|
||||
}
|
||||
|
||||
public function getImageUrlAttribute()
|
||||
{
|
||||
return url($this->image);
|
||||
}
|
||||
|
||||
public function setImageAttribute($value)
|
||||
{
|
||||
$attribute_name = "image";
|
||||
|
|
|
@ -9,13 +9,18 @@ class Tip extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $appends = ['amount_formatted'];
|
||||
protected $appends = ['amount_formatted', 'tx_url'];
|
||||
|
||||
public function getAmountFormattedAttribute()
|
||||
{
|
||||
return number_format(($this->amount)*(pow(10, -12)), 8, '.', '');
|
||||
}
|
||||
|
||||
public function getTxUrlAttribute()
|
||||
{
|
||||
return config('app.xmr_explorer_base_url') . $this->txid;
|
||||
}
|
||||
|
||||
public function address()
|
||||
{
|
||||
return $this->belongsTo(Address::class);
|
||||
|
|
|
@ -51,8 +51,7 @@ class User extends Authenticatable
|
|||
|
||||
public function tips()
|
||||
{
|
||||
return $this->hasManyThrough(Tip::class, Meme::class, 'address_id', 'id', 'id', 'address_id');
|
||||
return $this->hasManyThrough(Tip::class, Meme::class, 'id', 'address_id');
|
||||
return $this->hasManyThrough(Tip::class, Meme::class, 'user_id');
|
||||
}
|
||||
|
||||
public function getMemesTotalAttribute()
|
||||
|
|
|
@ -26,7 +26,7 @@ class ValidateAddress implements Rule
|
|||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$walletRPC = new walletRPC('127.0.0.1', config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$walletRPC = new walletRPC(config('app.xmr_daemon_ip'), config('app.xmr_network_port')); // Change to match your wallet (monero-wallet-rpc) IP address and port; 18083 is the customary port for mainnet, 28083 for testnet, 38083 for stagenet
|
||||
$open_wallet = $walletRPC->open_wallet(config('app.xmr_wallet_name'), '');
|
||||
$validate_address = $walletRPC->validate_address($value);
|
||||
return $validate_address['valid'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue