11package org .openimis .imispolicies .repository ;
22
3+ import static android .content .Context .MODE_PRIVATE ;
4+ import static org .openimis .imispolicies .Global .PREF_NAME ;
5+
36import android .content .Context ;
47import android .content .SharedPreferences ;
58import android .util .Base64 ;
1316import org .openimis .imispolicies .BuildConfig ;
1417import org .openimis .imispolicies .Global ;
1518import org .openimis .imispolicies .Token ;
19+ import org .openimis .imispolicies .network .util .PersistentCookieJar ;
1620import org .openimis .imispolicies .tools .Log ;
1721
1822import java .util .Date ;
@@ -37,7 +41,7 @@ public LoginRepository(@NonNull Context context) {
3741
3842 public LoginRepository (@ NonNull Context context , boolean isPaymentEnabled ) {
3943 this .isPaymentEnabled = isPaymentEnabled ;
40- prefs = context .getSharedPreferences (PREFS_NAME , Context . MODE_PRIVATE );
44+ prefs = context .getSharedPreferences (PREFS_NAME , MODE_PRIVATE );
4145 if (!prefs .getBoolean (HAS_MIGRATED , false )) {
4246 migrateOldTokens ();
4347 }
@@ -167,7 +171,21 @@ public boolean isLoggedIn() {
167171 if (isPaymentEnabled && getRestToken () == null ) {
168172 return false ;
169173 }
170- return getFhirToken () != null ;
174+
175+ PersistentCookieJar cookieJar = Global .getGlobal ().getCookieJar ();
176+ long expiry = Global .getGlobal ().getSharedPreferences (PREF_NAME , MODE_PRIVATE )
177+ .getLong ("session_expiry" , 0 );
178+
179+ boolean isLoggedIn = getFhirToken () != null
180+ && expiry > System .currentTimeMillis ();
181+
182+ if (!isLoggedIn ) {
183+ if (cookieJar != null ) {
184+ cookieJar .clear ();
185+ }
186+ }
187+
188+ return isLoggedIn ;
171189 }
172190
173191 public void logout () {
0 commit comments