diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index a120b65..f9e5797 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -386,7 +386,7 @@ class EmployerController extends Controller // Данные $users = $users->Baseuser()-> - orderBy(Worker::select('position_work')->whereColumn('workers.user_id', 'users.id'))-> + orderBy(Worker::select('position_work')->whereColumn('Workers.user_id', 'users.id'))-> paginate(5); return view('employers.bd', compact('users')); diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 61d9929..6aeafc2 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -4,14 +4,22 @@ namespace App\Http\Controllers; use App\Models\Message; use App\Models\Static_worker; +use App\Models\User; use App\Models\Worker; +use Illuminate\Auth\Events\Registered; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Validator; class WorkerController extends Controller { - public $status_work = Array(0 => 'Ищу работу', 1=> 'Не указано', 2=>'Не ищу работу'); + public $status_work = array(0 => 'Ищу работу', 1 => 'Не указано', 2 => 'Не ищу работу'); + //профиль - public function profile(Worker $worker) { + public function profile(Worker $worker) + { $get_date = date('Y.m'); $c = Static_worker::query()->where('year_month', '=', $get_date) @@ -31,14 +39,15 @@ class WorkerController extends Controller } $stat = Static_worker::query()->where('year_month', '=', $get_date) - ->where('user_id', '=', $worker->users->id) - ->get(); + ->where('user_id', '=', $worker->users->id) + ->get(); return view('public.workers.profile', compact('worker', 'stat')); } // лист база резюме - public function bd_resume() { + public function bd_resume() + { $status_work = $this->status_work; $resumes = Worker::query()->with('users')->with('job_titles'); @@ -49,7 +58,8 @@ class WorkerController extends Controller } // анкета соискателя - public function resume_profile(Worker $worker) { + public function resume_profile(Worker $worker) + { $status_work = $this->status_work; $Query = Worker::query()->with('users')->with('job_titles') ->with('place_worker')->with('sertificate')->with('prev_company') @@ -60,22 +70,26 @@ class WorkerController extends Controller } // скачать анкету соискателя - public function resume_download(Worker $worker) { + public function resume_download(Worker $worker) + { print_r('Резюме для скачивания'); } // Кабинет работника - public function cabinet(Worker $worker) { + public function cabinet(Worker $worker) + { return view('workers.cabinet', compact('worker')); } // Сохранение данных - public function cabinet_save(Worker $worker, Request $request) { + public function cabinet_save(Worker $worker, Request $request) + { } // Сообщения данные - public function messages($type_message) { + public function messages($type_message) + { $user_id = Auth()->user()->id; $messages_input = Message::query()->with('vacancies')->with('user_from')-> @@ -101,20 +115,89 @@ class WorkerController extends Controller } // Избранный - public function favorite() { + public function favorite() + { return view('workers.favorite'); } // Сменить пароль - public function new_password() { + public function new_password() + { return view('workers.new_password'); } // Удаление профиля - public function delete_profile() { + public function delete_profile() + { return view('workers.delete_profile'); } + + // Регистрация соискателя + public function register_worker(Request $request) + { + $params = $request->all(); + + $rules = [ + 'surname' => ['required', 'string', 'max:255'], + 'name_man' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'password' => ['required', 'string', 'min:8'], + 'confirmed' => ['required', 'string', 'min:8'], + ]; + + $messages = [ + 'required' => 'Укажите обязательное поле', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'integer' => 'Поле «:attribute» должно быть :min или больше', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'integer' => 'Поле «:attribute» должно быть :max или меньше', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ] + ]; + + + + if ($request->get('password') !== $request->get('confirmed')){ + return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); + } + + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return json_encode(Array("ERROR" => "Error: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены")); + } else { + $user = $this->create($params); + event(new Registered($user)); + + Auth::guard()->login($user); + } + if ($user) { + return json_encode(Array("REDIRECT" => redirect()->route('worker.cabinet')->getTargetUrl()));; + } else { + return json_encode(Array("ERROR" => "Данные были утеряны!")); + } + } + + // Создание пользователя + protected function create(array $data) + { + $Use = new User(); + $Code_user = $Use->create([ + 'name' => $data['surname']." ".$data['name_man'], + 'subscribe_email' => $data['email'], + 'email' => $data['email'], + 'telephone' => $data['telephone'], + 'password' => Hash::make($data['password']), + 'pubpassword' => base64_encode($data['password']), + ]); + dd($Code_user); + } } + diff --git a/app/Providers/MyServiceProvider.php b/app/Providers/MyServiceProvider.php index 9252423..6439f42 100644 --- a/app/Providers/MyServiceProvider.php +++ b/app/Providers/MyServiceProvider.php @@ -108,5 +108,14 @@ class MyServiceProvider extends ServiceProvider $view_worker->with(['id_worker' => $id_worker, 'Worker' => $Worker, 'User' => $user]); } ); + + $view_job_title = ['modals.register']; + View::composer($view_job_title, + function($view_job_title) { + $Job_titles = Job_title::query()->get(); + $view_job_title->with(['Job_titles' => $Job_titles]); + } + ); + } } diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 986f149..adc0435 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -36,6 +36,62 @@ } }); }); + + $(document).on('click', '#button_reg_worker', function() { + var field_login = $('#email_worker'); + var field_pwd = $('#password_worker'); + var field_confirm_pwd = $('#password_confirmation_worker'); + var field_politik_worker = $('#politik_worker'); + var field_telephone_worker = $('#telephone_worker'); + var field_job_titles_worker = $('#job_titles_worker'); + var field_surname_worker = $('#surname_worker'); + var field_name_man = $('#name_man_worker'); + var field_surname2_worker = $('#surname2_worker'); + + var login = field_login.val(); + var pwd = field_pwd.val(); + var confirm_pwd = field_confirm_pwd.val(); + var politik = field_politik_worker.val(); + var telephone = field_telephone_worker.val(); + var job_titles = field_job_titles_worker.val(); + var surname = field_surname_worker.val(); + var name_man = field_name_man.val(); + var surname2 = field_surname2_worker.val(); + + + console.log('login: '+login+' password: '+pwd); + + $.ajax({ + type: "GET", + url: "{{ route('register_worker') }}", + data: "email="+login+"&password="+pwd+"&confirmed="+confirm_pwd+"&politik="+politik+ + "&telephone="+telephone+"&job_titles="+job_titles+"&surname="+surname+"&name_man="+name_man+ + "&surname2="+surname2+"&subscribe_email="+login, + success: function (data) { + console.log('Вход в систему'); + let d = JSON.parse(data); + if(typeof d['REDIRECT'] !== "undefined") { + console.log(d['REDIRECT']); + //location.href = d['REDIRECT']; + } + if (typeof d['ERROR'] !== "undefined") { + console.log(d['ERROR']); + //$('#message_error').html(d['ERROR']); + } + console.log(d['REDIRECT']); + //$('#block_1').html(data); + }, + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + }, + error: function (data) { + data = JSON.stringify(data); + console.log('Error: ' + data); + } + }); + + return false; + }); @endsection diff --git a/resources/views/modals/register.blade.php b/resources/views/modals/register.blade.php index 077434d..32e2c53 100644 --- a/resources/views/modals/register.blade.php +++ b/resources/views/modals/register.blade.php @@ -9,91 +9,112 @@