Skip to content

Commit

Permalink
Merge pull request #91 from aferodeveloper/topic/reset-password
Browse files Browse the repository at this point in the history
Fix for AferoClient.resetPasswordWithCode 400 error
  • Loading branch information
Tony Myles authored Sep 20, 2019
2 parents 4f59c25 + ae8f9eb commit 4f63850
Show file tree
Hide file tree
Showing 17 changed files with 560 additions and 37 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Change Log
==========

Version 1.4.5 *(2019-09-20)*
----------------------------
* Fix: `AferoClient.resetPasswordWithCode` now actually works rather than returning a 400 error.
* New: AferoLab sample app now has a basic "Forgot Password" flow.

Version 1.4.4 *(2019-09-09)*
----------------------------
* Fixed: Added logic to `ConclaveDeviceEventSource.stop()` to clear the access credentials and account id.
* Fix: Added logic to `ConclaveDeviceEventSource.stop()` to clear the access credentials and account id.
* Removed: `ConclaveDeviceEventSource.setAccountId()` since this function is defunct.

Version 1.4.3 *(2019-08-22)*
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
author: Tony Myles
title: "AferoJavaSDK"
date: 2019-Sept-9
status: 1.4.4
date: 2019-Sept-20
status: 1.4.5
---

# AferoJavaSDK
Expand Down Expand Up @@ -32,23 +32,23 @@ The SDK is composed of four separate modules.

The `afero-sdk-core` module is required for base functionality such as interacting with the Afero Cloud and manipulating devices.
```Gradle
implementation 'io.afero.sdk:afero-sdk-core:1.4.4'
implementation 'io.afero.sdk:afero-sdk-core:1.4.5'
```

The `afero-sdk-client-retrofit2` module provides an optional implementation of the AferoClient REST API interface using [Retrofit2](http://square.github.io/retrofit/) and [okhttp3](http://square.github.io/okhttp/). If you choose not to include this module in your project, you will need to develop your own implementation of AferoClient using your preferred http client library.

```Gradle
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.4.4'
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.4.5'
```

The `afero-sdk-android` module is required for Android development.
```Gradle
implementation 'io.afero.sdk:afero-sdk-android:1.4.4'
implementation 'io.afero.sdk:afero-sdk-android:1.4.5'
```

The `afero-sdk-softhub` module is required for soft hub functionality on Android.
```Gradle
implementation 'io.afero.sdk:afero-sdk-softhub:1.4.4'
implementation 'io.afero.sdk:afero-sdk-softhub:1.4.5'
implementation "io.afero.sdk:hubby:1.0.844@aar"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.afero.sdk.client.afero.models.InvitationDetails;
import io.afero.sdk.client.afero.models.Location;
import io.afero.sdk.client.afero.models.PostActionBody;
import io.afero.sdk.client.afero.models.ResetPasswordBody;
import io.afero.sdk.client.afero.models.RuleExecuteBody;
import io.afero.sdk.client.afero.models.ViewRequest;
import io.afero.sdk.client.afero.models.ViewResponse;
Expand Down Expand Up @@ -423,7 +424,7 @@ public Observable<Void> resetPassword(String email) {
*/
@Override
public Observable<Void> resetPasswordWithCode(String resetCode, String newPassword) {
return mAferoService.resetPasswordWithCode(resetCode, newPassword);
return mAferoService.resetPasswordWithCode(resetCode, new ResetPasswordBody(newPassword));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.afero.sdk.client.afero.models.InvitationDetails;
import io.afero.sdk.client.afero.models.Location;
import io.afero.sdk.client.afero.models.PostActionBody;
import io.afero.sdk.client.afero.models.ResetPasswordBody;
import io.afero.sdk.client.afero.models.RuleExecuteBody;
import io.afero.sdk.client.afero.models.ViewRequest;
import io.afero.sdk.client.afero.models.ViewResponse;
Expand Down Expand Up @@ -88,7 +89,7 @@ Observable<Void> resetPassword(
@POST(V1 + "shortvalues/{resetCode}/passwordReset")
Observable<Void> resetPasswordWithCode(
@Path("resetCode") String resetCode,
@Body String newPassword
@Body ResetPasswordBody body
);

@POST(V1 + "credentials/{email}/passwordReset")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
*/

package io.afero.sdk.client.afero.models;


public class ResetPasswordBody {
public String password;

public ResetPasswordBody(String pw) {
password = pw;
}
}
4 changes: 0 additions & 4 deletions afero-sdk-softhub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ apply plugin: 'com.android.library'
repositories {
maven {
url "https://afero.jfrog.io/afero/hubby-android"
credentials {
username = project.aferoArtifactoryUserName
password = project.aferoArtifactoryPassword
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion samples/afero-lab/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
apply plugin: 'com.android.application'

final String sdkRepoKey = project.findProperty('aferoSDKConsumeRepoKey') ?: 'afero-java-sdk'
final String sdkVersion = project.findProperty('aferoSDKVersion') ?: '1.4.4'
final String sdkVersion = project.findProperty('aferoSDKVersion') ?: '1.4.5'

repositories {
maven {
url "https://afero.jfrog.io/afero/${sdkRepoKey}"
artifactUrls "https://afero.jfrog.io/afero/hubby-android"
credentials {
username = project.aferoArtifactoryUserName
password = project.aferoArtifactoryPassword
}
}
}
configurations.all {
Expand Down Expand Up @@ -95,4 +99,5 @@ dependencies {

testImplementation 'junit:junit:4.12'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2017 Afero, Inc. All rights reserved.
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
*/

package io.afero.aferolab;
Expand All @@ -26,6 +26,7 @@

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnEditorAction;
import io.afero.aferolab.addDevice.AddDeviceView;
import io.afero.aferolab.addDevice.AddSetupModeDeviceView;
Expand All @@ -35,6 +36,7 @@
import io.afero.aferolab.helper.BackStack;
import io.afero.aferolab.helper.PermissionsHelper;
import io.afero.aferolab.helper.PrefsHelper;
import io.afero.aferolab.resetPassword.RequestCodeView;
import io.afero.aferolab.widget.AferoEditText;
import io.afero.aferolab.widget.ScreenView;
import io.afero.sdk.android.clock.AndroidClock;
Expand Down Expand Up @@ -369,14 +371,25 @@ public void onNext(AddSetupModeDeviceView addDeviceView) {}
public boolean onEditorActionSignIn(TextView textView, int actionId, KeyEvent event) {
if (AferoEditText.isDone(actionId, event)) {
if (textView.getId() == R.id.edit_text_password) {
startSignIn(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
mPasswordEditText.hideKeyboard();
onClickSignIn();
}
}

return true;
}

@OnClick(R.id.button_sign_in)
public void onClickSignIn() {
mPasswordEditText.hideKeyboard();
startSignIn(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
}

@OnClick(R.id.button_forgot_password)
public void onClickForgotPassword() {
mPasswordEditText.hideKeyboard();
RequestCodeView.create(mRootView).start(mAferoClient);
}

private void startSignIn(String email, String password) {
mSignInGroup.setVisibility(View.GONE);
mStatusGroup.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
*/

package io.afero.aferolab.resetPassword;

import io.afero.aferolab.BuildConfig;
import io.afero.sdk.client.afero.AferoClient;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;

class RequestCodeController {

private RequestCodeView view;
private AferoClient aferoClient;

RequestCodeController(RequestCodeView requestCodeView, AferoClient aferoClient) {
this.view = requestCodeView;
this.aferoClient = aferoClient;
}

public void start() {

}

public void stop() {

}

void onClickRequestCode(String email) {
view.showProgress();
aferoClient.sendPasswordRecoveryEmail(email, BuildConfig.APPLICATION_ID, "ANDROID")
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Void>() {
@Override
public void onCompleted() {
view.hideProgress();
gotoPasswordResetView();
}

@Override
public void onError(Throwable e) {
view.hideProgress();
view.showError(e, aferoClient.getStatusCode(e));
}

@Override
public void onNext(Void v) {

}
});
}

void onClickAlreadyHaveCode() {
gotoPasswordResetView();
}

private void gotoPasswordResetView() {
ResetPasswordView.create(view.getRootView()).start(aferoClient);
view.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
*/

package io.afero.aferolab.resetPassword;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.afero.aferolab.R;
import io.afero.aferolab.widget.AferoEditText;
import io.afero.aferolab.widget.ProgressSpinnerView;
import io.afero.aferolab.widget.ScreenView;
import io.afero.sdk.client.afero.AferoClient;

public class RequestCodeView extends ScreenView {

@BindView(R.id.edit_text_email)
AferoEditText emailEditText;

@BindView(R.id.progress_request_code)
ProgressSpinnerView progressView;

private RequestCodeController mController;


public RequestCodeView(@NonNull Context context) {
super(context);
}

public RequestCodeView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public RequestCodeView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public static RequestCodeView create(@NonNull View contextView) {
return inflateView(R.layout.view_request_code, contextView);
}

@Override
public void onFinishInflate() {
super.onFinishInflate();
ButterKnife.bind(this);
}

public RequestCodeView start(AferoClient aferoClient) {
pushOnBackStack();

mController = new RequestCodeController(this, aferoClient);
mController.start();

emailEditText.showKeyboard();

return this;
}

@Override
public void stop() {
mController.stop();

super.stop();
}

@Override
public boolean onBackPressed() {
return false;
}

@OnClick(R.id.button_request_code)
void onClickRequestCode() {
emailEditText.hideKeyboard();
mController.onClickRequestCode(emailEditText.getText().toString());
}

@OnClick(R.id.button_already_have_code)
void onClickAlreadyHaveCode() {
emailEditText.hideKeyboard();
mController.onClickAlreadyHaveCode();
}

void showProgress() {
progressView.show();
}

void hideProgress() {
progressView.hide();
}
}
Loading

0 comments on commit 4f63850

Please sign in to comment.