forget password

This commit is contained in:
pajri
2022-12-29 11:38:55 +07:00
parent 0781e1ea00
commit 40ad4a22c7
27 changed files with 721 additions and 15 deletions

View File

@@ -30,7 +30,7 @@ class SendVerifyEmail extends Mailable
public function build()
{
$this->subject('Verify Email')
->markdown('email_user');
->markdown('verify_email');
return $this;
}

View File

@@ -4,6 +4,8 @@ namespace Modules\Internal\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\User;
use Crypt;
use Error;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
@@ -87,23 +89,25 @@ class AuthController extends Controller
return response(['message' => 'User Tidak Ditemukan'], 404);
}
Event(new ForgetPassword($user));
Mail::to($user->email)->send(new SendVerifyEmail($user));
// Mail::to($user->email)->send(new SendVerifyEmail($user));
return response()->json($user);
}
public function forgetPassword(Request $request)
{
return $request->all();
$request->validate([
'email' => 'required|email',
'new_password' => 'required',
'confirm_new_password' => 'required'
]);
$token = Crypt::decryptString($request->token);
$email = explode('|', $token)[0];
$user = User::query()
->where('email', $request->email)
->where('email', $email)
->first();
if (!$user) {
@@ -113,7 +117,7 @@ class AuthController extends Controller
if ($request["new_password"] != $request["confirm_new_password"]) {
return response([
'message' => "Password Tidak Sama"
]);
], 404);
}
$user->update([

View File

@@ -2,10 +2,12 @@
namespace Modules\Internal\Listeners;
use App\Models\User;
use Modules\Internal\Events\ForgetPassword;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
use Modules\Internal\Notifications\NotifyVerifyEmail;
class SendVerifyEmail
{
@@ -27,7 +29,9 @@ class SendVerifyEmail
*/
public function handle(ForgetPassword $event)
{
dd($event->data);
Mail::raw('Hello World!', function($msg) {$msg->to('myemail@gmail.com')->subject('Test Email'); });
User::where('email', $event->data['email'])
->each(function ($user) use ($event) {
$user->notify(new NotifyVerifyEmail($event->data));
});
}
}

View File

@@ -2,6 +2,7 @@
namespace Modules\Internal\Notifications;
use Crypt;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -10,15 +11,15 @@ use Illuminate\Notifications\Messages\MailMessage;
class NotifyVerifyEmail extends Notification
{
use Queueable;
protected $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
public function __construct($data)
{
//
$this->data = $data;
}
/**
@@ -40,10 +41,18 @@ class NotifyVerifyEmail extends Notification
*/
public function toMail($notifiable)
{
$token = Crypt::encryptString($this->data['email'] . '|' . now());
$url = env('INTERNAL_URL', 'https://aso.linksehat.com') . '/auth/forget-password?token=' . $token;
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
->subject('Verify Email')
->markdown('verify_email', ['url' => $url]);
// return (new MailMessage)
// ->line('The introduction to the notification.')
// ->action('Notification Action', 'https://laravel.com')
// ->line('Thank you for using our application!');
}
/**