mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-06-05 21:09:11 +02:00
Register + login
This commit is contained in:
@ -8,13 +8,13 @@ import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -62,11 +62,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
TextView create_an_account_peertube = findViewById(R.id.create_an_account_peertube);
|
||||
|
||||
SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
|
||||
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
||||
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
create_an_account_peertube.setText(content_create);
|
||||
|
||||
|
||||
create_an_account_peertube.setOnClickListener(v -> {
|
||||
Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
|
||||
@ -90,6 +86,12 @@ public class LoginActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
host = Helper.academies[position];
|
||||
SpannableString content_create = new SpannableString(getString(R.string.join_peertube_on, host));
|
||||
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
||||
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
create_an_account_peertube.setText(content_create);
|
||||
retrievesClientId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,8 +100,6 @@ public class LoginActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
ImageView main_logo = findViewById(R.id.main_logo);
|
||||
main_logo.setImageResource(R.drawable.ic_launcher);
|
||||
|
||||
connectionButton.setEnabled(false);
|
||||
|
||||
@ -125,9 +125,9 @@ public class LoginActivity extends AppCompatActivity {
|
||||
host = url.getHost();
|
||||
} catch (MalformedURLException ignored) {
|
||||
}
|
||||
host = Helper.getPeertubeUrl(host);
|
||||
instance = Helper.getPeertubeUrl(host);
|
||||
try {
|
||||
instance = URLEncoder.encode(host, "utf-8");
|
||||
instance = URLEncoder.encode(instance, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@ -168,7 +168,9 @@ public class LoginActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
String finalHost = host;
|
||||
connectionButton.setOnClickListener(v -> {
|
||||
|
||||
connectionButton.setEnabled(false);
|
||||
parameters.clear();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
@ -202,12 +204,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
if (instance != null) {
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
connectionButton.setEnabled(true);
|
||||
Toasty.error(LoginActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, finalHost).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import android.widget.TextView;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask;
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
||||
@ -61,6 +63,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.all_field_filled)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_error)).show();
|
||||
return;
|
||||
@ -69,6 +72,11 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error)).show();
|
||||
return;
|
||||
}
|
||||
String[] emailArray = email.getText().toString().split("@");
|
||||
if( emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
|
||||
return;
|
||||
}
|
||||
if (password.getText().toString().trim().length() < 8) {
|
||||
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_too_short)).show();
|
||||
return;
|
||||
@ -90,8 +98,8 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
|
||||
String tos = getString(R.string.tos);
|
||||
String serverrules = getString(R.string.server_rules);
|
||||
String content_agreement = getString(R.string.agreement_check,
|
||||
"<a href='https://" + Helper.getPeertubeUrl(instance) + "/about/more' >" + serverrules + "</a>",
|
||||
"<a href='https://" + Helper.getPeertubeUrl(instance) + "/terms' >" + tos + "</a>"
|
||||
"<a href='https://apps.education.fr/cgu#peertube' >" + serverrules + "</a>",
|
||||
"<a href='https://apps.education.fr/bonnes-pratiques/' >" + tos + "</a>"
|
||||
);
|
||||
agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
agreement_text.setText(Html.fromHtml(content_agreement));
|
||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.WeakReference;
|
||||
@ -22,13 +23,13 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||
public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private String token, client_id, client_secret, refresh_token;
|
||||
private String instance;
|
||||
private String host;
|
||||
private WeakReference<Context> contextReference;
|
||||
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String instance) {
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token, String client_id, String client_secret, String refresh_token, String host) {
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.token = token;
|
||||
this.instance = instance;
|
||||
this.host = host;
|
||||
this.client_id = client_id;
|
||||
this.client_secret = client_secret;
|
||||
this.refresh_token = refresh_token;
|
||||
@ -40,6 +41,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
if (this.contextReference == null) {
|
||||
return null;
|
||||
}
|
||||
String instance = Helper.getPeertubeUrl(host);
|
||||
account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials();
|
||||
if (account == null)
|
||||
return null;
|
||||
@ -61,7 +63,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
|
||||
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
|
||||
editor.putString(Helper.PREF_INSTANCE, instance);
|
||||
editor.putString(Helper.PREF_INSTANCE, host);
|
||||
editor.apply();
|
||||
if (userExists)
|
||||
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
|
||||
|
@ -15,6 +15,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
@ -131,13 +132,9 @@ public class Helper {
|
||||
"ac-dijon.fr",
|
||||
"ac-grenoble.fr",
|
||||
"education.fr",
|
||||
// "ac-guadeloupe.fr",
|
||||
// "ac-guyane.fr",
|
||||
// "ac-reunion.fr",
|
||||
"ac-lille.fr",
|
||||
"ac-limoges.fr",
|
||||
"ac-lyon.fr",
|
||||
// "ac-martinique.fr",
|
||||
"ac-mayotte.fr",
|
||||
"ac-montpellier.fr",
|
||||
"ac-nancy.fr",
|
||||
@ -148,12 +145,50 @@ public class Helper {
|
||||
"ac-poitiers.fr",
|
||||
"outremer.fr",
|
||||
"ac-rennes.fr",
|
||||
// "ac-spm.fr",
|
||||
"ac-strasbourg.fr",
|
||||
"ac-toulouse.fr",
|
||||
"ac-versailles.fr"
|
||||
};
|
||||
|
||||
|
||||
public static String[] valideEmails = {
|
||||
"ac-aix-marseille.fr",
|
||||
"ac-amiens.fr",
|
||||
"ac-besancon.fr",
|
||||
"ac-bordeaux.fr",
|
||||
"clermont-ferrand.fr",
|
||||
"ac-corse.fr",
|
||||
"ac-creteil.fr",
|
||||
"ac-dijon.fr",
|
||||
"ac-grenoble.fr",
|
||||
"education.fr",
|
||||
"ac-guadeloupe.fr",
|
||||
"ac-guyane.fr",
|
||||
"ac-reunion.fr",
|
||||
"ac-lille.fr",
|
||||
"ac-limoges.fr",
|
||||
"ac-lyon.fr",
|
||||
"ac-martinique.fr",
|
||||
"ac-mayotte.fr",
|
||||
"ac-montpellier.fr",
|
||||
"ac-nancy.fr",
|
||||
"ac-nantes.fr",
|
||||
"ac-normandie.fr",
|
||||
"ac-orleans-tours.fr",
|
||||
"ac-paris.fr",
|
||||
"ac-poitiers.fr",
|
||||
"ac-rennes.fr",
|
||||
"ac-spm.fr",
|
||||
"ac-strasbourg.fr",
|
||||
"ac-toulouse.fr",
|
||||
"ac-versailles.fr",
|
||||
"ac-wf.wf",
|
||||
"monvr.pf",
|
||||
"ac-noumea.nc",
|
||||
"education.gouv.fr",
|
||||
"igesr.gouv.fr"
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the peertube URL depending of the academic domain name
|
||||
*
|
||||
|
Reference in New Issue
Block a user