From d21b26a5d2b6a39e7805facc27de89f9a789ce0e Mon Sep 17 00:00:00 2001 From: Bayu Lukman Yusuf Date: Tue, 13 Jan 2026 14:56:47 +0700 Subject: [PATCH] language login --- .../Controllers/Auth/LoginWaController.php | 45 +++++++++-------- .../Member/Auth/MemberAuthRepository.php | 6 +-- lang/en/header.php | 2 + lang/en/otp.php | 1 + lang/en/signin.php | 6 ++- lang/en/signup.php | 1 - lang/id/header.php | 2 + lang/id/otp.php | 36 ++++++++++++++ lang/id/signin.php | 6 +-- lang/id/signup.php | 1 - resources/scss/_variables.scss | 2 +- resources/views/account/otp.blade.php | 22 +-------- resources/views/account/signin.blade.php | 48 +++++++++---------- resources/views/account/signup.blade.php | 4 +- .../views/components/layout/header.blade.php | 12 ++--- 15 files changed, 111 insertions(+), 83 deletions(-) create mode 100644 lang/id/otp.php diff --git a/app/Http/Controllers/Auth/LoginWaController.php b/app/Http/Controllers/Auth/LoginWaController.php index ab3464f..5dcbd68 100644 --- a/app/Http/Controllers/Auth/LoginWaController.php +++ b/app/Http/Controllers/Auth/LoginWaController.php @@ -5,10 +5,9 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Repositories\Member\Auth\MemberAuthRepository; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Session; -use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Validator; class LoginWaController extends Controller { @@ -36,13 +35,23 @@ class LoginWaController extends Controller return response()->json([ 'success' => false, 'message' => __('otp.invalid_phone'), - 'errors' => $validator->errors() + 'errors' => $validator->errors(), ], 422); } $identity = $request->identity; - + + // check first if user exists + $user = $this->memberAuthRepository->check(['phone' => $identity]); + if (! $user) { + return response()->json([ + 'success' => false, + 'message' => __('otp.user_not_found'), + ], 404); + } + try { + // Use MemberAuthRepository to generate OTP $otp = $this->memberAuthRepository->waOtp(['phone' => $identity]); @@ -53,14 +62,14 @@ class LoginWaController extends Controller return response()->json([ 'success' => true, 'message' => __('otp.sent'), - 'redirect' => route('login-phone.otp.view', ['identity' => $identity]) + 'redirect' => route('login-phone.otp.view', ['identity' => $identity]), ]); } catch (\Exception $e) { - Log::error("OTP generation failed: " . $e->getMessage()); - + Log::error('OTP generation failed: '.$e->getMessage()); + return response()->json([ 'success' => false, - 'message' => __('otp.generate_failed') + 'message' => __('otp.generate_failed'), ], 500); } } @@ -68,7 +77,7 @@ class LoginWaController extends Controller public function otpView($identity) { return view('account.otp', [ - 'identity' => $identity + 'identity' => $identity, ]); } @@ -92,25 +101,23 @@ class LoginWaController extends Controller // Use MemberAuthRepository to verify OTP $result = $this->memberAuthRepository->waOtpConfirm([ 'phone' => $identity, - 'otp' => $otp + 'otp' => $otp, ]); - // TODO: Authenticate user or create new user - // For now, we'll just redirect to dashboard - // In production, you would: - // 1. Find or create user by phone number - // 2. Log them in - // 3. Redirect to intended page + $check = $this->memberAuthRepository->check(['phone' => $identity]); + + + // Auth::guard('web')->attempt(['id' => $check->id]); return redirect()->route('home')->with('success', __('otp.login_success')); - + } catch (\Illuminate\Validation\ValidationException $e) { return back() ->withErrors(['otp' => $e->getMessage()]) ->withInput(); } catch (\Exception $e) { - Log::error("OTP verification failed: " . $e->getMessage()); - + Log::error('OTP verification failed: '.$e->getMessage()); + return back() ->withErrors(['otp' => __('otp.verification_failed')]) ->withInput(); diff --git a/app/Repositories/Member/Auth/MemberAuthRepository.php b/app/Repositories/Member/Auth/MemberAuthRepository.php index b1298c9..82c7af7 100644 --- a/app/Repositories/Member/Auth/MemberAuthRepository.php +++ b/app/Repositories/Member/Auth/MemberAuthRepository.php @@ -27,10 +27,10 @@ class MemberAuthRepository $this->voucherRepository = $voucherRepository; } - public function check($request) + public function check($data) { - $phone = $request->phone; - $email = $request->email; + $phone = $data['phone'] ?? null; + $email = $data['email'] ?? null; if ($email) { return $this->findUserByEmail($email); diff --git a/lang/en/header.php b/lang/en/header.php index 4f684ba..efbf836 100644 --- a/lang/en/header.php +++ b/lang/en/header.php @@ -1,4 +1,6 @@ 'Categories', + 'account' => 'Account', + 'wishlist' => 'Wishlist', ]; \ No newline at end of file diff --git a/lang/en/otp.php b/lang/en/otp.php index eaca3f1..bbb4038 100644 --- a/lang/en/otp.php +++ b/lang/en/otp.php @@ -23,6 +23,7 @@ return [ 'resend_in' => 'Resend in', 'need_help' => 'Need help?', 'invalid_phone' => 'Please enter a valid phone number', + 'user_not_found' => 'User not found with this phone number', 'sent' => 'OTP sent successfully', 'expired' => 'OTP has expired', 'max_attempts' => 'Maximum attempts reached. Please request a new OTP', diff --git a/lang/en/signin.php b/lang/en/signin.php index 774217b..f33b53d 100644 --- a/lang/en/signin.php +++ b/lang/en/signin.php @@ -31,6 +31,8 @@ return [ 'facebook' => 'Facebook', 'apple' => 'Apple', 'need_help' => 'Need help?', - 'rights_reserved' => '© All rights reserved. Made by :company', - 'company_name' => 'Coderthemes', + 'rights_reserved' => '© All rights reserved. Made by :company', + + 'sending' => 'Sending...', + 'error' => 'An error occurred. Please try again.', ]; diff --git a/lang/en/signup.php b/lang/en/signup.php index 29b4f2a..4071f50 100644 --- a/lang/en/signup.php +++ b/lang/en/signup.php @@ -46,7 +46,6 @@ return [ 'apple' => 'Apple', 'need_help' => 'Need help?', 'rights_reserved' => '© All rights reserved. Made by :company', - 'company_name' => 'Coderthemes', // Benefits section 'benefits_title' => 'Why create an account?', diff --git a/lang/id/header.php b/lang/id/header.php index a694c66..05e0152 100644 --- a/lang/id/header.php +++ b/lang/id/header.php @@ -1,4 +1,6 @@ 'Kategori', + 'account' => 'Akun', + 'wishlist' => 'Daftar Keinginan', ]; \ No newline at end of file diff --git a/lang/id/otp.php b/lang/id/otp.php new file mode 100644 index 0000000..8faee24 --- /dev/null +++ b/lang/id/otp.php @@ -0,0 +1,36 @@ + 'Verifikasi Telepon Anda', + 'description' => 'Kami mengirim kode 6 digit ke :phone', + 'enter_code' => 'Masukkan kode verifikasi', + 'invalid_code' => 'Masukkan kode 6 digit yang valid', + 'verify' => 'Verifikasi', + 'back_to_login' => 'Kembali ke login', + 'resend_code' => 'Kirim ulang kode', + 'resend_in' => 'Kirim ulang dalam', + 'need_help' => 'Butuh bantuan?', + 'invalid_phone' => 'Masukkan nomor telepon yang valid', + 'user_not_found' => 'Pengguna tidak ditemukan dengan nomor telepon ini', + 'sent' => 'OTP berhasil dikirim', + 'expired' => 'OTP telah kadaluarsa', + 'max_attempts' => 'Maksimal percobaan tercapai. Silakan minta OTP baru', + 'invalid' => 'Kode OTP tidak valid', + 'login_success' => 'Login berhasil', + 'resend_failed' => 'Gagal mengirim ulang OTP. Silakan coba lagi', + 'generate_failed' => 'Gagal membuat OTP. Silakan coba lagi', + 'verification_failed' => 'Verifikasi OTP gagal. Silakan coba lagi', + +]; diff --git a/lang/id/signin.php b/lang/id/signin.php index 63595f9..606b10f 100644 --- a/lang/id/signin.php +++ b/lang/id/signin.php @@ -31,7 +31,7 @@ return [ 'facebook' => 'Facebook', 'apple' => 'Apple', 'need_help' => 'Butuh bantuan?', - 'rights_reserved' => ' Semua hak dilindungi. Dibuat oleh :company', - 'rights_reserved' => '© Semua hak dilindungi. Dibuat oleh :company', - 'company_name' => 'Coderthemes', + 'rights_reserved' => '© Semua hak dilindungi. Dibuat oleh :company', + 'sending' => 'Mengirim...', + 'error' => 'Terjadi kesalahan. Silakan coba lagi.', ]; \ No newline at end of file diff --git a/lang/id/signup.php b/lang/id/signup.php index f4bc1f5..c39ce24 100644 --- a/lang/id/signup.php +++ b/lang/id/signup.php @@ -46,7 +46,6 @@ return [ 'apple' => 'Apple', 'need_help' => 'Butuh bantuan?', 'rights_reserved' => ' Semua hak dilindungi. Dibuat oleh :company', - 'company_name' => 'Coderthemes', // Benefits section 'benefits_title' => 'Mengapa membuat akun?', diff --git a/resources/scss/_variables.scss b/resources/scss/_variables.scss index 10b8239..324c632 100644 --- a/resources/scss/_variables.scss +++ b/resources/scss/_variables.scss @@ -35,7 +35,7 @@ $grays: () !default; $min-contrast-ratio: 2 !default; // Theme colors -$primary: #f55266 !default; +$primary: #000000 !default; $secondary: $gray-500 !default; $success: #33b36b !default; $info: #2f6ed5 !default; diff --git a/resources/views/account/otp.blade.php b/resources/views/account/otp.blade.php index 504e291..1c67465 100644 --- a/resources/views/account/otp.blade.php +++ b/resources/views/account/otp.blade.php @@ -9,23 +9,7 @@