first commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Proxy;
|
||||
|
||||
class FetchProxies extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'proxies:fetch';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch proxies from the CDN and save them to the database';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Fetching proxies from CDN...');
|
||||
|
||||
try {
|
||||
$response = Http::get('https://cdn.jsdelivr.net/gh/proxifly/free-proxy-list@main/proxies/all/data.json');
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \Exception('Failed to fetch proxies: ' . $response->status());
|
||||
}
|
||||
|
||||
$proxies = $response->json();
|
||||
$this->info('Found ' . count($proxies) . ' proxies');
|
||||
|
||||
$bar = $this->output->createProgressBar(count($proxies));
|
||||
$bar->start();
|
||||
|
||||
$saved = 0;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($proxies as $proxyData) {
|
||||
// Check if proxy already exists
|
||||
$exists = Proxy::where('proxy', $proxyData['proxy'])->exists();
|
||||
|
||||
if (!$exists) {
|
||||
Proxy::create([
|
||||
'proxy' => $proxyData['proxy'],
|
||||
'protocol' => $proxyData['protocol'],
|
||||
'ip' => $proxyData['ip'],
|
||||
'port' => $proxyData['port'],
|
||||
'https' => $proxyData['https'],
|
||||
'anonymity' => $proxyData['anonymity'],
|
||||
'score' => $proxyData['score'],
|
||||
'country' => $proxyData['geolocation']['country'] ?? null,
|
||||
'city' => $proxyData['geolocation']['city'] ?? null,
|
||||
]);
|
||||
$saved++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Proxies imported successfully!");
|
||||
$this->info("New proxies saved: {$saved}");
|
||||
$this->info("Existing proxies skipped: {$skipped}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\ProxiesList;
|
||||
use App\Models\Proxy;
|
||||
|
||||
class FetchProxyLists extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'proxies:fetch-lists {--timeout=30}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch proxy lists that haven\'t been scraped in the last 4 hours';
|
||||
|
||||
protected $timeout;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->timeout = $this->option('timeout');
|
||||
$this->info('Starting proxy list fetching...');
|
||||
|
||||
// Get lists that haven't been scraped in the last 4 hours
|
||||
$lists = ProxiesList::where(function($query) {
|
||||
$query->whereNull('last_scraped_at')
|
||||
->orWhere('last_scraped_at', '<', now()->subHours(12));
|
||||
})->get();
|
||||
|
||||
if ($lists->isEmpty()) {
|
||||
$this->info('No proxy lists need to be fetched.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->info('Found ' . $lists->count() . ' lists to process');
|
||||
$bar = $this->output->createProgressBar($lists->count());
|
||||
$bar->start();
|
||||
|
||||
$results = [
|
||||
'success' => 0,
|
||||
'failed' => 0,
|
||||
'proxies_added' => 0
|
||||
];
|
||||
|
||||
foreach ($lists as $list) {
|
||||
try {
|
||||
$this->processList($list, $results);
|
||||
$list->update(['last_scraped_at' => now()]);
|
||||
$results['success']++;
|
||||
} catch (\Exception $e) {
|
||||
$this->error("\nError processing {$list->url}: " . $e->getMessage());
|
||||
$results['failed']++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info('Proxy list fetching completed!');
|
||||
$this->info("Successfully processed: {$results['success']}");
|
||||
$this->info("Failed to process: {$results['failed']}");
|
||||
$this->info("New proxies added: {$results['proxies_added']}");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function processList(ProxiesList $list, array &$results)
|
||||
{
|
||||
$client = new \GuzzleHttp\Client([
|
||||
'timeout' => $this->timeout,
|
||||
'verify' => false,
|
||||
'http_errors' => false
|
||||
]);
|
||||
|
||||
$response = $client->get($list->url);
|
||||
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new \Exception("Failed to fetch list: HTTP {$response->getStatusCode()}");
|
||||
}
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
|
||||
if ($list->scrape_type === 'new_line') {
|
||||
$this->processNewLineList($content, $list->proxy_type, $results);
|
||||
} else {
|
||||
$this->processWebsiteList($content, $list->proxy_type, $results);
|
||||
}
|
||||
}
|
||||
|
||||
protected function processNewLineList(string $content, string $proxyType, array &$results)
|
||||
{
|
||||
$lines = array_filter(explode("\n", $content));
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (empty($line)) continue;
|
||||
|
||||
// Try to parse IP:PORT format
|
||||
if (preg_match('/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d+)$/', $line, $matches)) {
|
||||
$ip = $matches[1];
|
||||
$port = (int) $matches[2];
|
||||
$proxyUrl = "{$proxyType}://{$ip}:{$port}";
|
||||
|
||||
$this->saveProxy($proxyUrl, $proxyType, $ip, $port, $results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function processWebsiteList(string $content, string $proxyType, array &$results)
|
||||
{
|
||||
// Extract IP:PORT patterns from HTML content
|
||||
preg_match_all('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d+)/', $content, $matches);
|
||||
|
||||
if (empty($matches[0])) {
|
||||
throw new \Exception('No proxy patterns found in website content');
|
||||
}
|
||||
|
||||
foreach ($matches[0] as $match) {
|
||||
list($ip, $port) = explode(':', $match);
|
||||
$port = (int) $port;
|
||||
$proxyUrl = "{$proxyType}://{$ip}:{$port}";
|
||||
|
||||
$this->saveProxy($proxyUrl, $proxyType, $ip, $port, $results);
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveProxy(string $proxyUrl, string $proxyType, string $ip, int $port, array &$results)
|
||||
{
|
||||
// Check if proxy already exists
|
||||
$exists = Proxy::where('proxy', $proxyUrl)->exists();
|
||||
|
||||
if (!$exists) {
|
||||
Proxy::create([
|
||||
'proxy' => $proxyUrl,
|
||||
'protocol' => $proxyType,
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
'https' => $proxyType === 'https',
|
||||
'anonymity' => 'unknown',
|
||||
'score' => 1
|
||||
]);
|
||||
$results['proxies_added']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Proxy;
|
||||
|
||||
class FetchProxyScrape extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'proxies:fetch-scrape';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fetch proxies from ProxyScrape API and save them to the database';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Fetching proxies from ProxyScrape API...');
|
||||
|
||||
try {
|
||||
$response = Http::get('https://api.proxyscrape.com/v3/free-proxy-list/get?request=displayproxies&protocol=http&proxy_format=ipport&format=text&timeout=20000');
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \Exception('Failed to fetch proxies: ' . $response->status());
|
||||
}
|
||||
|
||||
$proxyList = explode("\n", trim($response->body()));
|
||||
$this->info('Found ' . count($proxyList) . ' proxies');
|
||||
|
||||
$bar = $this->output->createProgressBar(count($proxyList));
|
||||
$bar->start();
|
||||
|
||||
$saved = 0;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($proxyList as $proxyString) {
|
||||
$proxyString = trim($proxyString);
|
||||
if (empty($proxyString)) continue;
|
||||
|
||||
// Parse IP and Port from the proxy string
|
||||
list($ip, $port) = explode(':', $proxyString);
|
||||
$proxyUrl = "http://{$ip}:{$port}";
|
||||
|
||||
// Check if proxy already exists
|
||||
$exists = Proxy::where('proxy', $proxyUrl)->exists();
|
||||
|
||||
if (!$exists) {
|
||||
Proxy::create([
|
||||
'proxy' => $proxyUrl,
|
||||
'protocol' => 'http',
|
||||
'ip' => $ip,
|
||||
'port' => (int) $port,
|
||||
'https' => false, // Default to false since these are HTTP proxies
|
||||
'anonymity' => 'unknown', // ProxyScrape doesn't provide anonymity info
|
||||
'score' => 1, // Default score
|
||||
'country' => null, // ProxyScrape doesn't provide geolocation
|
||||
'city' => null,
|
||||
]);
|
||||
$saved++;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info("Proxies imported successfully!");
|
||||
$this->info("New proxies saved: {$saved}");
|
||||
$this->info("Existing proxies skipped: {$skipped}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Proxy;
|
||||
|
||||
class TestProxies extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'proxies:test {--timeout=10} {--concurrent=10}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Test proxies against the test endpoint';
|
||||
|
||||
protected $testUrl;
|
||||
protected $timeout;
|
||||
protected $concurrent;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->testUrl = config('app.url') . '/proxy-test';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->timeout = $this->option('timeout');
|
||||
$this->concurrent = $this->option('concurrent');
|
||||
|
||||
$this->info('Starting proxy testing...');
|
||||
$this->info("Test URL: {$this->testUrl}");
|
||||
$this->info("Timeout: {$this->timeout}s");
|
||||
$this->info("Concurrent tests: {$this->concurrent}");
|
||||
|
||||
$proxies = Proxy::all();
|
||||
$this->info('Found ' . $proxies->count() . ' proxies to test');
|
||||
|
||||
$bar = $this->output->createProgressBar($proxies->count());
|
||||
$bar->start();
|
||||
|
||||
$chunks = $proxies->chunk($this->concurrent);
|
||||
$results = [
|
||||
'working' => 0,
|
||||
'failed' => 0,
|
||||
'timeout' => 0
|
||||
];
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
$promises = [];
|
||||
foreach ($chunk as $proxy) {
|
||||
$promises[] = $this->testProxy($proxy, $results);
|
||||
}
|
||||
|
||||
// Wait for all promises to complete
|
||||
foreach ($promises as $promise) {
|
||||
$promise->wait();
|
||||
}
|
||||
|
||||
$bar->advance($chunk->count());
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info('Proxy testing completed!');
|
||||
$this->info("Working proxies: {$results['working']}");
|
||||
$this->info("Failed proxies: {$results['failed']}");
|
||||
$this->info("Timeout proxies: {$results['timeout']}");
|
||||
}
|
||||
|
||||
protected function testProxy($proxy, &$results)
|
||||
{
|
||||
return new \GuzzleHttp\Promise\Promise(function() use ($proxy, &$results) {
|
||||
try {
|
||||
$client = new \GuzzleHttp\Client([
|
||||
'proxy' => $proxy->proxy,
|
||||
'timeout' => $this->timeout,
|
||||
'verify' => false,
|
||||
'http_errors' => false
|
||||
]);
|
||||
|
||||
$response = $client->get($this->testUrl);
|
||||
$body = json_decode($response->getBody(), true);
|
||||
|
||||
if ($response->getStatusCode() === 200 && isset($body['unique_id'])) {
|
||||
// Proxy is working, increase score
|
||||
$proxy->increment('score');
|
||||
$results['working']++;
|
||||
} else {
|
||||
// Proxy returned invalid response
|
||||
$proxy->decrement('score');
|
||||
$results['failed']++;
|
||||
}
|
||||
} catch (\GuzzleHttp\Exception\ConnectException $e) {
|
||||
// Connection failed
|
||||
$proxy->decrement('score');
|
||||
$results['failed']++;
|
||||
} catch (\GuzzleHttp\Exception\RequestException $e) {
|
||||
if ($e->getCode() === CURLE_OPERATION_TIMEDOUT) {
|
||||
// Request timed out
|
||||
$proxy->decrement('score');
|
||||
$results['timeout']++;
|
||||
} else {
|
||||
// Other request error
|
||||
$proxy->decrement('score');
|
||||
$results['failed']++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class ProxiesList extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'proxies_list';
|
||||
|
||||
protected $fillable = [
|
||||
'url',
|
||||
'scrape_type',
|
||||
'proxy_type',
|
||||
'last_scraped_at'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_scraped_at' => 'datetime'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Proxy extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'proxy',
|
||||
'protocol',
|
||||
'ip',
|
||||
'port',
|
||||
'https',
|
||||
'anonymity',
|
||||
'score',
|
||||
'country',
|
||||
'city'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'https' => 'boolean',
|
||||
'port' => 'integer',
|
||||
'score' => 'integer'
|
||||
];
|
||||
|
||||
public function getGeolocationAttribute()
|
||||
{
|
||||
return [
|
||||
'country' => $this->country,
|
||||
'city' => $this->city
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user