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

Commit

Permalink
Merge pull request #126 from schul-cloud/109-password-recovery-new
Browse files Browse the repository at this point in the history
109 - Password recovery feature added
  • Loading branch information
kremer-io authored Jul 3, 2018
2 parents 55ae92f + fdc9491 commit 8b42853
Show file tree
Hide file tree
Showing 17 changed files with 529 additions and 9 deletions.
6 changes: 6 additions & 0 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,6 +182,7 @@
</intent-filter>
</receiver>


</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import org.schulcloud.mobile.data.model.requestBodies.FeedbackRequest;
import org.schulcloud.mobile.data.model.responseBodies.FeedbackResponse;
import org.schulcloud.mobile.data.remote.RestService;
import org.schulcloud.mobile.ui.PasswordRecovery.PasswordRecoveryMvpView;

import javax.inject.Inject;
import javax.inject.Singleton;

import okhttp3.ResponseBody;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;

@Singleton
Expand Down Expand Up @@ -41,4 +44,12 @@ public Observable<FeedbackResponse> call(FeedbackResponse feedbackResponse) {
}
});
}

public void sendEmail(FeedbackRequest feedbackRequest){

mRestService
.sendFeedback(userDataManager.getAccessToken(),feedbackRequest)
.observeOn(AndroidSchedulers.mainThread()).subscribe(res->{},error -> {});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import org.schulcloud.mobile.data.local.PreferencesHelper;
import org.schulcloud.mobile.data.local.UserDatabaseHelper;
import org.schulcloud.mobile.data.model.Account;
import org.schulcloud.mobile.data.model.CurrentUser;
import org.schulcloud.mobile.data.model.User;
import org.schulcloud.mobile.data.model.requestBodies.Credentials;
import org.schulcloud.mobile.data.model.requestBodies.ResetData;
import org.schulcloud.mobile.data.model.requestBodies.ResetRequest;
import org.schulcloud.mobile.data.model.responseBodies.ResetResponse;
import org.schulcloud.mobile.data.remote.RestService;
import org.schulcloud.mobile.util.crypt.JWTUtil;

Expand All @@ -13,6 +17,7 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import okhttp3.ResponseBody;
import rx.Observable;
import rx.Single;
import rx.functions.Func1;
Expand Down Expand Up @@ -52,6 +57,12 @@ public Observable<List<User>> getUsers() {
return mUserDatabaseHelper.getUsers().distinctUntilChanged();
}

public Observable<Account> getAccount(String accountID){
return mRestService.getAccount(getAccessToken(),accountID);
}



public String getAccessToken() {
return mPreferencesHelper.getAccessToken();
}
Expand All @@ -72,16 +83,19 @@ public void signOut() {
mPreferencesHelper.clear();
}

public Observable<ResetResponse> requestResetPassword(String username){
return mRestService.passwordRecovery(getAccessToken(), new ResetRequest(username));
}
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
Expand Up @@ -4,6 +4,7 @@
import org.schulcloud.mobile.data.model.CurrentUser;
import org.schulcloud.mobile.data.model.User;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

Expand All @@ -12,6 +13,7 @@
import javax.inject.Singleton;

import io.realm.Realm;
import io.realm.RealmResults;
import rx.Observable;
import rx.Single;
import timber.log.Timber;
Expand Down Expand Up @@ -49,6 +51,7 @@ public Observable<List<User>> getUsers() {
.map(users -> realm.copyFromRealm(users));
}


public Observable<AccessToken> setAccessToken(final AccessToken newAccessToken) {
return Observable.create(subscriber -> {
if (subscriber.isUnsubscribed())
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/data/model/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmModel;

import io.realm.annotations.PrimaryKey;
import io.realm.annotations.RealmClass;

@RealmClass
public class Account implements RealmModel {
@PrimaryKey
public String _id;
public String username;
public String password;
public String updatedAt;
public String createdAt;
public User userId;


public String get_id() {
return _id;
}

public void set_id(String _id) {
this._id = _id;
}

public void setUsername(String username){this.username = username;}

public String getUsername(){return this.username;}

public void setPassword(String password){}

public String getUpdatedAt(){return this.updatedAt;}

public void setUpdatedAt(String updatedAt){this.updatedAt = updatedAt;}

public String getCreatedAt(){return this.createdAt;}

public void setCreatedAt(String createdAt){this.createdAt = createdAt;}

public User getUserId(){return this.userId;}

public void setUserId(User userId){this.userId = userId;}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.schulcloud.mobile.data.model.requestBodies;

public class ResetData {
String accountId;
String password;

public ResetData(String accountId,String password){
this.accountId = accountId;
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.schulcloud.mobile.data.model.requestBodies;

public class ResetRequest {
public String username;

public ResetRequest(String username){
this.username = username;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.schulcloud.mobile.data.model.responseBodies;

public class ResetResponse {
public String _id;
public String account;
public String updatedAt;
public String createdAt;
public boolean changed;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schulcloud.mobile.data.remote;

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.Device;
Expand All @@ -18,12 +19,15 @@
import org.schulcloud.mobile.data.model.requestBodies.Credentials;
import org.schulcloud.mobile.data.model.requestBodies.DeviceRequest;
import org.schulcloud.mobile.data.model.requestBodies.FeedbackRequest;
import org.schulcloud.mobile.data.model.requestBodies.ResetData;
import org.schulcloud.mobile.data.model.requestBodies.ResetRequest;
import org.schulcloud.mobile.data.model.requestBodies.SignedUrlRequest;
import org.schulcloud.mobile.data.model.responseBodies.AddHomeworkResponse;
import org.schulcloud.mobile.data.model.responseBodies.DeviceResponse;
import org.schulcloud.mobile.data.model.responseBodies.FeathersResponse;
import org.schulcloud.mobile.data.model.responseBodies.FeedbackResponse;
import org.schulcloud.mobile.data.model.responseBodies.FilesResponse;
import org.schulcloud.mobile.data.model.responseBodies.ResetResponse;
import org.schulcloud.mobile.data.model.responseBodies.SignedUrlResponse;

import java.util.List;
Expand Down Expand Up @@ -51,9 +55,19 @@ public interface RestService {
@GET("users/{userId}")
Observable<CurrentUser> getUser(@Header("Authorization") String accessToken, @Path("userId") String userId);


@GET("accounts/{accountId}?$populate[0]=userId")
Observable<Account> getAccount(@Header("Authorization") String accessToken, @Path("accountId") String accountId);

@POST("authentication")
Observable<AccessToken> signIn(@Body Credentials credentials);

@POST("passwordRecovery")
Observable<ResetResponse> passwordRecovery(@Header("Authorization") String accessToken, @Body ResetRequest username);

@POST("passwordRecovery/reset")
Observable<ResponseBody> passwordReset(@Header("Authorization") String accessToken, @Body ResetData data);

// todo: move Authorization-Header to somewhere better
@GET("fileStorage")
Observable<FilesResponse> getFiles(@Header("Authorization") String accessToken, @Query("path") String path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.schulcloud.mobile.injection.module.ActivityModule;
import org.schulcloud.mobile.injection.scope.PerActivity;
import org.schulcloud.mobile.ui.PasswordRecovery.PasswordRecovery;
import org.schulcloud.mobile.ui.courses.CourseFragment;
import org.schulcloud.mobile.ui.courses.detailed.DetailedCourseFragment;
import org.schulcloud.mobile.ui.courses.topic.ContentAdapter;
Expand Down Expand Up @@ -35,6 +36,9 @@ public interface ActivityComponent {
// Sign in
void inject(SignInActivity signInActivity);

// Password Recovery
void inject(PasswordRecovery passwordRecovery);

// Main
void inject(MainActivity mainActivity);

Expand Down
Loading

0 comments on commit 8b42853

Please sign in to comment.