diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7c9fb625..531a4aae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,6 +32,11 @@ android:label="@string/app_name" android:noHistory="true" /> + + - - diff --git a/app/src/main/java/org/schulcloud/mobile/data/datamanagers/UserDataManager.java b/app/src/main/java/org/schulcloud/mobile/data/datamanagers/UserDataManager.java index 9cc7940e..400029d8 100644 --- a/app/src/main/java/org/schulcloud/mobile/data/datamanagers/UserDataManager.java +++ b/app/src/main/java/org/schulcloud/mobile/data/datamanagers/UserDataManager.java @@ -83,23 +83,19 @@ public void signOut() { mPreferencesHelper.clear(); } - public Observable requestResetPassword(String username ){ - return mRestService.passwordRecovery(getAccessToken(),new ResetRequest(username)); + public Observable requestResetPassword(String username){ + return mRestService.passwordRecovery(getAccessToken(), new ResetRequest(username)); } - public Observable resetPassword(String AccountId,String passwort){ - return mRestService.passwordReset(getAccessToken(),new ResetData(AccountId,passwort)); + public Observable resetPassword(String accountId, String password) { + return mRestService.passwordReset(getAccessToken(), new ResetData(accountId, password)); } public Observable syncCurrentUser(String userId) { - return mRestService.getUser(getAccessToken(), userId).concatMap( - new Func1>() { - @Override - public Observable call(CurrentUser currentUser) { - mPreferencesHelper.saveCurrentUsername(currentUser.displayName); - mPreferencesHelper.saveCurrentSchoolId(currentUser.schoolId); - return mUserDatabaseHelper.setCurrentUser(currentUser); - } - }).doOnError(Throwable::printStackTrace); + return mRestService.getUser(getAccessToken(), userId).concatMap(currentUser -> { + mPreferencesHelper.saveCurrentUsername(currentUser.displayName); + mPreferencesHelper.saveCurrentSchoolId(currentUser.schoolId); + return mUserDatabaseHelper.setCurrentUser(currentUser); + }).doOnError(Throwable::printStackTrace); } public Single getCurrentUser() { diff --git a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecovery.java b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecovery.java index 03db6927..3bf32044 100644 --- a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecovery.java +++ b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecovery.java @@ -1,7 +1,8 @@ package org.schulcloud.mobile.ui.PasswordRecovery; - +import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -11,13 +12,12 @@ import org.schulcloud.mobile.data.datamanagers.FeedbackDataManager; import org.schulcloud.mobile.data.datamanagers.UserDataManager; import org.schulcloud.mobile.data.model.Account; -import org.schulcloud.mobile.data.model.User; import org.schulcloud.mobile.data.model.requestBodies.FeedbackRequest; import org.schulcloud.mobile.data.model.responseBodies.ResetResponse; import org.schulcloud.mobile.data.sync.UserSyncService; import org.schulcloud.mobile.ui.base.BaseActivity; - - +import org.schulcloud.mobile.ui.signin.SignInActivity; +import org.schulcloud.mobile.util.WebUtil; import javax.inject.Inject; @@ -25,17 +25,12 @@ import butterknife.ButterKnife; -public class PasswordRecovery extends BaseActivity implements PasswordRecoveryMvpView - -{ - +public class PasswordRecovery extends BaseActivity implements PasswordRecoveryMvpView { @Inject UserDataManager mUserDataManager; @Inject FeedbackDataManager mFeedbackDataManager; - - @Inject PasswordRecoveryPresenter mPasswordRecoveryPresenter; @@ -55,7 +50,6 @@ public class PasswordRecovery extends BaseActivity executeStep() ); - + recoveryButton.setOnClickListener(v -> executeStep()); } private void executeStep(){ if(getStep() == 0) { RequestNewPassword(input_emailUser.getText().toString()); }else if(getStep() == 1){ - CheckCode(code_input.getText().toString()); + checkCode(code_input.getText().toString()); }else if(getStep() == 2){ - PasswordsEqual(pw_input.getText().toString(),pw_input_repeat.getText().toString()); - }else if(getStep() == 3){ - PasswordValid(pw_input.getText().toString()); + checkPasswords(pw_input.getText().toString(), pw_input_repeat.getText().toString()); + } else { + startActivity(new Intent(this, SignInActivity.class)); } } @@ -86,51 +79,43 @@ private void setMessageText(String messageText, int color){ errorMessageView.setTextColor(color); } - private void RequestNewPassword(String input) { - mPasswordRecoveryPresenter.requestReset(input); + private void RequestNewPassword(String email) { + mPasswordRecoveryPresenter.requestReset(email); } - private void PasswordValid(String password){ - if(mPasswordRecoveryPresenter.isNewPasswortValid(password)){ - showSuccessMessage(); - setStep(4); - showSuccessMessage(); - } - else{ - showErrorMessage(); - } - } - - private void CheckCode(String code){ + private void checkCode(String code){ mPasswordRecoveryPresenter.checkCode(code); } - private void PasswordsEqual(String pw1,String pw2) { - if (mPasswordRecoveryPresenter.passwordsEqual(pw1, pw2)){ - showSuccessMessage(); - setStep(3); - executeStep(); - }else{ - showErrorMessage(); - } + private void checkPasswords(String pw1, String pw2) { + if (!mPasswordRecoveryPresenter.isNewPasswortValid(pw1)) + showErrorMessage(false); + else if (!mPasswordRecoveryPresenter.passwordsEqual(pw1, pw2)) + showErrorMessage(true); + else + mPasswordRecoveryPresenter.setPassword(pw1); } - public void setStep(int step){ - if(step==0){ + public void setStep(int step) { + if (step == 0) { this.input_emailUser.setVisibility(View.VISIBLE); this.code_input.setVisibility(View.GONE); this.pw_input.setVisibility(View.GONE); this.pw_input_repeat.setVisibility(View.GONE); - }else if(step==1){ + } else if (step == 1) { this.input_emailUser.setVisibility(View.GONE); this.code_input.setVisibility(View.VISIBLE); this.pw_input.setVisibility(View.GONE); this.pw_input_repeat.setVisibility(View.GONE); - } - else if(step==2 || step==3){ + } else if (step == 2) { this.input_emailUser.setVisibility(View.GONE); this.code_input.setVisibility(View.GONE); this.pw_input.setVisibility(View.VISIBLE); this.pw_input_repeat.setVisibility(View.VISIBLE); + } else if (step == 3) { + this.input_emailUser.setVisibility(View.GONE); + this.code_input.setVisibility(View.GONE); + this.pw_input.setVisibility(View.GONE); + this.pw_input_repeat.setVisibility(View.GONE); } this.step = step; } @@ -146,22 +131,26 @@ public void showSuccessMessage() { setMessageText(getResources().getString(R.string.recovery_success_request), color); else if(getStep()==1) setMessageText(getResources().getString(R.string.recovery_success_code_input), color); - else if(getStep()==4) + else if(getStep()==3) { setMessageText(getResources().getString(R.string.recovery_success), color); + recoveryButton.setText(R.string.recovery_button_done); + } } @Override - public void showErrorMessage() { + public void showErrorMessage(boolean subStep) { int color = getResources().getColor(R.color.hpiRed); - if(getStep() == 0) - setMessageText(getResources().getString(R.string.recovery_errorMessage_Email),color ); - else if(getStep()==1) + if (getStep() == 0) + setMessageText(getResources().getString(R.string.recovery_errorMessage_Email), color); + else if (getStep() == 1) setMessageText(getResources().getString(R.string.recovery_errorMessage_code_input), color); - else if(getStep()==2) - setMessageText(getResources().getString(R.string.recovery_errorMessage_pw_ungleich), color); - else if(getStep()==3) - setMessageText(getResources().getString(R.string.recovery_errorMessage_pw_fehlende_zeichen), color); - else if(getStep()==4) + else if (getStep() == 2) + if (!subStep) + setMessageText(getResources() + .getString(R.string.recovery_errorMessage_pw_fehlende_zeichen), color); + else + setMessageText(getResources().getString(R.string.recovery_errorMessage_pw_ungleich), color); + else setMessageText(getResources().getString(R.string.recovery_errorMessage_final_error), color); } @@ -171,9 +160,8 @@ public void sendEmail(ResetResponse responseBody, Account account){ String text = getResources().getString(R.string.recovery_email_text); String subject = getResources().getString(R.string.recovery_reset_email_subject); - String username = (account.userId.firstName==""||account.userId.firstName == null) ? account.username : account.userId.firstName+" "+ account.userId.lastName; - text = String.format(text, username,Code, "http://192.168.1.179:3100"+"/pwrecovery/"+Code); - mFeedbackDataManager.sendEmail(new FeedbackRequest(text,subject,account.userId.email)); - + String username = TextUtils.isEmpty(account.userId.firstName) ? account.username : account.userId.firstName + " " + account.userId.lastName; + text = String.format(text, username, Code, WebUtil.URL_BASE + "/pwrecovery/" + Code); + mFeedbackDataManager.sendEmail(new FeedbackRequest(text, subject, account.userId.email)); } } diff --git a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryMvpView.java b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryMvpView.java index bc4a855a..b63e37c0 100644 --- a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryMvpView.java +++ b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryMvpView.java @@ -6,7 +6,7 @@ public interface PasswordRecoveryMvpView extends MvpView { void showSuccessMessage(); - void showErrorMessage(); + void showErrorMessage(boolean subStep); void setStep(int step); void sendEmail(ResetResponse responseBody, Account account); } diff --git a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryPresenter.java b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryPresenter.java index fecad31c..4f7308a1 100644 --- a/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryPresenter.java +++ b/app/src/main/java/org/schulcloud/mobile/ui/PasswordRecovery/PasswordRecoveryPresenter.java @@ -1,120 +1,87 @@ package org.schulcloud.mobile.ui.PasswordRecovery; -import android.renderscript.ScriptIntrinsicYuvToRGB; import android.support.annotation.NonNull; +import android.text.TextUtils; -import org.schulcloud.mobile.data.datamanagers.CourseDataManager; -import org.schulcloud.mobile.data.datamanagers.FeedbackDataManager; import org.schulcloud.mobile.data.datamanagers.UserDataManager; -import org.schulcloud.mobile.data.model.AccessToken; import org.schulcloud.mobile.data.model.Account; -import org.schulcloud.mobile.data.model.Course; -import org.schulcloud.mobile.data.model.CurrentUser; -import org.schulcloud.mobile.data.model.User; -import org.schulcloud.mobile.data.model.requestBodies.FeedbackRequest; import org.schulcloud.mobile.data.model.responseBodies.ResetResponse; -import org.schulcloud.mobile.data.sync.UserSyncService; import org.schulcloud.mobile.injection.ConfigPersistent; import org.schulcloud.mobile.ui.base.BasePresenter; -import org.schulcloud.mobile.util.RxUtil; - -import java.util.List; import javax.inject.Inject; -import io.realm.Realm; -import rx.Observable; -import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; @ConfigPersistent public class PasswordRecoveryPresenter extends BasePresenter { private final UserDataManager mUserDataManager; - private Subscription mSubscription; private Account resetAccount = null; private ResetResponse resetResponse = null; - @Inject public PasswordRecoveryPresenter(UserDataManager userDataManager) { mUserDataManager = userDataManager; } - - public void requestReset(@NonNull String username) { - - - mUserDataManager.requestResetPassword(username) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - responseBody -> sendToView(view -> { - resetResponse = responseBody; - mUserDataManager.getAccount(responseBody.account).observeOn(AndroidSchedulers.mainThread()).subscribe(response ->{ - this.resetAccount = response; - view.sendEmail(responseBody,getAccount()); - view.showSuccessMessage(); - view.setStep(1); - },error->{ - System.out.print(error.getMessage()); - }); - - }), - error -> { - sendToView(PasswordRecoveryMvpView::showErrorMessage); - - }); - - + public void requestReset(@NonNull String email) { + mUserDataManager.requestResetPassword(email) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + responseBody -> sendToView(view -> { + resetResponse = responseBody; + mUserDataManager.getAccount(responseBody.account) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(response -> { + resetAccount = response; + view.sendEmail(responseBody, getAccount()); + view.showSuccessMessage(); + view.setStep(1); + }, error -> System.out.print(error.getMessage())); + }), + error -> sendToView(view -> view.showErrorMessage(false))); } - public void setPasswort(String AccountId,String passwort){ - - mUserDataManager.resetPassword(AccountId,passwort) + public void setPassword(String password) { + mUserDataManager.resetPassword(resetAccount._id, password) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(responseBody -> sendToView(view ->{ + .subscribe(responseBody -> sendToView(view -> { + view.setStep(3); view.showSuccessMessage(); - view.setStep(5); - }), error -> sendToView(view ->{ - view.showErrorMessage(); - })); + }), error -> sendToView(view -> view.showErrorMessage(false))); } - public void checkCode(String code){ + public void checkCode(String code) { final String rightCode = resetResponse._id; - sendToView(v->{ - if(code.equals(rightCode)){ - v.showSuccessMessage(); - v.setStep(2); - }else{ - v.showErrorMessage(); - } - }); - - - + sendToView(v -> { + if (code.equals(rightCode)) { + v.showSuccessMessage(); + v.setStep(2); + } else + v.showErrorMessage(false); + }); } - public boolean passwordsEqual(String pw1,String pw2) { - return (pw1.equals(pw2)); + public boolean passwordsEqual(String pw1, String pw2) { + return TextUtils.equals(pw1, pw2); } public boolean isNewPasswortValid(String passwort){ int pwSize = passwort.length(); int capChars = charsInInterval(passwort,'A','Z'); int smallChars = charsInInterval(passwort,'a','z'); - int specialChars = pwSize - capChars - smallChars; + int digits = charsInInterval(passwort,'0','9'); + int specialChars = pwSize - capChars - smallChars - digits; - if(pwSize<8){ + if (pwSize < 8) return false; - } - if(capChars<1){ + if (capChars < 1) return false; - } - if(smallChars<1){ + if (smallChars < 1) return false; - } - if(specialChars<1){ + if (digits < 1) + return false; + if (specialChars < 1) return false; - } return true; } @@ -128,10 +95,7 @@ private int charsInInterval(String pw,char min,char max){ return amount; } - private Account getAccount(){ return this.resetAccount; } - - } diff --git a/app/src/main/res/layouts/courses/layout/activity_password_recovery.xml b/app/src/main/res/layouts/courses/layout/activity_password_recovery.xml index 01ba3bd9..8afea5e7 100644 --- a/app/src/main/res/layouts/courses/layout/activity_password_recovery.xml +++ b/app/src/main/res/layouts/courses/layout/activity_password_recovery.xml @@ -1,103 +1,76 @@ - + android:layout_height="match_parent"> + tools:context=".ui.PasswordRecovery.PasswordRecovery"> - + android:inputType="textEmailAddress" /> + android:inputType="textPersonName" /> + android:inputType="textPassword" /> + android:inputType="textPassword" /> - - - - - -