Register + login

This commit is contained in:
Thomas 2020-06-29 15:43:35 +02:00
parent 515740d889
commit bd6d0bdd3f
8 changed files with 80 additions and 71 deletions

View File

@ -8,13 +8,13 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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); 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 -> { create_an_account_peertube.setOnClickListener(v -> {
Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class); Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
@ -90,6 +86,12 @@ public class LoginActivity extends AppCompatActivity {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
host = Helper.academies[position]; 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 @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); connectionButton.setEnabled(false);
@ -125,9 +125,9 @@ public class LoginActivity extends AppCompatActivity {
host = url.getHost(); host = url.getHost();
} catch (MalformedURLException ignored) { } catch (MalformedURLException ignored) {
} }
host = Helper.getPeertubeUrl(host); instance = Helper.getPeertubeUrl(host);
try { try {
instance = URLEncoder.encode(host, "utf-8"); instance = URLEncoder.encode(instance, "utf-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show(); Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
} }
@ -168,7 +168,9 @@ public class LoginActivity extends AppCompatActivity {
}); });
} }
}).start(); }).start();
String finalHost = host;
connectionButton.setOnClickListener(v -> { connectionButton.setOnClickListener(v -> {
connectionButton.setEnabled(false); connectionButton.setEnabled(false);
parameters.clear(); parameters.clear();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); 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.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply(); editor.apply();
//Update the account with the token; //Update the account with the token;
if (instance != null) { new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, finalHost).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
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();
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -13,6 +13,8 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import java.util.Arrays;
import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask; import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse; import app.fedilab.fedilabtube.client.APIResponse;
import app.fedilab.fedilabtube.client.entities.AccountCreation; 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(); Toasty.error(PeertubeRegisterActivity.this, getString(R.string.all_field_filled)).show();
return; return;
} }
if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) { if (!password.getText().toString().trim().equals(password_confirm.getText().toString().trim())) {
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_error)).show(); Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_error)).show();
return; return;
@ -69,6 +72,11 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error)).show(); Toasty.error(PeertubeRegisterActivity.this, getString(R.string.email_error)).show();
return; 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) { if (password.getText().toString().trim().length() < 8) {
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_too_short)).show(); Toasty.error(PeertubeRegisterActivity.this, getString(R.string.password_too_short)).show();
return; return;
@ -90,8 +98,8 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
String tos = getString(R.string.tos); String tos = getString(R.string.tos);
String serverrules = getString(R.string.server_rules); String serverrules = getString(R.string.server_rules);
String content_agreement = getString(R.string.agreement_check, String content_agreement = getString(R.string.agreement_check,
"<a href='https://" + Helper.getPeertubeUrl(instance) + "/about/more' >" + serverrules + "</a>", "<a href='https://apps.education.fr/cgu#peertube' >" + serverrules + "</a>",
"<a href='https://" + Helper.getPeertubeUrl(instance) + "/terms' >" + tos + "</a>" "<a href='https://apps.education.fr/bonnes-pratiques/' >" + tos + "</a>"
); );
agreement_text.setMovementMethod(LinkMovementMethod.getInstance()); agreement_text.setMovementMethod(LinkMovementMethod.getInstance());
agreement_text.setText(Html.fromHtml(content_agreement)); agreement_text.setText(Html.fromHtml(content_agreement));

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -22,13 +23,13 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> { public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private String token, client_id, client_secret, refresh_token; private String token, client_id, client_secret, refresh_token;
private String instance; private String host;
private WeakReference<Context> contextReference; 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.contextReference = new WeakReference<>(context);
this.token = token; this.token = token;
this.instance = instance; this.host = host;
this.client_id = client_id; this.client_id = client_id;
this.client_secret = client_secret; this.client_secret = client_secret;
this.refresh_token = refresh_token; this.refresh_token = refresh_token;
@ -40,6 +41,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
if (this.contextReference == null) { if (this.contextReference == null) {
return null; return null;
} }
String instance = Helper.getPeertubeUrl(host);
account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials();
if (account == null) if (account == null)
return null; return null;
@ -61,7 +63,7 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin());
editor.putString(Helper.PREF_INSTANCE, instance); editor.putString(Helper.PREF_INSTANCE, host);
editor.apply(); editor.apply();
if (userExists) if (userExists)
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account); new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);

View File

@ -15,6 +15,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
@ -131,13 +132,9 @@ public class Helper {
"ac-dijon.fr", "ac-dijon.fr",
"ac-grenoble.fr", "ac-grenoble.fr",
"education.fr", "education.fr",
// "ac-guadeloupe.fr",
// "ac-guyane.fr",
// "ac-reunion.fr",
"ac-lille.fr", "ac-lille.fr",
"ac-limoges.fr", "ac-limoges.fr",
"ac-lyon.fr", "ac-lyon.fr",
// "ac-martinique.fr",
"ac-mayotte.fr", "ac-mayotte.fr",
"ac-montpellier.fr", "ac-montpellier.fr",
"ac-nancy.fr", "ac-nancy.fr",
@ -148,12 +145,50 @@ public class Helper {
"ac-poitiers.fr", "ac-poitiers.fr",
"outremer.fr", "outremer.fr",
"ac-rennes.fr", "ac-rennes.fr",
// "ac-spm.fr",
"ac-strasbourg.fr", "ac-strasbourg.fr",
"ac-toulouse.fr", "ac-toulouse.fr",
"ac-versailles.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 * Returns the peertube URL depending of the academic domain name
* *

View File

@ -1,30 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -22,25 +22,20 @@
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:contentDescription="@string/app_logo" android:contentDescription="@string/app_logo"
app:layout_constraintEnd_toEndOf="parent" android:src="@drawable/ic_launcher_foreground"
app:layout_constraintEnd_toStartOf="@+id/info_instance"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Spinner <Spinner
android:id="@+id/info_instance" android:id="@+id/info_instance"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toEndOf="@+id/main_logo"
app:layout_constraintTop_toBottomOf="@id/main_logo" /> app:layout_constraintTop_toTopOf="@+id/main_logo"
app:layout_constraintBottom_toBottomOf="@+id/main_logo"
<androidx.constraintlayout.widget.Barrier />
android:id="@+id/barrier_instance_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="info_instance" />
<TextView <TextView
android:id="@+id/create_an_account_peertube" android:id="@+id/create_an_account_peertube"
@ -50,11 +45,11 @@
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:drawablePadding="10dp" android:drawablePadding="10dp"
android:gravity="center" android:gravity="center"
android:text="@string/join_peertube" android:text="@string/join_peertube_on"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/barrier_instance_bottom" /> app:layout_constraintTop_toBottomOf="@id/main_logo" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -143,5 +143,7 @@
<string name="tos">conditions de service</string> <string name="tos">conditions de service</string>
<string name="server_rules">règles du serveur</string> <string name="server_rules">règles du serveur</string>
<string name="agreement_check">J\'accepte les %1$s et les %2$s</string> <string name="agreement_check">J\'accepte les %1$s et les %2$s</string>
<string name="join_peertube_on">Rejoindre <b>%1$s</b></string>
<string name="email_error_domain">Les adresses mails %1$s ne sont pas autorisées !</string>
</resources> </resources>