Initial implementation of the HomeSysPanel CMS built with Laravel 13.0. Includes complete admin panel, content management, user authentication, modular architecture for products/services/chatbot, and marketing tools. Key features: - User authentication with email verification and password reset - Role-based access control (Admin/User with granular permissions) - Content management (pages, news, FAQ, downloads, galleries, banners) - Contact management system with subjects and responses - Marketing tools (email campaigns, visitor analytics, social sharing) - Modular architecture (Products, Services, Chatbot modules) - AI Chatbot integration with OpenRouter.ai and LlamaCpp support - Visitor tracking with geolocation - SEO optimization with meta tags and Open Graph - Responsive design with Bootstrap 5 - Dark mode support - Maintenance mode - Feature request system
147 lines
4.4 KiB
PHP
Executable File
147 lines
4.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Models\Setting;
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
use App\Notifications\NewUserRegisteredNotification;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Register Controller
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This controller handles the registration of new users as well as their
|
|
| validation and creation. By default this controller uses a trait to
|
|
| provide this functionality without requiring any additional code.
|
|
|
|
|
*/
|
|
|
|
use RegistersUsers;
|
|
|
|
/**
|
|
* Where to redirect users after registration.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $redirectTo = '/home';
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('guest');
|
|
}
|
|
|
|
/**
|
|
* Check if public registration is enabled.
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function isRegistrationEnabled()
|
|
{
|
|
return Setting::get('public_registration', 'off') === 'on';
|
|
}
|
|
|
|
/**
|
|
* Show the application registration form.
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
|
*/
|
|
public function showRegistrationForm()
|
|
{
|
|
if (!$this->isRegistrationEnabled()) {
|
|
return redirect()->route('login')->with('error', 'O registro público está desativado no momento.');
|
|
}
|
|
|
|
return view('auth.register');
|
|
}
|
|
|
|
/**
|
|
* Handle a registration request for the application.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
|
*/
|
|
public function register(\Illuminate\Http\Request $request)
|
|
{
|
|
if (!$this->isRegistrationEnabled()) {
|
|
return redirect()->route('login')->with('error', 'O registro público está desativado no momento.');
|
|
}
|
|
|
|
$request->validate(['captcha' => 'required|numeric']);
|
|
if ($request->captcha != session('captcha_result')) {
|
|
throw \Illuminate\Validation\ValidationException::withMessages([
|
|
'captcha' => ['O resultado da soma está incorreto.'],
|
|
]);
|
|
}
|
|
|
|
$this->validator($request->all())->validate();
|
|
|
|
event(new \Illuminate\Auth\Events\Registered($user = $this->create($request->all())));
|
|
|
|
$this->guard()->login($user);
|
|
|
|
if ($response = $this->registered($request, $user)) {
|
|
return $response;
|
|
}
|
|
|
|
return $request->wantsJson()
|
|
? new \Illuminate\Http\JsonResponse([], 201)
|
|
: redirect($this->redirectPath());
|
|
}
|
|
|
|
/**
|
|
* Get a validator for an incoming registration request.
|
|
*
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
*/
|
|
protected function validator(array $data)
|
|
{
|
|
return Validator::make($data, [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
'company' => ['nullable', 'string', 'max:255'],
|
|
'website' => ['nullable', 'string', 'max:255'],
|
|
'whatsapp' => ['nullable', 'string', 'max:20'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Create a new user instance after a valid registration.
|
|
*
|
|
* @return User
|
|
*/
|
|
protected function create(array $data)
|
|
{
|
|
$user = User::create([
|
|
'name' => $data['name'],
|
|
'email' => $data['email'],
|
|
'password' => Hash::make($data['password']),
|
|
'user_type' => 'User', // Force all public registrations to be regular users
|
|
'company' => $data['company'] ?? null,
|
|
'website' => $data['website'] ?? null,
|
|
'whatsapp' => $data['whatsapp'] ?? null,
|
|
'permissions' => [],
|
|
]);
|
|
|
|
// Notificar administradores sobre o novo cadastro
|
|
$admins = User::where('user_type', 'Admin')->get();
|
|
Notification::send($admins, new NewUserRegisteredNotification($user));
|
|
|
|
return $user;
|
|
}
|
|
}
|