Added forced relogin if connection time exceeds a certain period
This commit is contained in:
parent
51b233213b
commit
9cb2317ba9
|
@ -32,6 +32,14 @@ public class Global {
|
|||
* User logged flag
|
||||
*/
|
||||
private static boolean logged;
|
||||
/**
|
||||
* Time of application's last login
|
||||
*/
|
||||
private static long lastLoginTime;
|
||||
/**
|
||||
* Time to force relogin
|
||||
*/
|
||||
public static final int RELOGIN_TIME = 86400000; //24h
|
||||
/**
|
||||
* Request code for Login module.
|
||||
*/
|
||||
|
@ -123,6 +131,20 @@ public class Global {
|
|||
Global.logged = logged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets start time of application
|
||||
* @return Start time of application
|
||||
*/
|
||||
public static long getLastLoginTime() {
|
||||
return lastLoginTime;
|
||||
}
|
||||
/**
|
||||
* Sets start time of application
|
||||
* @param l Start time of application
|
||||
*/
|
||||
public static void setLastLoginTime(long l) {
|
||||
Global.lastLoginTime = l;
|
||||
}
|
||||
/**
|
||||
* Function to parse from Integer to Boolean
|
||||
* @param n Integer to be parsed
|
||||
|
|
|
@ -97,7 +97,8 @@ public class Login extends Module {
|
|||
protected void requestService()
|
||||
throws NoSuchAlgorithmException, IOException, XmlPullParserException, SoapFault, IllegalAccessException, InstantiationException {
|
||||
|
||||
if(!Global.isLogged())
|
||||
//If the application isn't logged or last login time > Global.RELOGIN_TIME, force login
|
||||
if(!Global.isLogged() || (System.currentTimeMillis()-Global.getLastLoginTime() > Global.RELOGIN_TIME))
|
||||
{
|
||||
//Encrypts user password with SHA-512 and encodes it to Base64UrlSafe
|
||||
md = MessageDigest.getInstance("SHA-512");
|
||||
|
@ -124,6 +125,9 @@ public class Login extends Module {
|
|||
User.setUserSurname2(ks.getProperty(5).toString());
|
||||
User.setUserFirstName(ks.getProperty(6).toString());
|
||||
User.setUserTypeName(ks.getProperty(7).toString());
|
||||
|
||||
//Update application last login time
|
||||
Global.setLastLoginTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +140,7 @@ public class Login extends Module {
|
|||
Log.d(TAG, "userSurname2=" + User.getUserSurname2());
|
||||
Log.d(TAG, "userFirstName=" + User.getUserFirstName());
|
||||
Log.d(TAG, "userTypeName=" + User.getUserTypeName());
|
||||
Log.d(TAG, "lastLoginTime=" + Global.getLastLoginTime());
|
||||
}
|
||||
|
||||
//Request finalized without errors
|
||||
|
|
Loading…
Reference in New Issue
Block a user