Skip to content

Commit

Permalink
Merge pull request #18 from Infosys/offline-login
Browse files Browse the repository at this point in the history
Fixed offline login
  • Loading branch information
Piyush7034 authored Jun 27, 2023
2 parents a9360d9 + f40d0ce commit d80d647
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 313 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onResponse(Call call, Response response) {
ServiceError error = SyncRestUtil.getServiceError(wrapper);
if (error == null) {
try {
loginService.saveAuthToken(wrapper.getResponse());
loginService.saveAuthToken(wrapper.getResponse(), username);
loginService.setPasswordHash(username, password);
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse(wrapper.getResponse())
Expand Down Expand Up @@ -160,6 +160,34 @@ private void offlineLogin(final String username, final String password, AuthResp


if(loginService.getAuthToken() == null) {

}

try {
String token = loginService.saveAuthTokenOffline(username);

if(token != null && !token.isEmpty()) {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse(loginService.getAuthToken())
.setUsername(sharedPreferences.getString(USER_NAME, null))
.setIsDefault(sharedPreferences.getBoolean(IS_DEFAULT, false))
.setIsOfficer(sharedPreferences.getBoolean(IS_OPERATOR, false))
.setIsSupervisor(sharedPreferences.getBoolean(IS_SUPERVISOR, false))
.build();
result.success(authResponse);
} else {
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
.setIsDefault(false)
.setIsOfficer(false)
.setIsSupervisor(false)
.setErrorCode("REG_CRED_EXPIRED")
.build();
result.success(authResponse);
}
} catch (Exception ex) {
Log.e(getClass().getSimpleName(), "Some error occurred!");
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse("")
.setUsername("")
Expand All @@ -168,17 +196,9 @@ private void offlineLogin(final String username, final String password, AuthResp
.setIsSupervisor(false)
.setErrorCode("REG_CRED_EXPIRED")
.build();
result.success(authResponse);
return;
result.error(ex);
}
AuthResponsePigeon.AuthResponse authResponse = new AuthResponsePigeon.AuthResponse.Builder()
.setResponse(loginService.getAuthToken())
.setUsername(sharedPreferences.getString(USER_NAME, null))
.setIsDefault(sharedPreferences.getBoolean(IS_DEFAULT, false))
.setIsOfficer(sharedPreferences.getBoolean(IS_OPERATOR, false))
.setIsSupervisor(sharedPreferences.getBoolean(IS_SUPERVISOR, false))
.build();
result.success(authResponse);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.mosip.registration.clientmanager.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;
Expand All @@ -24,7 +24,7 @@ public interface UserTokenDao {
@Query("delete from user_token")
public void removeAllUsers();

@Insert
@Insert(onConflict = OnConflictStrategy.REPLACE)
public void insert(UserToken users);

@Query("delete from user_token")
Expand Down
Loading

0 comments on commit d80d647

Please sign in to comment.