mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 20:59:00 +00:00
implement password reset
This commit is contained in:
parent
24ed9d1455
commit
e50976f3c5
8 changed files with 73 additions and 12 deletions
|
|
@ -2,7 +2,8 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".ui.activities.LoginActivity">
|
||||
|
||||
<com.habitrpg.android.habitica.ui.views.login.LockableScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -215,15 +216,16 @@
|
|||
android:drawableLeft="@drawable/google_icon"
|
||||
style="@style/LoginButton"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/forgot_pw_tv"
|
||||
<Button
|
||||
android:id="@+id/forgot_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="@dimen/spacing_xlarge"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/forgot_pw_tv"
|
||||
android:text="@string/forgot_pw_btn"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:textColor="@color/white_50_alpha"/>
|
||||
android:textColor="@color/white_75_alpha"
|
||||
android:background="@color/transparent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,6 @@
|
|||
<string name="unlock_lvl_11">Unlock at lvl 11</string>
|
||||
<string name="no_party_message">You are not in a party. To join a party, please visit the website.</string>
|
||||
<string name="forgot_pw_btn">Forgot Password</string>
|
||||
<string name="forgot_pw_tv">Forgot Password? Please use the mobile Website.</string>
|
||||
<string name="tavern.inn.checkOut">Reactivate your Dailies</string>
|
||||
<string name="tavern.inn.rest">Pause your Dailies</string>
|
||||
<string name="reward.dialog.buy">Buy</string>
|
||||
|
|
@ -673,4 +672,8 @@
|
|||
<string name="fix_character_description">If you\'ve encountered a bug or made a mistake that unfairly changed your character (damage you shouldn\'t have taken, Gold you didn\'t really earn, etc.), you can manually correct your numbers here. Yes, this makes it possible to cheat: use this feature wisely, or you\'ll sabotage your own habit-building!</string>
|
||||
<string name="fix_character_values">Fix Character Values</string>
|
||||
<string name="saving">Saving</string>
|
||||
<string name="forgot_password_title">Email a Password Reset Link</string>
|
||||
<string name="forgot_password_description">Enter the email address you used to register your Habitica account.</string>
|
||||
<string name="forgot_password_confirmation">If we have your email on file, instructions for setting a new password have been sent to your email.</string>
|
||||
<string name="ok">OK</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -334,4 +334,7 @@ public interface ApiService {
|
|||
|
||||
@GET("user/toggle-pinned-item/{pinType}/{path}")
|
||||
Observable<HabitResponse<Void>> togglePinnedItem(@Path("pinType") String pinType,@Path("path") String path);
|
||||
|
||||
@POST("user/reset-password")
|
||||
Observable<HabitResponse<Void>> sendPasswordResetEmail(@Body Map<String, String> data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,4 +238,6 @@ public interface ApiClient {
|
|||
Observable<Void> deleteAccount(String password);
|
||||
|
||||
Observable<Void> togglePinnedItem(String pinType, String path);
|
||||
|
||||
Observable<Void> sendPasswordResetEmail(String email);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,4 +64,6 @@ public interface UserRepository extends BaseRepository {
|
|||
|
||||
Observable<User> resetAccount();
|
||||
Observable<Void> deleteAccount(String password);
|
||||
|
||||
Observable<Void> sendPasswordResetEmail(String email);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -949,4 +949,11 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
|
|||
public Observable<Void> togglePinnedItem(String pinType, String path) {
|
||||
return apiService.togglePinnedItem(pinType, path).compose(configureApiCallObserver());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> sendPasswordResetEmail(String email) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("email", email);
|
||||
return apiService.sendPasswordResetEmail(data).compose(configureApiCallObserver());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository>
|
|||
return apiClient.deleteAccount(password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> sendPasswordResetEmail(String email) {
|
||||
return apiClient.sendPasswordResetEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCron(List<Task> tasks) {
|
||||
Observable<List<TaskScoringResult>> observable;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.animation.ObjectAnimator;
|
|||
import android.animation.ValueAnimator;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -18,6 +19,7 @@ import android.support.design.widget.Snackbar;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.Log;
|
||||
|
|
@ -85,6 +87,8 @@ import rx.exceptions.Exceptions;
|
|||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import static com.habitrpg.android.habitica.R.id.password;
|
||||
|
||||
/**
|
||||
* @author Mickael Goubin
|
||||
*/
|
||||
|
|
@ -133,14 +137,14 @@ public class LoginActivity extends BaseActivity
|
|||
ProgressBar mProgressBar;
|
||||
@BindView(R.id.username)
|
||||
EditText mUsernameET;
|
||||
@BindView(R.id.password)
|
||||
@BindView(password)
|
||||
EditText mPasswordET;
|
||||
@BindView(R.id.email)
|
||||
EditText mEmail;
|
||||
@BindView(R.id.confirm_password)
|
||||
EditText mConfirmPassword;
|
||||
@BindView(R.id.forgot_pw_tv)
|
||||
TextView mForgotPWTV;
|
||||
@BindView(R.id.forgot_password)
|
||||
Button forgotPasswordButton;
|
||||
private CallbackManager callbackManager;
|
||||
private String googleEmail;
|
||||
private LoginManager loginManager;
|
||||
|
|
@ -165,10 +169,9 @@ public class LoginActivity extends BaseActivity
|
|||
|
||||
mLoginNormalBtn.setOnClickListener(mLoginNormalClick);
|
||||
|
||||
mForgotPWTV.setOnClickListener(mForgotPWClick);
|
||||
SpannableString content = new SpannableString(mForgotPWTV.getText());
|
||||
SpannableString content = new SpannableString(forgotPasswordButton.getText());
|
||||
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
|
||||
mForgotPWTV.setText(content);
|
||||
forgotPasswordButton.setText(content);
|
||||
|
||||
callbackManager = CallbackManager.Factory.create();
|
||||
|
||||
|
|
@ -640,4 +643,38 @@ public class LoginActivity extends BaseActivity
|
|||
showAnimation.start();
|
||||
UiUtils.dismissKeyboard(this);
|
||||
}
|
||||
|
||||
@OnClick(R.id.forgot_password)
|
||||
public void onForgotPasswordClicked() {
|
||||
final EditText input = new EditText(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
input.setAutofillHints(EditText.AUTOFILL_HINT_EMAIL_ADDRESS);
|
||||
}
|
||||
input.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
input.setLayoutParams(lp);
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.forgot_password_title)
|
||||
.setMessage(R.string.forgot_password_description)
|
||||
.setView(input)
|
||||
.setPositiveButton(R.string.send, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
userRepository.sendPasswordResetEmail(input.getText().toString()).subscribe(aVoid -> {
|
||||
showPasswordEmailConfirmation();
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
}).setNegativeButton(R.string.action_cancel, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void showPasswordEmailConfirmation() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.forgot_password_confirmation)
|
||||
.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue