aboutsummaryrefslogtreecommitdiff
path: root/src/org/slcl/LoginActivity.java
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-01-07 23:49:03 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2024-05-17 23:28:51 +0200
commit40f6d425a4429b16936cc8bb4900a23c3362a123 (patch)
treecc60a4a6995604f095952d7c3cda83913c92b61a /src/org/slcl/LoginActivity.java
parenta3bfeb15064ab85900e28f0f3f84b88e99c9a466 (diff)
WIP
Diffstat (limited to 'src/org/slcl/LoginActivity.java')
-rw-r--r--src/org/slcl/LoginActivity.java146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/org/slcl/LoginActivity.java b/src/org/slcl/LoginActivity.java
new file mode 100644
index 0000000..79e2ed4
--- /dev/null
+++ b/src/org/slcl/LoginActivity.java
@@ -0,0 +1,146 @@
+/*
+ * slcl-android, an Android frontend for slcl
+ * Copyright (C) 2023-2024 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package org.slcl;
+
+import org.slcl.core.Cookie;
+import org.slcl.core.Login;
+import org.slcl.Directory;
+import org.slcl.InternalFile;
+import java.net.URLEncoder;
+import java.io.IOException;
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.text.Editable;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.TextView;
+
+public final class LoginActivity extends Activity {
+
+ private class LoginParams {
+ public LoginParams(final boolean https, String url,
+ final String username, final String password)
+ {
+ this.https = https;
+ this.username = username;
+ this.url = url;
+ this.password = password;
+ }
+
+ final boolean https;
+ final String url, username, password;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_login);
+
+ Button button = (Button)findViewById(R.id.button);
+
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final EditText url = (EditText)findViewById(R.id.url);
+ final EditText username = (EditText)findViewById(R.id.username);
+ final EditText password = (EditText)findViewById(R.id.password);
+ final CheckBox https = (CheckBox)findViewById(R.id.https);
+
+ url.setText("192.168.1.180:50683");
+ username.setText("a");
+ password.setText("a");
+ https.setChecked(false);
+
+ try {
+ final String urlstr = url.getText().toString();
+ final String encusername = URLEncoder.encode(
+ username.getText().toString(), "UTF-8");
+ final String encpassword = URLEncoder.encode(
+ password.getText().toString(), "UTF-8");
+
+ final LoginTask t = new LoginTask();
+ LoginParams p = new LoginParams(https.isChecked(),
+ urlstr, encusername, encpassword);
+
+ t.execute(p);
+ }
+ catch (final IOException e) {
+ //error.setText("Exception: " + e.getMessage());
+ }
+ }
+ });
+ }
+
+ // https://stackoverflow.com/questions/6053602/what-arguments-are-passed-into-asynctaskarg1-arg2-arg3
+ private final class LoginTask
+ extends AsyncTask<LoginParams, String, String>
+ {
+ ProgressDialog dialog;
+
+ @Override
+ protected void onPreExecute()
+ {
+ dialog = dialog.show(LoginActivity.this, "ProgressDialog",
+ "Logging into server");
+ }
+
+ @Override
+ protected String doInBackground(final LoginParams... params)
+ {
+ try {
+ final LoginParams p = params[0];
+ final Login l = new Login();
+ final String cookie = l.login(p.https, p.url, p.username,
+ p.password);
+ final InternalFile f = new InternalFile(
+ getApplicationContext(), "login");
+ final Cookie c = new Cookie(p.username, cookie);
+
+ c.store(f.getFile());
+ return "";
+ } catch (final IOException e) {
+ System.out.println(e.getMessage());
+ return e.getMessage();
+ }
+ }
+
+ @Override
+ protected void onProgressUpdate(final String... text)
+ {
+ }
+
+ @Override
+ protected void onPostExecute(final String result)
+ {
+ Intent intent = new Intent(LoginActivity.this, Directory.class);
+
+ dialog.dismiss();
+ startActivity(intent);
+ // TODO: review errors.
+ //error.setText("Exception: " + e.getMessage());
+ }
+ }
+}