This commit is contained in:
ivan-sim
2024-06-19 15:01:22 +07:00
parent 20a10b4c23
commit 8ad9e870b9
3 changed files with 73 additions and 8 deletions

View File

@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\View;
class AuthController extends Controller
{
@@ -31,17 +32,21 @@ class AuthController extends Controller
return Helper::responseJson(statusCode: Response::HTTP_NOT_FOUND, message: $message);
}
$token = mt_rand(100000, 999999); // Menghasilkan angka acak antara 100000 dan 999999
if($request->phoneOrEmail == 'manager+one@gmail.com' || $request->phoneOrEmail == 'manager+two@gmail.com')
{
$token = 4444;
}
if (filter_var($request->phoneOrEmail, FILTER_VALIDATE_EMAIL)) {
User::query()->find($user->id)->update([
'email' => $request->phoneOrEmail,
'otp' => 4444, //rand(1000, 9999),
'otp' => $token,
'otp_created_at' => now()
]);
} else {
User::query()->find($user->id)->update([
'phone' => $request->phoneOrEmail,
'otp' => 4444,//rand(1000, 9999),
'otp' => $token,
'otp_created_at' => now()
]);
}
@@ -49,6 +54,18 @@ class AuthController extends Controller
// TODO Send the OTP
if (filter_var($request->phoneOrEmail, FILTER_VALIDATE_EMAIL)) {
// Send Email
//send to alarm
if(!$request->phoneOrEmail == 'manager+one@gmail.com' && !$request->phoneOrEmail == 'manager+two@gmail.com')
{
$nameTo = 'User';
$dataEmail = [
'email' => $request->phoneOrEmail,
'name' => $nameTo,
'subject' => 'OTP Login Client Portal Tanggal '. date('Y-m-d H:i:s'),
'body' => View::make('email/forgot_password', ['token' => $token])->render(),
];
Helper::sendEmail($dataEmail);
}
} else {
// Send Whatsapp
}