Added New User Registration button to authentication activity

This commit is contained in:
Graham Jones
2022-01-27 15:05:11 +00:00
parent 203ffdc07f
commit 7f9a61c2a5
4 changed files with 46 additions and 8 deletions

View File

@@ -1,7 +1,9 @@
package uk.org.openseizuredetector;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
@@ -46,6 +48,8 @@ public class AuthenticateActivity extends AppCompatActivity {
logoutCancelBtn.setOnClickListener(onCancel);
Button logoutBtn = (Button)findViewById(R.id.logoutBtn);
logoutBtn.setOnClickListener(onLogout);
Button registerBtn = (Button) findViewById(R.id.RegisterBtn);
registerBtn.setOnClickListener(onRegister);
mUnameEt = (EditText) findViewById(R.id.username);
mPasswdEt = (EditText) findViewById(R.id.password);
@@ -158,6 +162,22 @@ public class AuthenticateActivity extends AppCompatActivity {
}
};
View.OnClickListener onRegister =
new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "onRegisterBtn");
//Intent i;
//i = new Intent(getApplicationContext(), RemoteDbActivity.class);
//i.putExtra("url", "https://osdapi.ddns.net/static/register.html");
//startActivity(i);
String url = "https://osdapi.ddns.net/static/register.html";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
};
private void saveAuthToken(String tokenStr) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
prefs.edit().putString(TOKEN_ID, tokenStr).commit();

View File

@@ -29,6 +29,7 @@ public class RemoteDbActivity extends AppCompatActivity {
private OsdUtil mUtil;
final Handler serverStatusHandler = new Handler();
private String TOKEN_ID = "webApiAuthToken";
private String mRemtoteUrl = "https://osdapi.ddns.net/";
@Override
@@ -40,6 +41,14 @@ public class RemoteDbActivity extends AppCompatActivity {
mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler);
mConnection = new SdServiceConnection(getApplicationContext());
mUtil.bindToServer(getApplicationContext(), mConnection);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String remoteUrl = extras.getString("url");
mRemtoteUrl = remoteUrl;
Log.d(TAG, "onCreate - mRemoteUrl=" + mRemtoteUrl);
}
waitForConnection();
//mLm= new LogManager(mContext);
@@ -62,7 +71,7 @@ public class RemoteDbActivity extends AppCompatActivity {
// the mConnection to bind to the service, so we delay half a second to give it chance
// to connect before trying to update the UI for the first time (it happens again periodically using the uiTimer)
if (mConnection.mBound) {
Log.v(TAG, "waitForConnection - Bound!");
Log.d(TAG, "waitForConnection - Bound!");
initialiseServiceConnection();
} else {
Log.v(TAG, "waitForConnection - waiting...");
@@ -77,6 +86,7 @@ public class RemoteDbActivity extends AppCompatActivity {
private void initialiseServiceConnection() {
mLm = mConnection.mSdServer.mLm;
mWebView.loadUrl(mRemtoteUrl, getAuthHeaders());
//mWac = mConnection.mSdServer.mLm.mWac;
}
@@ -99,7 +109,6 @@ public class RemoteDbActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
startUiTimer();
mWebView.loadUrl("https://osdapi.ddns.net/api/events/", getAuthHeaders());
}
private HashMap<String, String> getAuthHeaders() {
@@ -132,12 +141,14 @@ public class RemoteDbActivity extends AppCompatActivity {
// Remote Database Information
tv = (TextView)findViewById(R.id.authStatusTv);
btn = (Button)findViewById(R.id.auth_button);
if (mLm.mWac.isLoggedIn()) {
tv.setText("Authenticated");
btn.setText("Log Out");
} else {
tv.setText("NOT AUTHENTICATED");
btn.setText("Log In");
if (mLm != null) {
if (mLm.mWac.isLoggedIn()) {
tv.setText("Authenticated");
btn.setText("Log Out");
} else {
tv.setText("NOT AUTHENTICATED");
btn.setText("Log In");
}
}
}