Merge branch '119-app-tokens' of gitnex/GitNex into master

This commit is contained in:
M M Arif 2019-11-16 05:18:41 +00:00
commit f9550ad115
3 changed files with 35 additions and 5 deletions

View File

@ -550,6 +550,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
List<UserTokens> userTokens = response.body(); List<UserTokens> userTokens = response.body();
final TinyDB tinyDb = new TinyDB(getApplicationContext()); final TinyDB tinyDb = new TinyDB(getApplicationContext());
final AppUtil appUtil = new AppUtil();
//Headers responseHeaders = response.headers(); //Headers responseHeaders = response.headers();
if (response.isSuccessful()) { if (response.isSuccessful()) {
@ -560,13 +561,30 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
assert userTokens != null; assert userTokens != null;
if (userTokens.size() > 0) { if (userTokens.size() > 0) {
for (int i = 0; i < userTokens.size(); i++) {
if (userTokens.get(i).getSha1().equals(tinyDb.getString(loginUid + "-token"))) { if(userTokens.get(0).getToken_last_eight() != null) {
setTokenFlag = true;
break; for (int i = 0; i < userTokens.size(); i++) {
if (userTokens.get(i).getToken_last_eight().equals(tinyDb.getString(loginUid + "-token-last-eight"))) {
setTokenFlag = true;
break;
}
//Log.i("Tokens: ", userTokens.get(i).getToken_last_eight());
} }
//Log.i("Tokens: ", userTokens.get(i).getSha1());
} }
else {
for (int i = 0; i < userTokens.size(); i++) {
if (userTokens.get(i).getSha1().equals(tinyDb.getString(loginUid + "-token"))) {
setTokenFlag = true;
break;
}
//Log.i("Tokens: ", userTokens.get(i).getSha1());
}
}
} }
if(tinyDb.getString(loginUid + "-token").isEmpty() || !setTokenFlag) { if(tinyDb.getString(loginUid + "-token").isEmpty() || !setTokenFlag) {
@ -605,6 +623,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
tinyDb.remove("loginPass"); tinyDb.remove("loginPass");
tinyDb.putBoolean("loggedInMode", true); tinyDb.putBoolean("loggedInMode", true);
tinyDb.putString(loginUid + "-token", newToken.getSha1()); tinyDb.putString(loginUid + "-token", newToken.getSha1());
tinyDb.putString(loginUid + "-token-last-eight", appUtil.getLastCharactersOfWord(newToken.getSha1(), 8));
//Log.i("Tokens", "new:" + newToken.getSha1() + " old:" + tinyDb.getString(loginUid + "-token")); //Log.i("Tokens", "new:" + newToken.getSha1() + " old:" + tinyDb.getString(loginUid + "-token"));
startActivity(new Intent(LoginActivity.this, MainActivity.class)); startActivity(new Intent(LoginActivity.this, MainActivity.class));

View File

@ -9,6 +9,7 @@ public class UserTokens {
private int id; private int id;
private String name; private String name;
private String sha1; private String sha1;
private String token_last_eight;
public UserTokens(String name) { public UserTokens(String name) {
this.name = name; this.name = name;
@ -29,4 +30,8 @@ public class UserTokens {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getToken_last_eight() {
return token_last_eight;
}
} }

View File

@ -230,4 +230,10 @@ public class AppUtil {
return Arrays.asList(extValues).contains(ext); return Arrays.asList(extValues).contains(ext);
} }
public String getLastCharactersOfWord( String str, int count ) {
return str.substring(str.length() - count);
}
} }