Commit 9d90bb86 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

[WIP] Save login info


Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent dc80b77f
......@@ -19,7 +19,9 @@
</intent-filter>
</activity>
<activity android:name=".LoginActivity">
<activity
android:name=".LoginActivity"
android:noHistory="true">
</activity>
<activity android:name=".HomeActivity">
......
......@@ -113,6 +113,11 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
}
}
@Override
public void onBackPressed() {
finish();
}
@Override
public void setWrongPassword(boolean enabled) {
TextView textView = (TextView) findViewById(R.id.tv_loginact_error);
......
......@@ -14,7 +14,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
presenter = new MainPresenter();
presenter = new MainPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}
......@@ -47,7 +47,20 @@ public class MainActivity extends AppCompatActivity implements MainView {
@Override
public void onLoaded() {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
Intent intent;
long expiry = presenter.isLoggedIn();
long current_time = System.currentTimeMillis() / 1000;
if (expiry == -1) {
intent = new Intent(this, LoginActivity.class);
startActivity(intent);
} else if (current_time > expiry) {
} else {
intent = new Intent(this, HomeActivity.class);
startActivity(intent);
}
finish();
}
}
\ No newline at end of file
......@@ -111,9 +111,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
public boolean validateData() {
DialogActivity dialog = new DialogActivity();
FragmentManager manager = getFragmentManager();
if (et_name.getText().toString().replaceAll("\\s+","").isEmpty() || et_cpf.getText().toString()|| birth_date =="" || citizen.rg=="" || phone1==""|| citizen.password=="" || confirm_password=="" ||)
return false;
}
......
......@@ -44,6 +44,7 @@ public class LoginPresenter extends BasePresenter<LoginView> {
osb.edit().putString("access-token", headers.get("access-token")).apply();
osb.edit().putString("client", headers.get("client")).apply();
osb.edit().putString("uid", headers.get("uid")).apply();
osb.edit().putString("expiry", headers.get("expiry")).apply();
view().setWrongPassword(false);
accountOutput.getCitizen().save(context);
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.views.MainView;
/**
......@@ -12,6 +14,11 @@ import br.ufpr.c3sl.agendador.agendador.views.MainView;
public class MainPresenter extends BasePresenter<MainView>{
private boolean isLoadingData = false;
private Context context;
public MainPresenter(Context context) {
this.context = context;
}
@Override
protected void updateView() {
......@@ -33,6 +40,18 @@ public class MainPresenter extends BasePresenter<MainView>{
new LoadDataTask().execute();
}
public long isLoggedIn() {
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(context,
"Agendador", context.MODE_PRIVATE);
String expiry = osb.getString("expiry", null);
if (expiry == null) {
return -1;
}
return Long.parseLong(expiry, 10);
}
private class LoadDataTask extends AsyncTask<Void, Void, Void> {
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment