Før feilsøking 3
This commit is contained in:
parent
09a339b3ee
commit
332574113e
6 changed files with 269 additions and 958 deletions
|
|
@ -18,14 +18,14 @@ if (localPropertiesFile.exists()) {
|
|||
|
||||
android {
|
||||
namespace = "com.kbs.kbsintranett"
|
||||
compileSdk = 34
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.kbs.kbsintranett"
|
||||
minSdk = 28
|
||||
targetSdk = 34
|
||||
versionCode = 4
|
||||
versionName = "1.5.1"
|
||||
targetSdk = 35
|
||||
versionCode = 6
|
||||
versionName = "1.6.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -7,7 +7,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -30,8 +29,8 @@ public class LoginFragment extends Fragment {
|
|||
private GoogleSignInClient mGoogleSignInClient;
|
||||
private TextView statusText;
|
||||
private SignInButton signInButton;
|
||||
private View reviewerLoginArea; // Nytt
|
||||
|
||||
// Håndterer resultatet fra Google-vinduet
|
||||
private final ActivityResultLauncher<Intent> signInLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
|
|
@ -48,7 +47,9 @@ public class LoginFragment extends Fragment {
|
|||
signInButton = view.findViewById(R.id.sign_in_button);
|
||||
signInButton.setSize(SignInButton.SIZE_WIDE);
|
||||
|
||||
// Hent ID fra MainActivity
|
||||
// Finn reviewer-knappen (vi legger den til i XML-en under)
|
||||
reviewerLoginArea = view.findViewById(R.id.reviewer_login_text);
|
||||
|
||||
String clientId = MainActivity.GOOGLE_WEB_CLIENT_ID;
|
||||
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.requestIdToken(clientId)
|
||||
|
|
@ -61,15 +62,52 @@ public class LoginFragment extends Fragment {
|
|||
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
|
||||
signInLauncher.launch(signInIntent);
|
||||
});
|
||||
|
||||
// Reviewer Bypass-logikk
|
||||
if (reviewerLoginArea != null) {
|
||||
reviewerLoginArea.setOnClickListener(v -> {
|
||||
performReviewerLogin();
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void performReviewerLogin() {
|
||||
statusText.setText("Kobler til som gjest...");
|
||||
signInButton.setEnabled(false);
|
||||
|
||||
// Vi sender den hemmelige nøkkelen i stedet for et ekte Google-token
|
||||
AuthRepository.loginToWordPress(
|
||||
"KBS_REVIEW_BYPASS_2026_SECRET",
|
||||
"Google Reviewer",
|
||||
"google-test@kbs.no",
|
||||
null,
|
||||
new AuthRepository.AuthCallback() {
|
||||
@Override
|
||||
public void onSuccess(String role) {
|
||||
if (isAdded()) {
|
||||
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
|
||||
navController.navigate(R.id.action_login_to_home);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (isAdded()) {
|
||||
statusText.setText("Feil ved tilkobling: " + message);
|
||||
signInButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void handleGoogleResult(Task<GoogleSignInAccount> completedTask) {
|
||||
try {
|
||||
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
|
||||
// 1. Google er OK. Nå logger vi inn på WordPress.
|
||||
statusText.setText("Google OK. Kobler til KBS Intranett...");
|
||||
signInButton.setEnabled(false); // Hindre dobbeltklikk
|
||||
signInButton.setEnabled(false);
|
||||
|
||||
String photoUrl = (account.getPhotoUrl() != null) ? account.getPhotoUrl().toString() : null;
|
||||
|
||||
|
|
@ -81,9 +119,7 @@ public class LoginFragment extends Fragment {
|
|||
new AuthRepository.AuthCallback() {
|
||||
@Override
|
||||
public void onSuccess(String role) {
|
||||
// 2. Alt er OK! Naviger til Hjem.
|
||||
if (isAdded()) {
|
||||
statusText.setText("Innlogging OK!");
|
||||
NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
|
||||
navController.navigate(R.id.action_login_to_home);
|
||||
}
|
||||
|
|
@ -99,16 +135,9 @@ public class LoginFragment extends Fragment {
|
|||
}
|
||||
);
|
||||
} catch (ApiException e) {
|
||||
// --- KORRIGERT FEILMELDING ---
|
||||
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
|
||||
String message;
|
||||
if (e.getStatusCode() == 12500) {
|
||||
message = "Konto ikke funnet, eller konto uten rettigheter.";
|
||||
} else {
|
||||
message = "Google-feil: " + e.getStatusCode();
|
||||
}
|
||||
String message = (e.getStatusCode() == 12500) ? "Konto ikke funnet." : "Google-feil: " + e.getStatusCode();
|
||||
statusText.setText(message);
|
||||
// --- SLUTT PÅ KORRIGERING ---
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
|
||||
public class UserFilterHelper {
|
||||
|
||||
private static final List<Integer> EXCLUDED_IDS = Arrays.asList(50, 51); // felles@kbs.no og kbs@kbs.no
|
||||
private static final List<Integer> EXCLUDED_IDS = Arrays.asList(50, 51, 56); // felles@kbs.no og kbs@kbs.no
|
||||
private static final String REQUIRED_DOMAIN = "@kbs.no";
|
||||
|
||||
public static List<User> getFilteredUsers(List<User> allUsers) {
|
||||
|
|
|
|||
|
|
@ -8,24 +8,7 @@
|
|||
android:background="#F5F5F5"
|
||||
tools:context=".FormsFragment">
|
||||
|
||||
<!-- NYTT: Toolbar med tilbake-knapp -->
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Light">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/forms_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/white"
|
||||
app:navigationIcon="@android:drawable/ic_menu_revert"
|
||||
app:titleTextColor="@color/black"
|
||||
app:title="Laster..." />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<!-- Resten er likt, men nå under toolbaren -->
|
||||
<!-- Den lokale toolbaren er fjernet herfra for å unngå dobbel heading -->
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/history_wrapper"
|
||||
|
|
|
|||
|
|
@ -38,4 +38,14 @@
|
|||
android:text=""
|
||||
android:textColor="#D32F2F"/>
|
||||
|
||||
<!-- Legg dette nederst i LinearLayout i fragment_login.xml -->
|
||||
<TextView
|
||||
android:id="@+id/reviewer_login_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:text="Reviewer Access"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in a new issue