Revert to LDAP login

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-20 23:23:44 +01:00
parent 157855d911
commit 8a29b93533
4 changed files with 15 additions and 25 deletions

View File

@ -135,6 +135,7 @@ public abstract class BaseActivity
userListFragment = new UsersListFragment(); userListFragment = new UsersListFragment();
isTutor = PrefUtils.getIsTutor(getApplicationContext()); isTutor = PrefUtils.getIsTutor(getApplicationContext());
if (!isTutor) { if (!isTutor) {
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE); navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
} }

View File

@ -33,6 +33,7 @@ import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RestApiHelper;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -72,12 +73,6 @@ public class LoginActivity extends AppCompatActivity {
return false; return false;
}); });
Switch tutorLogin = findViewById(R.id.tutor_login_switch);
tutorLogin.setOnCheckedChangeListener((buttonView, isChecked) -> {
PrefUtils.storeIsTutor(getApplicationContext(), isChecked);
});
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button); Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(view -> attemptLogin()); mEmailSignInButton.setOnClickListener(view -> attemptLogin());
@ -158,17 +153,9 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
Log.e("LOGIN", String.valueOf(PrefUtils.getIsTutor(getApplicationContext()))); ValidateUser user = new ValidateUser(email, password);
//Fake validate disposable.add(ldapService.validate(user)
LdapUser user = new LdapUser(email, password, "admin", (PrefUtils.getIsTutor(getApplicationContext())) ? "Tutor" : "Student", "Imię", "Nazwisko", email);
// ValidateUser user = new ValidateUser(email, password);
// LDAP logging
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(user)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));
@ -192,13 +179,20 @@ public class LoginActivity extends AppCompatActivity {
String token = jwtToken.getToken(); String token = jwtToken.getToken();
JWT jwt = new JWT(token); JWT jwt = new JWT(token);
Claim role = jwt.getClaim("nameid"); Claim userId = jwt.getClaim("nameid");
Claim role = jwt.getClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
if(Objects.requireNonNull(role.asString()).equals("Student")){
PrefUtils.storeIsTutor(getApplicationContext(), false);
}
Log.e("LOGOWANIE",role.asString());
PrefUtils.storeIsLoggedIn(getApplicationContext(), true); PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
PrefUtils.storeApiKey(getApplicationContext(), token); PrefUtils.storeApiKey(getApplicationContext(), token);
PrefUtils.storeUserId(getApplicationContext(), role.asString()); PrefUtils.storeUserId(getApplicationContext(), userId.asString());
getUserProfile(role.asString()); getUserProfile(userId.asString());
Intent data = new Intent(); Intent data = new Intent();
String txt = "Main Activity"; String txt = "Main Activity";

View File

@ -134,7 +134,7 @@ public class PrefUtils {
} }
public static String getLocale(Context context) { public static String getLocale(Context context) {
return getSharedPreferences(context).getString("LOCALE", "pl"); return getSharedPreferences(context).getString("LOCALE", "en");
} }
public static Boolean isBackgroundLocationServiceRunning(Context context) { public static Boolean isBackgroundLocationServiceRunning(Context context) {

View File

@ -72,11 +72,6 @@
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
<Switch
android:id="@+id/tutor_login_switch"
android:layout_width="192dp"
android:layout_height="wrap_content"
android:text="Login as Tutor" />
<Button <Button
android:id="@+id/email_sign_in_button" android:id="@+id/email_sign_in_button"