update data info di main menu card
This commit is contained in:
parent
78f9e95c3f
commit
40d0fc2402
@ -28,7 +28,6 @@ import java.util.concurrent.Executors;
|
|||||||
public class LoginActivity extends AppCompatActivity {
|
public class LoginActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final String TAG = "LoginActivity";
|
private static final String TAG = "LoginActivity";
|
||||||
private static final String API_URL = "https://be-edc.msvc.app/users/auth";
|
|
||||||
private static final String PREFS_NAME = "LoginPrefs";
|
private static final String PREFS_NAME = "LoginPrefs";
|
||||||
private static final String KEY_TOKEN = "token";
|
private static final String KEY_TOKEN = "token";
|
||||||
private static final String KEY_USER_DATA = "user_data";
|
private static final String KEY_USER_DATA = "user_data";
|
||||||
@ -130,8 +129,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
jsonPayload.put("identifier", identifier);
|
jsonPayload.put("identifier", identifier);
|
||||||
jsonPayload.put("password", password);
|
jsonPayload.put("password", password);
|
||||||
|
|
||||||
// Setup HTTP connection
|
// Setup HTTP connection using BuildConfig
|
||||||
URL url = new URL(API_URL);
|
URL url = new URL(BuildConfig.BACKEND_BASE_URL + "/users/auth");
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
@ -196,8 +195,10 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
String token = result.getString("token");
|
String token = result.getString("token");
|
||||||
JSONObject userData = result.getJSONObject("user");
|
JSONObject userData = result.getJSONObject("user");
|
||||||
|
|
||||||
|
// Log user data to console
|
||||||
|
logUserData(userData);
|
||||||
|
|
||||||
// Save login data
|
// Save login data
|
||||||
// saveLoginData(token, userData.toString());
|
|
||||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(KEY_TOKEN, token);
|
editor.putString(KEY_TOKEN, token);
|
||||||
@ -225,6 +226,28 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to log user data to console
|
||||||
|
private void logUserData(JSONObject userData) {
|
||||||
|
try {
|
||||||
|
StringBuilder userInfo = new StringBuilder();
|
||||||
|
userInfo.append("\n=== USER LOGIN DETAILS ===");
|
||||||
|
userInfo.append("\nID: ").append(userData.optString("id", "N/A"));
|
||||||
|
userInfo.append("\nName: ").append(userData.optString("name", "N/A"));
|
||||||
|
userInfo.append("\nEmail: ").append(userData.optString("email", "N/A"));
|
||||||
|
userInfo.append("\nRole: ").append(userData.optString("role", "N/A"));
|
||||||
|
userInfo.append("\nPhone: ").append(userData.optString("phone", "N/A"));
|
||||||
|
userInfo.append("\nPosition: ").append(userData.optString("position", "N/A"));
|
||||||
|
userInfo.append("\nMID: ").append(userData.optString("mid", "N/A"));
|
||||||
|
userInfo.append("\nTID: ").append(userData.optString("tid", "N/A"));
|
||||||
|
userInfo.append("\nLast Login: ").append(userData.optString("last_login", "N/A"));
|
||||||
|
userInfo.append("\n==========================");
|
||||||
|
|
||||||
|
Log.i(TAG, userInfo.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error logging user data: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setLoadingState(boolean isLoading) {
|
private void setLoadingState(boolean isLoading) {
|
||||||
btnLogin.setEnabled(!isLoading);
|
btnLogin.setEnabled(!isLoading);
|
||||||
etIdentifier.setEnabled(!isLoading);
|
etIdentifier.setEnabled(!isLoading);
|
||||||
@ -238,17 +261,6 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveLoginData(String token, String userData) {
|
|
||||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putString(KEY_TOKEN, token);
|
|
||||||
editor.putString(KEY_USER_DATA, userData);
|
|
||||||
editor.putBoolean(KEY_IS_LOGGED_IN, true);
|
|
||||||
editor.apply();
|
|
||||||
|
|
||||||
Log.d(TAG, "Login data saved successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUserLoggedIn() {
|
private boolean isUserLoggedIn() {
|
||||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||||
return prefs.getBoolean(KEY_IS_LOGGED_IN, false);
|
return prefs.getBoolean(KEY_IS_LOGGED_IN, false);
|
||||||
|
@ -129,13 +129,21 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
// Get user data
|
// Get user data
|
||||||
userData = LoginActivity.getUserDataAsJson(this);
|
userData = LoginActivity.getUserDataAsJson(this);
|
||||||
|
|
||||||
Log.d(TAG, "Loaded auth token: " + (authToken != null ? "✓" : "✗"));
|
|
||||||
Log.d(TAG, "Loaded user data: " + (userData != null ? "✓" : "✗"));
|
|
||||||
|
|
||||||
if (userData != null) {
|
if (userData != null) {
|
||||||
Log.d(TAG, "User: " + userData.optString("name", "Unknown"));
|
StringBuilder userInfo = new StringBuilder();
|
||||||
Log.d(TAG, "Email: " + userData.optString("email", "Unknown"));
|
userInfo.append("\n=== CURRENT USER DETAILS ===");
|
||||||
Log.d(TAG, "Role: " + userData.optString("role", "Unknown"));
|
userInfo.append("\nID: ").append(userData.optString("id", "N/A"));
|
||||||
|
userInfo.append("\nName: ").append(userData.optString("name", "N/A"));
|
||||||
|
userInfo.append("\nEmail: ").append(userData.optString("email", "N/A"));
|
||||||
|
userInfo.append("\nRole: ").append(userData.optString("role", "N/A"));
|
||||||
|
userInfo.append("\nPhone: ").append(userData.optString("phone", "N/A"));
|
||||||
|
userInfo.append("\nPosition: ").append(userData.optString("position", "N/A"));
|
||||||
|
userInfo.append("\nMID: ").append(userData.optString("mid", "N/A"));
|
||||||
|
userInfo.append("\nTID: ").append(userData.optString("tid", "N/A"));
|
||||||
|
userInfo.append("\nLast Login: ").append(userData.optString("last_login", "N/A"));
|
||||||
|
userInfo.append("\n==========================");
|
||||||
|
|
||||||
|
Log.i(TAG, userInfo.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +151,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (userData != null) {
|
if (userData != null) {
|
||||||
String userName = userData.optString("name", "User");
|
String userName = userData.optString("name", "User");
|
||||||
String userRole = userData.optString("role", "");
|
String userRole = userData.optString("role", "");
|
||||||
|
String mid = userData.optString("mid", "");
|
||||||
|
String tid = userData.optString("tid", "");
|
||||||
|
|
||||||
// Display welcome message
|
// Display welcome message
|
||||||
String welcomeMessage = "Selamat datang, " + userName;
|
String welcomeMessage = "Selamat datang, " + userName;
|
||||||
@ -164,6 +174,28 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
tvUserRole.setVisibility(View.GONE);
|
tvUserRole.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update MID and TID
|
||||||
|
TextView tvStoreName = findViewById(R.id.tv_store_name);
|
||||||
|
TextView tvStoreAddress = findViewById(R.id.tv_store_address);
|
||||||
|
TextView tvMid = findViewById(R.id.tv_mid);
|
||||||
|
TextView tvTid = findViewById(R.id.tv_tid);
|
||||||
|
|
||||||
|
if (tvStoreName != null) {
|
||||||
|
String storeName = userData.optString("store_name", "TOKO KLONTONG PAK EKO");
|
||||||
|
tvStoreName.setText(storeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tvStoreAddress != null) {
|
||||||
|
String storeAddress = userData.optString("store_address", "Ciputat Baru, Tangsel");
|
||||||
|
tvStoreAddress.setText(storeAddress);
|
||||||
|
}
|
||||||
|
if (tvMid != null && !mid.isEmpty()) {
|
||||||
|
tvMid.setText("MID: " + mid);
|
||||||
|
}
|
||||||
|
if (tvTid != null && !tid.isEmpty()) {
|
||||||
|
tvTid.setText("TID: " + tid);
|
||||||
|
}
|
||||||
|
|
||||||
// Show user info section in merchant card
|
// Show user info section in merchant card
|
||||||
if (userInfoSection != null) {
|
if (userInfoSection != null) {
|
||||||
userInfoSection.setVisibility(View.VISIBLE);
|
userInfoSection.setVisibility(View.VISIBLE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user