1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-02-02 20:36:53 +01:00

Fix an issue when logging in.

This commit is contained in:
Thomas 2020-09-05 17:15:07 +02:00
parent a680046574
commit 6d56c7f803
6 changed files with 222 additions and 140 deletions

View File

@ -219,9 +219,9 @@ public class LoginActivity extends AppCompatActivity {
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
parameters.put("grant_type", "password");
try {
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
parameters.put("username", login_uid.getText().toString().trim());
}
try {
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));

View File

@ -17,17 +17,21 @@ package app.fedilab.fedilabtube;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Patterns;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.textfield.TextInputEditText;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.asynctasks.CreatePeertubeAccountAsyncTask;
import app.fedilab.fedilabtube.client.APIResponse;
@ -55,16 +59,53 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
signup = findViewById(R.id.signup);
EditText username = findViewById(R.id.username);
EditText email = findViewById(R.id.email);
EditText password = findViewById(R.id.password);
EditText password_confirm = findViewById(R.id.password_confirm);
TextInputEditText username = findViewById(R.id.username);
TextInputEditText email = findViewById(R.id.email);
TextInputEditText password = findViewById(R.id.password);
TextInputEditText password_confirm = findViewById(R.id.password_confirm);
CheckBox agreement = findViewById(R.id.agreement);
error_message = findViewById(R.id.error_message);
username.setOnFocusChangeListener((view, focused) -> {
if (!focused && username.getText() != null) {
Pattern patternUsername = Pattern.compile("^[a-z0-9._]{1,50}$");
Matcher matcherMaxId = patternUsername.matcher(username.getText().toString());
if (!matcherMaxId.matches()) {
username.setError(getString(R.string.username_error));
}
}
});
email.setOnFocusChangeListener((view, focused) -> {
if (!focused && email.getText() != null) {
Pattern patternUsername = Patterns.EMAIL_ADDRESS;
Matcher matcherMaxId = patternUsername.matcher(email.getText().toString());
if (!matcherMaxId.matches()) {
email.setError(getString(R.string.email_error));
}
}
});
password.setOnFocusChangeListener((view, focused) -> {
if (!focused && password.getText() != null) {
if (password.getText().length() < 6) {
password.setError(getString(R.string.password_length_error));
}
}
});
password_confirm.setOnFocusChangeListener((view, focused) -> {
if (!focused && password_confirm.getText() != null && password.getText() != null) {
if (password_confirm.getText().toString().compareTo(password.getText().toString()) != 0) {
password_confirm.setError(getString(R.string.password));
}
}
});
signup.setOnClickListener(view -> {
error_message.setVisibility(View.GONE);
if (username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
if (username.getText() == null || email.getText() == null || password.getText() == null || password_confirm.getText() == null || username.getText().toString().trim().length() == 0 || email.getText().toString().trim().length() == 0 ||
password.getText().toString().trim().length() == 0 || password_confirm.getText().toString().trim().length() == 0 || !agreement.isChecked()) {
Toasty.error(PeertubeRegisterActivity.this, getString(R.string.all_field_filled)).show();
return;
@ -101,6 +142,7 @@ public class PeertubeRegisterActivity extends AppCompatActivity implements OnPos
accountCreation.setPassword(password.getText().toString().trim());
accountCreation.setPasswordConfirm(password_confirm.getText().toString().trim());
accountCreation.setUsername(username.getText().toString().trim());
accountCreation.setInstance(instance);
new CreatePeertubeAccountAsyncTask(PeertubeRegisterActivity.this, accountCreation, Helper.getPeertubeUrl(instance), PeertubeRegisterActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
});

View File

@ -838,7 +838,7 @@ public class PeertubeAPI {
params.put("username", accountCreation.getUsername());
params.put("email", accountCreation.getEmail());
params.put("password", accountCreation.getPassword());
new HttpsConnection(context).post(getAbsoluteUrl("/users/register"), 30, params, null);
new HttpsConnection(context).post(getAbsoluteUrlForInstance(accountCreation.getInstance(), "/users/register"), 30, params, null);
apiResponse.setStringData(accountCreation.getEmail());
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace();
@ -920,7 +920,6 @@ public class PeertubeAPI {
* @param accountId String account fetched
* @return Account entity
*/
@SuppressWarnings("unused")
public Account getAccount(String accountId) {
account = new Account();
@ -2074,6 +2073,11 @@ public class PeertubeAPI {
return Helper.instanceWithProtocol(context) + "/api/v1" + action;
}
private String getAbsoluteUrlForInstance(String instance, String action) {
return "https://" + instance + "/api/v1" + action;
}
public enum reportType {
ACCOUNT,
COMMENT,

View File

@ -22,6 +22,7 @@ public class AccountCreation {
private String email;
private String password;
private String passwordConfirm;
private String instance;
public String getUsername() {
return username;
@ -62,4 +63,12 @@ public class AccountCreation {
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getInstance() {
return instance;
}
public void setInstance(String instance) {
this.instance = instance;
}
}

View File

@ -14,150 +14,176 @@
You should have received a copy of the GNU General Public License along with TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:orientation="vertical">
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
android:layout_margin="@dimen/fab_margin"
android:orientation="vertical">
<TextView
android:id="@+id/host_reg"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp" />
android:orientation="horizontal">
<TextView
android:id="@+id/host_reg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="18sp" />
<TextView
android:id="@+id/change_instance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/change_instance"
android:layout_width="wrap_content"
android:id="@+id/error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/red_border"
android:gravity="center"
android:padding="5dp"
android:textColor="@color/red_1"
android:visibility="gone" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:labelFor="@+id/username"
android:text="@string/username" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="text"
android:maxLength="30"
android:singleLine="true" />
<TextView
android:id="@+id/username_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/email"
android:text="@string/email" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
android:singleLine="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/email_indicator"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/password"
android:text="@string/password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="textPassword"
android:singleLine="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password_indicator"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/password_confirm"
android:text="@string/password_confirm" />
<EditText
android:id="@+id/password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:importantForAutofill="no"
android:inputType="textPassword"
android:singleLine="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/agreement"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_margin="10dp"
android:background="@drawable/red_border"
android:gravity="center"
android:padding="5dp"
android:textColor="@color/red_1"
android:visibility="gone" />
<TextView
android:id="@+id/agreement_text"
android:layout_width="wrap_content"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/agreement_check_peertube" />
</LinearLayout>
android:layout_marginTop="20dp"
android:labelFor="@+id/username"
android:text="@string/username" />
<Button
android:id="@+id/signup"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sign_up" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/username_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="50" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/username_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/email"
android:text="@string/email" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/email_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/email_indicator"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/password"
android:text="@string/password" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password_indicator"
android:textSize="12sp" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:labelFor="@+id/password_confirm"
android:text="@string/password_confirm" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_confirm_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/agreement"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/agreement_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="@string/agreement_check_peertube" />
</LinearLayout>
<Button
android:id="@+id/signup"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sign_up" />
</LinearLayout>
</ScrollView>

View File

@ -134,6 +134,7 @@
<string name="account_created">Compte créé !</string>
<string name="account_created_message">Votre compte est créé !\n\nVous allez recevoir un email de confirmation à l\'adresse <b>%1$s</b>.\n\nCliquez sur le lien présent dans le mail pour valider votre compte.</string>
<string name="all_field_filled">Veuillez remplir tous les champs !</string>
<string name="password_length_error">Le mot de passe doit contenir 6 caractères !</string>
<string name="password_error">Les mots de passe ne sont pas identiques !</string>
<string name="email_error">L\'e-mail ne semble pas être valide !</string>
<string name="password_too_short">Le mot de passe doit contenir au moins 8 caractères</string>