diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index b1060a8..e77297d 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -10,6 +10,9 @@ use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; +use Illuminate\Support\Str; + +use App\Notifications\UserRegistered; class RegisterController extends Controller { @@ -55,7 +58,6 @@ protected function validator(array $data) 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'phone' => ['required', 'string', 'unique:users'], - 'password' => ['required', 'string', 'min:8', 'confirmed'], 'inn' => ['required', 'unique:companies'] ]); } @@ -68,12 +70,14 @@ protected function validator(array $data) */ protected function create(array $data) { + $newUserPassword = Str::password(8); $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'phone' => $data['phone'], - 'password' => Hash::make($data['password']), + 'password' => Hash::make($newUserPassword), ]); + $user->notify(new UserRegistered(login: $user->email, password: $newUserPassword)); $company = Company::create([ 'name' => $data['name'], diff --git a/app/Http/Controllers/Company/ConfirmCompanyController.php b/app/Http/Controllers/Company/ConfirmCompanyController.php index 03863a1..51a3b9b 100644 --- a/app/Http/Controllers/Company/ConfirmCompanyController.php +++ b/app/Http/Controllers/Company/ConfirmCompanyController.php @@ -4,11 +4,13 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; use Illuminate\Foundation\Auth\RegistersUsers; - use App\Models\Company\Company; use App\Models\Company\CompanyAdmin; use App\Models\User; +use App\Notifications\UserRegistered; +use Illuminate\Support\Str; class ConfirmCompanyController extends Controller { @@ -27,12 +29,14 @@ public function __invoke(Request $request) } else { + $newUserPassword = Str::password(8); $user = User::create([ 'name' => $request->user_name, 'email' => $company->email, 'phone' => $request->user_phone, - 'password' => uniqid(), + 'password' => Hash::make($newUserPassword), ]); + $user->notify(new UserRegistered($user->email, password: $newUserPassword)); } CompanyAdmin::create([ 'user_id' => $user->id, diff --git a/app/Http/Controllers/Company/DetailsController.php b/app/Http/Controllers/Company/DetailsController.php index 982bf10..dfabfe9 100644 --- a/app/Http/Controllers/Company/DetailsController.php +++ b/app/Http/Controllers/Company/DetailsController.php @@ -7,52 +7,67 @@ use App\Models\Company\Company; use App\Models\Company\Details; -use App\Models\Agent; +use App\Models\Agent\Agent; class DetailsController extends Controller -{ - public function index() { + { + public function index() + { $company = false; $userId = auth()->user()->id; $agent = Agent::where('user_id', $userId)->get(); - if ($agent->count() == 1) { + if ($agent->count() == 1) + { $agent = $agent->first(); $company = Company::find($agent->company_id); - } else { + } + else + { return back(); - }; - + } + ; + $details = new Details($company); $details = $details->details; - if ($company->type == 'SELFEMP') { + if ($company->type == 'SELFEMP') + { return view('company.details.selfemp', [ 'company' => $company, 'details' => $details ]); - }; - if ($company->type == 'AGENCY') { + } + ; + if ($company->type == 'AGENCY') + { return view('company.details.agency', [ 'company' => $company, 'details' => $details ]); - }; - } - public function store(Request $request, Company $company) { + } + ; + } + public function store(Request $request, Company $company) + { $userId = auth()->user()->id; $agent = Agent::where('user_id', $userId)->get(); - if ($agent->count() == 1) { + if ($agent->count() == 1) + { $agent = $agent->first(); - if ($agent->company_id != $company->id) { + if ($agent->company_id != $company->id) + { return; + } } - } else { + else + { return back(); - }; + } + ; $company->details = $request->all(); $company->save(); return to_route('company.details', [ 'company' => $company ]); + } } -} diff --git a/app/Models/User.php b/app/Models/User.php index d995ee1..38d4286 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,14 +2,13 @@ namespace App\Models; - use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; - -class User extends Authenticatable implements MustVerifyEmail -{ +class User extends Authenticatable + { use HasApiTokens, HasFactory, Notifiable; /** @@ -44,12 +43,13 @@ class User extends Authenticatable implements MustVerifyEmail 'password' => 'hashed', ]; - public function getPartialsName() { + public function getPartialsName() + { $name = explode(' ', $this->name); return [ 'firstName' => $name[0], 'secondName' => $name[1], 'familyName' => $name[2] ]; + } } -} diff --git a/app/Notifications/UserRegistered.php b/app/Notifications/UserRegistered.php new file mode 100644 index 0000000..fbdabf9 --- /dev/null +++ b/app/Notifications/UserRegistered.php @@ -0,0 +1,59 @@ +password = $password; + $this->login = $login; + } + + /** + * Get the notification's delivery channels. + * + * @return array + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + return (new MailMessage) + ->subject(__('Account was created')) + ->line(__('Your account was created')) + ->line(__('Your login', ['login' => $this->login])) + ->line(__('Your password', ['password' => $this->password])) + ->action(__('Go to login'), url(path: '/')); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } + } diff --git a/lang/ru.json b/lang/ru.json index f821498..a078f45 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -1,3 +1,23 @@ { - "Login": "Вход на сайт" + "Login": "Вход на сайт", + "Hello!": "Здравствуйте!", + "Email Address": "Электронная почта", + "Reset Password": "Сбросить пароль", + "Send Password Reset Link": "Восстановить пароль", + "Reset Password Notification": "Восстановление пароля", + "New Password": "Новый пароль", + "Confirm Password": "Введите пароль еще раз", + "You are receiving this email because we received a password reset request for your account.": "Вы получили это письмо после поступившего к нам запроса на сброс пароля для Вашей учетной записи.", + "This password reset link will expire in :count minutes.": "Эта ссылка для восстановления пароля будет действительна :count минут.", + "If you did not request a password reset, no further action is required.": "Если Вы не запрашивали сброс пароля, никаких дальнейших действий не требуется.", + "Regards": "С уважением", + "Your team": "Ваша команда", + "If you're having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser:": "Если кнопка \":actionText\" выше не нажимается, то скопируйте следующую ссылку в адресную строку браузера: ", + "These credentials do not match our records.": "Электронная почта или пароль указаны неверно", + "Account was created": "Ваш личный кабинет Alfa создан", + "Your account was created": "Учетная запись для Вас была создана", + "Please use your email as login and created password": "Пожалуйста, используйте для входа Вашу электронную почту в качестве логина и пароль, который был автоматически сгенерирован: :password", + "Go to login": "Перейти к авторизации", + "Your login": "Ваш логин: :login", + "Your password": "Ваш пароль: :password" } \ No newline at end of file diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 3c59f9f..565bbfa 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -59,32 +59,6 @@ class="form-control @error('email') is-invalid @enderror" name="email" -
- - -
- - - @error('password') - - {{ $message }} - - @enderror -
-
- -
- - -
- -
-
-