Commit cdd8caed034a0465975888d872cf505db208373f
1 parent
5e17adedfd
Exists in
master
fix reset password
Showing 6 changed files with 150 additions and 15 deletions Side-by-side Diff
app/Http/Controllers/MainController.php
... | ... | @@ -367,19 +367,40 @@ class MainController extends Controller |
367 | 367 | $validator = Validator::make($request->all(), $rules, $messages); |
368 | 368 | |
369 | 369 | if ($validator->fails()) { |
370 | - return redirect()->back()->with('Error', "Email невалидный"); | |
370 | + return response()->json([ | |
371 | + 'errors' => $validator->errors() | |
372 | + ], 422); | |
371 | 373 | } else { |
372 | - $new_password = Tools::generator_id(10); | |
373 | - $hash_password = Hash::make($new_password); | |
374 | - $user = User::query()->where('email', $request->get('email'))->first(); | |
375 | - $EditRec = User::find($user->id); | |
376 | - $EditRec->password = $hash_password; | |
377 | - $EditRec->save(); | |
378 | - | |
379 | - foreach ([$request->get('email')] as $recipient) { | |
380 | - Mail::to($recipient)->send(new MailRepair($new_password)); | |
374 | + try { | |
375 | + $user = User::query()->where('email', $request->get('email'))->first(); | |
376 | + if (!$user) { | |
377 | + return response()->json([ | |
378 | + 'errors' => [ | |
379 | + 'email' => [ | |
380 | + 'Пользователь не найден' | |
381 | + ] | |
382 | + ] | |
383 | + ], 422); | |
384 | + } | |
385 | + | |
386 | + $new_password = Tools::generator_id(10); | |
387 | + $hash_password = Hash::make($new_password); | |
388 | + | |
389 | + $user->update([ | |
390 | + 'password' => $hash_password, | |
391 | + 'pubpassword' => base64_encode($new_password) | |
392 | + ]); | |
393 | + | |
394 | + Mail::to($user)->send(new MailRepair($new_password)); | |
395 | + | |
396 | + return response()->json([ | |
397 | + 'success' => true | |
398 | + ], 200); | |
399 | + } catch (\Exception $exception) { | |
400 | + return response()->json([ | |
401 | + 'success' => true | |
402 | + ], 400); | |
381 | 403 | } |
382 | - return redirect()->route('index'); | |
383 | 404 | |
384 | 405 | } |
385 | 406 |
app/Mail/MailRepair.php
... | ... | @@ -24,8 +24,8 @@ class MailRepair extends Mailable |
24 | 24 | public function envelope(): Envelope |
25 | 25 | { |
26 | 26 | return new Envelope( |
27 | - from: new Address('jeffrey@example.com', 'Рассылка сообщений'), | |
28 | - subject: 'Send add messages', | |
27 | + from: new Address(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME')), | |
28 | + subject: 'Воостановление пароля', | |
29 | 29 | ); |
30 | 30 | } |
31 | 31 |
resources/views/emails/RepairPassword.blade.php
... | ... | @@ -0,0 +1,54 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html lang="ru"> | |
3 | + | |
4 | +<head> | |
5 | + <meta charset="utf-8"> | |
6 | + <title>BAIKALY</title> | |
7 | +</head> | |
8 | + | |
9 | +<body style="background: #eff2fb; padding: 50px 0;"> | |
10 | +<div class="email__first" style="background: #fff url({{asset('images/emails/23.png')}}) no-repeat 100% 100%; border: 1px solid #377d87; border-radius: 10px; max-width: 600px; margin: 0 auto; margin-top: 32px; font-family: sans-serif; padding: 60px; text-align: center;"> | |
11 | + <a href="{{config('app.url')}}" target="_blank" style="display: block; margin: 0 auto;"> | |
12 | + <img src="{{asset('images/emails/20.png')}}" alt="" style="width: 182px; height: 54px; display: block; margin: 0 auto;"> | |
13 | + </a> | |
14 | + <b style="font-size: 24px; line-height: 32px; display: block; margin: 32px 0;"> | |
15 | + Ваш новый пароль. | |
16 | + </b> | |
17 | + <b style="font-size: 24px; line-height: 32px; display: block; margin: 32px 0;"> | |
18 | + {{$password}} | |
19 | + </b> | |
20 | + <div style="text-align:center;margin-top: 32px;font-size: 0;"> | |
21 | + <a href="https://t.me/rekamore_su" target="_blank" | |
22 | + style="background: #20A0E1;font-size: 16px;font-weight: 700;margin:0 16px 32px 16px;border-radius: 8px;height: 44px;line-height: 44px;text-decoration: none;color:#fff;display: inline-block;vertical-align: top;padding: 0 32px;"> | |
23 | + <img src="{{asset('images/emails/24.png')}}" alt="" style="width: 17px; height: 14px; margin-right:5px;"> | |
24 | + Телеграм | |
25 | + </a> | |
26 | + <a href="https://vk.com/rekamore_su" target="_blank" | |
27 | + style="background: #2787F5;font-size: 16px;font-weight: 700;margin:0 16px 32px 16px;border-radius: 8px;height: 44px;line-height: 44px;text-decoration: none;color:#fff;display: inline-block;vertical-align: top;padding: 0 32px;"> | |
28 | + <img src="{{asset('images/emails/25.png')}}" alt="" style="width: 17px; height: 14px; margin-right:5px;"> | |
29 | + ВКонтакте | |
30 | + </a> | |
31 | + </div> | |
32 | +</div> | |
33 | +<div class="email__text" | |
34 | + style="margin:32px 0;font-style: italic;font-size: 14px;line-height: 20px;font-family: sans-serif;color:#37393a;text-align: center;display: block;"> | |
35 | + Это письмо отправлено автоматически. Пожалуйста, не отвечайте на него. | |
36 | +</div> | |
37 | +<a href="{{config('app.url')}}" target="_blank" style="display: block; margin: 0 auto;"> | |
38 | + <img src="{{asset('images/emails/19.png')}}" alt="" style="width: 222px; height: 74px; display: block; margin: 0 auto;"> | |
39 | +</a> | |
40 | +<div class="email__socials" style="display: block;text-align: center;margin-top: 56px;font-size: 0;"> | |
41 | + <a href="https://vk.com/rekamore_su" style="display:inline-block;vertical-align: middle;margin:0 4px;"> | |
42 | + <img src="{{asset('images/emails/22.png')}}" alt="" style="width: 40px; height: 40px"> | |
43 | + </a> | |
44 | + <a href="https://t.me/rekamore_su" style="display:inline-block;vertical-align: middle;margin:0 4px;"> | |
45 | + <img src="{{asset('images/emails/21.png')}}" alt="" style="width: 40px; height: 40px"> | |
46 | + </a> | |
47 | +</div> | |
48 | +<div class="email__bottom" | |
49 | + style="font-family: sans-serif;color:#37393A;text-align: center;margin-top: 24px;font-size: 14px;line-height: 20px;margin-bottom: 32px;"> | |
50 | + © 2023 — RekaMore.su | |
51 | +</div> | |
52 | +</body> | |
53 | + | |
54 | +</html> |
resources/views/layout/frontend.blade.php
... | ... | @@ -346,5 +346,26 @@ |
346 | 346 | @include('js.modals') |
347 | 347 | @include('js.captha') |
348 | 348 | @yield('scripts') |
349 | + | |
350 | +@if(App::isProduction()) | |
351 | + <!-- Yandex.Metrika counter --> | |
352 | + <script type="text/javascript" > | |
353 | + (function(m,e,t,r,i,k,a){m[i]=m[i]function(){(m[i].a=m[i].a[]).push(arguments)}; | |
354 | + m[i].l=1*new Date(); | |
355 | + for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} | |
356 | + k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) | |
357 | + (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); | |
358 | + | |
359 | + ym(98897513, "init", { | |
360 | + clickmap:true, | |
361 | + trackLinks:true, | |
362 | + accurateTrackBounce:true, | |
363 | + webvisor:true | |
364 | + }); | |
365 | + </script> | |
366 | + <noscript><div><img src="https://mc.yandex.ru/watch/98897513" style="position:absolute; left:-9999px;" alt="" /></div></noscript> | |
367 | + <!-- /Yandex.Metrika counter --> | |
368 | + | |
369 | +@endif | |
349 | 370 | </body> |
350 | 371 | </html> |
resources/views/modals/reset_password.blade.php
... | ... | @@ -2,12 +2,13 @@ |
2 | 2 | <div class="modal__body"> |
3 | 3 | <div class="modal__title left">Сбросить пароль</div> |
4 | 4 | <div class="modal__text left">Пожалуйста, введите имя пользователя или адрес электронной почты</div> |
5 | - <form class="modal__sign" action="{{ route('repair_password') }}"> | |
5 | + <form id="reset-password-form" class="modal__sign" action="{{ route('repair_password') }}"> | |
6 | 6 | <div class="modal__sign-item"> |
7 | 7 | <input type="text" class="input" name="email" id="email" placeholder="Введите свой email для восстановления" required> |
8 | + <div id="email-error" class="error-message"></div> | |
8 | 9 | </div> |
9 | 10 | <div class="modal__sign-item"> |
10 | - <button type="submit" class="button">Получить новый пароль</button> | |
11 | + <button id="reset-password-btn" type="submit" class="button">Получить новый пароль</button> | |
11 | 12 | </div> |
12 | 13 | </form> |
13 | 14 | <div class="modal__text"> |
... | ... | @@ -17,3 +18,35 @@ |
17 | 18 | </div> |
18 | 19 | </div> |
19 | 20 | </div> |
21 | +@include('modals.successful_reset_password') | |
22 | +<script> | |
23 | + $(document).on('click', '#reset-password-btn', function (e) { | |
24 | + e.preventDefault(); | |
25 | + const form = $('#reset-password-form'); | |
26 | + $.ajax({ | |
27 | + url: form.attr('action'), | |
28 | + method: form.attr('method'), | |
29 | + data: form.serialize(), | |
30 | + success: function (response) { | |
31 | + $.fancybox.open({ | |
32 | + src: '#reset-password-sent', | |
33 | + type: 'inline', | |
34 | + opts: {touch: false} | |
35 | + }); | |
36 | + }, | |
37 | + error: function (jqXHR) { | |
38 | + if (jqXHR.status === 422) { | |
39 | + let errors = jqXHR.responseJSON.errors; | |
40 | + console.log('errors', errors); | |
41 | + for (let field in errors) { | |
42 | + if (errors.hasOwnProperty(field)) { | |
43 | + $(`#${field}-error`).text(errors[field][0]); | |
44 | + } | |
45 | + } | |
46 | + } else { | |
47 | + alert('Произошла ошибка. Попробуйте снова.'); | |
48 | + } | |
49 | + } | |
50 | + }); | |
51 | + }) | |
52 | +</script> |
resources/views/modals/successful_reset_password.blade.php