mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-09-29 21:13:05 -04:00
307 lines
14 KiB
PHP
307 lines
14 KiB
PHP
<?php
|
|
namespace Modules\WTISignupForms\Services;
|
|
|
|
class AugmentationService
|
|
{
|
|
public function __construct() {
|
|
$this->updateAuthRepository();
|
|
$this->updateRegisterController();
|
|
}
|
|
|
|
|
|
public function updateAuthRepository() {
|
|
|
|
$path = app_path('Repositories/AuthRepository.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
|
|
|
|
if (!preg_match("/function register\(\$data\,\$role_id = 4\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function register\((.*?)\)/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("function register(\$data)", "function register(\$data,\$role_id = 4)",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+function register\((.*?)\)/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/function getRegister\(\$user\,\$role_id = 4\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function getRegister\((.*?)\)/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("function getRegister(\$user)", "function getRegister(\$user,\$role_id = 4)",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+function getRegister\((.*?)\)/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/\-\>where\(\'role_id',\$role_id\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function getRegister\((.*?)\)[.\s\S]+where\(\'is_active\'\,2\)\-\>first\(\)/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("where('is_active',2)->first()", "where('is_active',2)->where('role_id',\$role_id)->first()",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+where\(\'is_active\'\,2\)\-\>first\(\)/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/[.\s\S]+function getRegister[.\s\S]+\'role_id\' => \$role_id/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function getRegister[.\s\S]+\'role_id\' => 4\,/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("'role_id' => 4", "'role_id' => \$role_id",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+function getRegister[.\s\S]+\'role_id\' => 4\,/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public function updateRegisterController() {
|
|
$path = app_path('Http/Controllers/Auth/RegisterController.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/function create\(\$data\,\$role_id = 4\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function create\((.*?)\)/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("function create(\$data)", "function create(\$data,\$role_id = 4)",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+function create\((.*?)\)/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/isModuleActive\(\'WTISignupForms\'\)\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/', $content, $matches);
|
|
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "\n\n\t\tif(isModuleActive('WTISignupForms')){\n\t\t\t\$user->phone = \$data['phone'];\n\t\t\t\$user->job_category_id = \$data['job_type'];\n\t\t\t\$user->company = \$data['company'];\n\t\t\t\$user->website = \$data['website'];\n\t\t\t\$user->address = \$data['address'];\n\t\t\t\$user->notes = \$data['notes'];\n\t\t\t\$user->interest = \$data['interest'];\n\t\t\t\$user->technical = \$data['technical'];\n\t\t\t\$user->works = \$data['works'];\n\t\t\t\$user->wti = \$data['wti'];\n\t\t\t\$user->geographically = \$data['geographically'];\n\t\t\t\$user->save();\n\t\t}\n\n";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/\'role_id\' => \$role_id/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+\'role_id\' => 4\,/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = str_replace("'role_id' => 4", "'role_id' => \$role_id",$matches[0]);
|
|
$content = preg_replace("/[.\s\S]+\'role_id\' => 4\,/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/showClientRegisterForm\(/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function showRegistrationForm\([.\s\S]+?return view\(theme\(\'auth\.register\'\)[.\s\S]+?}/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
|
|
public function showClientRegisterForm()
|
|
{
|
|
\$row = '';
|
|
\$form_data = '';
|
|
if(Module::has('FormBuilder')){
|
|
if(Schema::hasTable('custom_forms')){
|
|
\$formBuilderRepo = new FormBuilderRepositories();
|
|
\$row = \$formBuilderRepo->find(2);
|
|
if(\$row->form_data){
|
|
\$form_data = json_decode(\$row->form_data);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(url()->previous() == url('/checkout') || url()->previous() == url('/checkout?checkout_type=YnV5X2l0X25vdw==')){
|
|
session()->put('from_checkout',url()->previous());
|
|
}
|
|
|
|
\$loginPageInfo = LoginPage::findOrFail(10);
|
|
\$categories = [];
|
|
if (isModuleActive('JobPortal')) {
|
|
\$categories = \Modules\JobPortal\Entities\JobCategory::orderBy('id')->get();
|
|
}
|
|
|
|
return view('wtisignupforms::client_register',compact('row','form_data','loginPageInfo','categories'));
|
|
}
|
|
|
|
|
|
public function clientRegister(Request \$request)
|
|
{
|
|
session()->put('register_type', \$request->register_type);
|
|
|
|
\$request->validate( [
|
|
'job_type' => ['required', 'exists:jp_job_categories,id'],
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'last_name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'max:255'],
|
|
'phone' => ['required', 'string', 'max:255'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
'referred_by' => ['nullable', 'string', 'max:255'],
|
|
'referral_code' => ['sometimes', 'nullable', Rule::exists('referral_codes', 'referral_code')->where('status', 1)],
|
|
'company' => ['nullable', 'string', 'max:255'],
|
|
'website' => ['nullable', 'string', 'max:255'],
|
|
'address' => ['nullable', 'string', 'max:255'],
|
|
'notes' => ['nullable', 'string', 'max:255'],
|
|
],
|
|
[
|
|
'password.min' => 'The password field minimum 8 character.',
|
|
|
|
]);
|
|
if (isModuleActive('Otp') && otp_configuration('otp_activation_for_customer')) {
|
|
try {
|
|
if (!\$this->sendOtp(\$request)) {
|
|
Toastr::error(__('otp.something_wrong_on_otp_send'), __('common.error'));
|
|
return back();
|
|
}
|
|
return view(theme('auth.otp'), compact('request'));
|
|
} catch (Exception \$e) {
|
|
LogActivity::errorLog(\$e->getMessage());
|
|
Toastr::error(__('otp.something_wrong_on_otp_send'), __('common.error'));
|
|
return back();
|
|
}
|
|
}
|
|
\$authRepos = new AuthRepository();
|
|
\$user_exist = \$authRepos->getRegister(\$request->all());
|
|
if(\$user_exist){
|
|
\$prev_session_id = session()->getId();
|
|
\$buy_it_now = session()->get('buy_it_now');
|
|
\$this->guard()->login(\$user_exist);
|
|
\$this->dataUpdateWhenLogin(\$prev_session_id, \$buy_it_now);
|
|
Toastr::success(__('auth.successfully_registered'), __('common.success'));
|
|
LogActivity::addLoginLog(Auth::user()->id, Auth::user()->first_name . ' - logged in at : ' . Carbon::now());
|
|
return \$this->registered(\$request, \$user_exist) ?: redirect(\$this->redirectPath());
|
|
}
|
|
\$this->validator(\$request->all())->validate();
|
|
event(new Registered(\$user = \$this->create(\$request)));
|
|
\$prev_session_id = session()->getId();
|
|
\$buy_it_now = session()->get('buy_it_now');
|
|
\$this->guard()->login(\$user);
|
|
\$this->dataUpdateWhenLogin(\$prev_session_id, \$buy_it_now);
|
|
Toastr::success(__('auth.successfully_registered'), __('common.success'));
|
|
LogActivity::addLoginLog(Auth::user()->id, Auth::user()->first_name . ' - logged in at : ' . Carbon::now());
|
|
return \$this->registered(\$request, \$user) ?: redirect(\$this->redirectPath());
|
|
}
|
|
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/[.\s\S]+function showRegistrationForm\([.\s\S]+?return view\(theme\(\'auth\.register\'\)[.\s\S]+?}/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/showStaffRegisterForm\(/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+function showRegistrationForm\([.\s\S]+?return view\(theme\(\'auth\.register\'\)[.\s\S]+?}/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
|
|
public function showStaffRegisterForm()
|
|
{
|
|
\$row = '';
|
|
\$form_data = '';
|
|
if(Module::has('FormBuilder')){
|
|
if(Schema::hasTable('custom_forms')){
|
|
\$formBuilderRepo = new FormBuilderRepositories();
|
|
\$row = \$formBuilderRepo->find(2);
|
|
if(\$row->form_data){
|
|
\$form_data = json_decode(\$row->form_data);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(url()->previous() == url('/checkout') || url()->previous() == url('/checkout?checkout_type=YnV5X2l0X25vdw==')){
|
|
session()->put('from_checkout',url()->previous());
|
|
}
|
|
|
|
\$loginPageInfo = LoginPage::findOrFail(11);
|
|
\$locations = [];
|
|
if (isModuleActive('JobPortal')) {
|
|
\$locations = \Modules\JobPortal\Entities\Location::orderBy('id')->get();
|
|
}
|
|
return view('wtisignupforms::staff_register',compact('row','form_data','loginPageInfo','locations'));
|
|
}
|
|
|
|
|
|
public function staffRegister(Request \$request)
|
|
{
|
|
session()->put('register_type', \$request->register_type);
|
|
|
|
\$request->validate( [
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'max:255'],
|
|
'phone' => ['required', 'string', 'max:255'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
//'location' => ['required', 'exists:jp_locations,id'],
|
|
'referral_code' => ['sometimes', 'nullable', Rule::exists('referral_codes', 'referral_code')->where('status', 1)],
|
|
'interest' => ['required', 'string', 'max:255'],
|
|
'technical' => ['required', 'string', 'max:255'],
|
|
'your_work' => ['required', 'string', 'max:255'],
|
|
'wti' => ['required', 'string', 'max:255'],
|
|
'geographically' => ['required', 'string', 'max:255'],
|
|
|
|
],
|
|
[
|
|
'password.min' => 'The password field minimum 8 character.',
|
|
|
|
]);
|
|
if (isModuleActive('Otp') && otp_configuration('otp_activation_for_customer')) {
|
|
try {
|
|
if (!\$this->sendOtp(\$request)) {
|
|
Toastr::error(__('otp.something_wrong_on_otp_send'), __('common.error'));
|
|
return back();
|
|
}
|
|
return view(theme('auth.otp'), compact('request'));
|
|
} catch (Exception \$e) {
|
|
LogActivity::errorLog(\$e->getMessage());
|
|
Toastr::error(__('otp.something_wrong_on_otp_send'), __('common.error'));
|
|
return back();
|
|
}
|
|
}
|
|
\$authRepos = new AuthRepository();
|
|
\$user_exist = \$authRepos->getRegister(\$request->all(),3);
|
|
if(\$user_exist){
|
|
\$prev_session_id = session()->getId();
|
|
\$buy_it_now = session()->get('buy_it_now');
|
|
\$this->guard()->login(\$user_exist);
|
|
\$this->dataUpdateWhenLogin(\$prev_session_id, \$buy_it_now);
|
|
Toastr::success(__('auth.successfully_registered'), __('common.success'));
|
|
LogActivity::addLoginLog(Auth::user()->id, Auth::user()->first_name . ' - logged in at : ' . Carbon::now());
|
|
return \$this->registered(\$request, \$user_exist) ?: redirect(\$this->redirectPath());
|
|
}
|
|
\$this->validator(\$request->all())->validate();
|
|
event(new Registered(\$user = \$this->create(\$request,3)));
|
|
\$prev_session_id = session()->getId();
|
|
\$buy_it_now = session()->get('buy_it_now');
|
|
\$this->guard()->login(\$user);
|
|
\$this->dataUpdateWhenLogin(\$prev_session_id, \$buy_it_now);
|
|
Toastr::success(__('auth.successfully_registered'), __('common.success'));
|
|
LogActivity::addLoginLog(Auth::user()->id, Auth::user()->first_name . ' - logged in at : ' . Carbon::now());
|
|
return \$this->registered(\$request, \$user) ?: redirect(\$this->redirectPath());
|
|
}
|
|
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/[.\s\S]+function showRegistrationForm\([.\s\S]+?return view\(theme\(\'auth\.register\'\)[.\s\S]+?}/", $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
} |