diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index 028569d..8438263 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -363,14 +363,40 @@ class EmployerController extends Controller return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); } + if (strlen($request->get('password')) < 8) { + return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); + } + + $specsumbol = Array('!','~', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', ';', ':', '<', '>', '?'); + $alpha = Array('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', + 'X', 'C', 'V', 'B', 'N', 'M'); + $spec_bool = false; + $alpha_bool = false; + + $haystack = $request->get('password'); + + foreach ($specsumbol as $it) { + if (strpos($haystack, $it) !== false) { + $spec_bool = true; + } + } + + foreach ($alpha as $it) { + if (strpos($haystack, $it) !== false) { + $alpha_bool = true; + } + } + + if ((!$spec_bool) || (!$alpha_bool)) { + return json_encode(Array("ERROR" => "Error: Нет спецсимволов в пароле, латинские буквы заглавные, а также один из символов: !~#$%^&*()-=;,:<>?")); + } + if (empty($request->get('surname'))) { $params['surname'] = 'Неизвестно'; } - if (empty($request->get('name_man'))) { $params['name_man'] = 'Неизвестно'; } - $validator = Validator::make($params, $rules, $messages); if ($validator->fails()) { @@ -378,9 +404,9 @@ class EmployerController extends Controller } else { $user = $this->create($params); event(new Registered($user)); - Auth::guard()->login($user); } + if ($user) { return json_encode(Array("REDIRECT" => redirect()->route('employer.cabinet')->getTargetUrl()));; } else { diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 6eb9758..343f810 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -22,6 +22,7 @@ use App\Models\reclame; use App\Models\ResponseWork; use App\Models\sertification; use App\Models\Static_worker; +use App\Models\Title_worker; use App\Models\User; use App\Models\User as User_Model; use App\Models\Worker; @@ -469,7 +470,7 @@ class WorkerController extends Controller $rules = [ 'surname' => ['required', 'string', 'max:255'], 'name_man' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'email' => ['required', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8'] ]; @@ -487,6 +488,10 @@ class WorkerController extends Controller ] ]; + if (empty($request->get('email'))) { + return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); + } + if ($request->get('password') !== $request->get('confirmed')){ return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); } @@ -496,9 +501,12 @@ class WorkerController extends Controller $specsumbol = Array('!','~', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', ';', ':', '<', '>', '?'); $alpha = Array('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'); + $lenpwd_bool = true; $spec_bool = false; $alpha_bool = false; + if (strlen($haystack) < 8) $lenpwd_bool = false; + foreach ($specsumbol as $it) { if (strpos($haystack, $it) !== false) { $spec_bool = true; @@ -511,6 +519,10 @@ class WorkerController extends Controller } } + if (!$lenpwd_bool) { + return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); + } + if ((!$spec_bool) || (!$alpha_bool)) { return json_encode(Array("ERROR" => "Error: Нет спецсимволов в пароле, латинские буквы заглавные, а также один из символов: !~#$%^&*()-=;,:<>?")); } @@ -521,7 +533,7 @@ class WorkerController extends Controller if ($validator->fails()) { return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); } else { - + //dd($params); $user = $this->create($params); event(new Registered($user)); Auth::guard()->login($user); @@ -561,10 +573,44 @@ class WorkerController extends Controller return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); } + public function TestWorker() + { + $Use = new User(); + + $Code_user = $Use->create([ + 'name' => 'surname name_man', + 'name_man' => 'name_man', + 'surname' => 'surname', + 'surname2' => 'surname2', + 'subscribe_email' => '1', + 'email' => 'email@mail.com', + 'telephone' => '1234567890', + 'password' => Hash::make('password'), + 'pubpassword' => base64_encode('password'), + 'email_verified_at' => Carbon::now(), + 'is_worker' => 1, + ]); + + if ($Code_user->id > 0) { + $Worker = new Worker(); + $Worker->user_id = $Code_user->id; + $Worker->position_work = 1; //'job_titles'; + $Worker->email = 'email@email.com'; + $Worker->telephone = '1234567890'; + $status = $Worker->save(); + + $Title_Worker = new Title_worker(); + $Title_Worker->worker_id = $Worker->id; + $Title_Worker->job_title_id = 1; + $Title_Worker->save(); + } + } + // Создание пользователя protected function create(array $data) { $Use = new User(); + $Code_user = $Use->create([ 'name' => $data['surname']." ".$data['name_man'], 'name_man' => $data['name_man'], @@ -578,6 +624,7 @@ class WorkerController extends Controller 'email_verified_at' => Carbon::now(), 'is_worker' => $data['is_worker'], ]); + if ($Code_user->id > 0) { $Worker = new Worker(); $Worker->user_id = $Code_user->id; @@ -586,6 +633,13 @@ class WorkerController extends Controller $Worker->telephone = $data['telephone']; $Worker->save(); + if (isset($Worker->id)) { + $Title_Worker = new Title_worker(); + $Title_Worker->worker_id = $Worker->id; + $Title_Worker->job_title_id = $data['job_titles']; + $Title_Worker->save(); + } + return $Code_user; } } diff --git a/routes/web.php b/routes/web.php index cb1dda2..bbae8da 100644 --- a/routes/web.php +++ b/routes/web.php @@ -624,4 +624,5 @@ Route::group([ Route::post('сообщение/', [EmployerController::class, 'new_message'])->name('new_message'); }); +Route::get('TestWorker', [WorkerController::class, 'TestWorker'])->name('TestWorker');