Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
fix(PwRecovery)
Browse files Browse the repository at this point in the history
fix check: check for numbers
fix check: check for equality
fix messages: add number, correct speling mistakes
fix: server url
fix: actually reset password
fix: return to login
  • Loading branch information
JonasWanke committed Jul 2, 2018
1 parent 65544c2 commit fdc9491
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 217 deletions.
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
android:label="@string/app_name"
android:noHistory="true" />

<activity
android:name=".ui.PasswordRecovery.PasswordRecovery"
android:noHistory="true"
android:parentActivityName=".ui.signin.SignInActivity" />

<activity
android:name=".ui.main.MainActivity"
android:label="@string/app_name"
Expand Down Expand Up @@ -177,8 +182,6 @@
</intent-filter>
</receiver>

<activity android:name=".ui.PasswordRecovery.PasswordRecovery" />


</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,19 @@ public void signOut() {
mPreferencesHelper.clear();
}

public Observable<ResetResponse> requestResetPassword(String username ){
return mRestService.passwordRecovery(getAccessToken(),new ResetRequest(username));
public Observable<ResetResponse> requestResetPassword(String username){
return mRestService.passwordRecovery(getAccessToken(), new ResetRequest(username));
}
public Observable<ResponseBody> resetPassword(String AccountId,String passwort){
return mRestService.passwordReset(getAccessToken(),new ResetData(AccountId,passwort));
public Observable<ResponseBody> resetPassword(String accountId, String password) {
return mRestService.passwordReset(getAccessToken(), new ResetData(accountId, password));
}

public Observable<CurrentUser> syncCurrentUser(String userId) {
return mRestService.getUser(getAccessToken(), userId).concatMap(
new Func1<CurrentUser, Observable<CurrentUser>>() {
@Override
public Observable<CurrentUser> 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<CurrentUser> getCurrentUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,31 +12,25 @@
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;

import butterknife.BindView;
import butterknife.ButterKnife;


public class PasswordRecovery extends BaseActivity<PasswordRecoveryMvpView,PasswordRecoveryPresenter > implements PasswordRecoveryMvpView

{

public class PasswordRecovery extends BaseActivity<PasswordRecoveryMvpView, PasswordRecoveryPresenter> implements PasswordRecoveryMvpView {
@Inject
UserDataManager mUserDataManager;
@Inject
FeedbackDataManager mFeedbackDataManager;



@Inject
PasswordRecoveryPresenter mPasswordRecoveryPresenter;

Expand All @@ -55,7 +50,6 @@ public class PasswordRecovery extends BaseActivity<PasswordRecoveryMvpView,Passw
private int step = 0;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -65,19 +59,18 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);
setStep(0);
this.startService(UserSyncService.getStartIntent(this));
recoveryButton.setOnClickListener(v-> 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));
}
}

Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading

0 comments on commit fdc9491

Please sign in to comment.