Skip to content

Commit 4f63850

Browse files
author
Tony Myles
authored
Merge pull request #91 from aferodeveloper/topic/reset-password
Fix for AferoClient.resetPasswordWithCode 400 error
2 parents 4f59c25 + ae8f9eb commit 4f63850

File tree

17 files changed

+560
-37
lines changed

17 files changed

+560
-37
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
Change Log
22
==========
33

4+
Version 1.4.5 *(2019-09-20)*
5+
----------------------------
6+
* Fix: `AferoClient.resetPasswordWithCode` now actually works rather than returning a 400 error.
7+
* New: AferoLab sample app now has a basic "Forgot Password" flow.
8+
49
Version 1.4.4 *(2019-09-09)*
510
----------------------------
6-
* Fixed: Added logic to `ConclaveDeviceEventSource.stop()` to clear the access credentials and account id.
11+
* Fix: Added logic to `ConclaveDeviceEventSource.stop()` to clear the access credentials and account id.
712
* Removed: `ConclaveDeviceEventSource.setAccountId()` since this function is defunct.
813

914
Version 1.4.3 *(2019-08-22)*

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
author: Tony Myles
33
title: "AferoJavaSDK"
4-
date: 2019-Sept-9
5-
status: 1.4.4
4+
date: 2019-Sept-20
5+
status: 1.4.5
66
---
77

88
# AferoJavaSDK
@@ -32,23 +32,23 @@ The SDK is composed of four separate modules.
3232

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

3838
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.
3939

4040
```Gradle
41-
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.4.4'
41+
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.4.5'
4242
```
4343

4444
The `afero-sdk-android` module is required for Android development.
4545
```Gradle
46-
implementation 'io.afero.sdk:afero-sdk-android:1.4.4'
46+
implementation 'io.afero.sdk:afero-sdk-android:1.4.5'
4747
```
4848

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

afero-sdk-client-retrofit2/src/main/java/io/afero/sdk/client/retrofit2/AferoClientRetrofit2.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.afero.sdk.client.afero.models.InvitationDetails;
3030
import io.afero.sdk.client.afero.models.Location;
3131
import io.afero.sdk.client.afero.models.PostActionBody;
32+
import io.afero.sdk.client.afero.models.ResetPasswordBody;
3233
import io.afero.sdk.client.afero.models.RuleExecuteBody;
3334
import io.afero.sdk.client.afero.models.ViewRequest;
3435
import io.afero.sdk.client.afero.models.ViewResponse;
@@ -423,7 +424,7 @@ public Observable<Void> resetPassword(String email) {
423424
*/
424425
@Override
425426
public Observable<Void> resetPasswordWithCode(String resetCode, String newPassword) {
426-
return mAferoService.resetPasswordWithCode(resetCode, newPassword);
427+
return mAferoService.resetPasswordWithCode(resetCode, new ResetPasswordBody(newPassword));
427428
}
428429

429430
/**

afero-sdk-client-retrofit2/src/main/java/io/afero/sdk/client/retrofit2/api/AferoClientAPI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.afero.sdk.client.afero.models.InvitationDetails;
2121
import io.afero.sdk.client.afero.models.Location;
2222
import io.afero.sdk.client.afero.models.PostActionBody;
23+
import io.afero.sdk.client.afero.models.ResetPasswordBody;
2324
import io.afero.sdk.client.afero.models.RuleExecuteBody;
2425
import io.afero.sdk.client.afero.models.ViewRequest;
2526
import io.afero.sdk.client.afero.models.ViewResponse;
@@ -88,7 +89,7 @@ Observable<Void> resetPassword(
8889
@POST(V1 + "shortvalues/{resetCode}/passwordReset")
8990
Observable<Void> resetPasswordWithCode(
9091
@Path("resetCode") String resetCode,
91-
@Body String newPassword
92+
@Body ResetPasswordBody body
9293
);
9394

9495
@POST(V1 + "credentials/{email}/passwordReset")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
3+
*/
4+
5+
package io.afero.sdk.client.afero.models;
6+
7+
8+
public class ResetPasswordBody {
9+
public String password;
10+
11+
public ResetPasswordBody(String pw) {
12+
password = pw;
13+
}
14+
}

afero-sdk-softhub/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ apply plugin: 'com.android.library'
77
repositories {
88
maven {
99
url "https://afero.jfrog.io/afero/hubby-android"
10-
credentials {
11-
username = project.aferoArtifactoryUserName
12-
password = project.aferoArtifactoryPassword
13-
}
1410
}
1511
}
1612

samples/afero-lab/app/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
apply plugin: 'com.android.application'
66

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

1010
repositories {
1111
maven {
1212
url "https://afero.jfrog.io/afero/${sdkRepoKey}"
1313
artifactUrls "https://afero.jfrog.io/afero/hubby-android"
14+
credentials {
15+
username = project.aferoArtifactoryUserName
16+
password = project.aferoArtifactoryPassword
17+
}
1418
}
1519
}
1620
configurations.all {
@@ -95,4 +99,5 @@ dependencies {
9599

96100
testImplementation 'junit:junit:4.12'
97101
implementation 'com.android.support:cardview-v7:27.1.1'
102+
implementation 'com.android.support:design:27.1.1'
98103
}

samples/afero-lab/app/src/main/java/io/afero/aferolab/MainActivity.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014-2017 Afero, Inc. All rights reserved.
2+
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
33
*/
44

55
package io.afero.aferolab;
@@ -26,6 +26,7 @@
2626

2727
import butterknife.BindView;
2828
import butterknife.ButterKnife;
29+
import butterknife.OnClick;
2930
import butterknife.OnEditorAction;
3031
import io.afero.aferolab.addDevice.AddDeviceView;
3132
import io.afero.aferolab.addDevice.AddSetupModeDeviceView;
@@ -35,6 +36,7 @@
3536
import io.afero.aferolab.helper.BackStack;
3637
import io.afero.aferolab.helper.PermissionsHelper;
3738
import io.afero.aferolab.helper.PrefsHelper;
39+
import io.afero.aferolab.resetPassword.RequestCodeView;
3840
import io.afero.aferolab.widget.AferoEditText;
3941
import io.afero.aferolab.widget.ScreenView;
4042
import io.afero.sdk.android.clock.AndroidClock;
@@ -369,14 +371,25 @@ public void onNext(AddSetupModeDeviceView addDeviceView) {}
369371
public boolean onEditorActionSignIn(TextView textView, int actionId, KeyEvent event) {
370372
if (AferoEditText.isDone(actionId, event)) {
371373
if (textView.getId() == R.id.edit_text_password) {
372-
startSignIn(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
373-
mPasswordEditText.hideKeyboard();
374+
onClickSignIn();
374375
}
375376
}
376377

377378
return true;
378379
}
379380

381+
@OnClick(R.id.button_sign_in)
382+
public void onClickSignIn() {
383+
mPasswordEditText.hideKeyboard();
384+
startSignIn(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
385+
}
386+
387+
@OnClick(R.id.button_forgot_password)
388+
public void onClickForgotPassword() {
389+
mPasswordEditText.hideKeyboard();
390+
RequestCodeView.create(mRootView).start(mAferoClient);
391+
}
392+
380393
private void startSignIn(String email, String password) {
381394
mSignInGroup.setVisibility(View.GONE);
382395
mStatusGroup.setVisibility(View.VISIBLE);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
3+
*/
4+
5+
package io.afero.aferolab.resetPassword;
6+
7+
import io.afero.aferolab.BuildConfig;
8+
import io.afero.sdk.client.afero.AferoClient;
9+
import rx.Observer;
10+
import rx.android.schedulers.AndroidSchedulers;
11+
12+
class RequestCodeController {
13+
14+
private RequestCodeView view;
15+
private AferoClient aferoClient;
16+
17+
RequestCodeController(RequestCodeView requestCodeView, AferoClient aferoClient) {
18+
this.view = requestCodeView;
19+
this.aferoClient = aferoClient;
20+
}
21+
22+
public void start() {
23+
24+
}
25+
26+
public void stop() {
27+
28+
}
29+
30+
void onClickRequestCode(String email) {
31+
view.showProgress();
32+
aferoClient.sendPasswordRecoveryEmail(email, BuildConfig.APPLICATION_ID, "ANDROID")
33+
.observeOn(AndroidSchedulers.mainThread())
34+
.subscribe(new Observer<Void>() {
35+
@Override
36+
public void onCompleted() {
37+
view.hideProgress();
38+
gotoPasswordResetView();
39+
}
40+
41+
@Override
42+
public void onError(Throwable e) {
43+
view.hideProgress();
44+
view.showError(e, aferoClient.getStatusCode(e));
45+
}
46+
47+
@Override
48+
public void onNext(Void v) {
49+
50+
}
51+
});
52+
}
53+
54+
void onClickAlreadyHaveCode() {
55+
gotoPasswordResetView();
56+
}
57+
58+
private void gotoPasswordResetView() {
59+
ResetPasswordView.create(view.getRootView()).start(aferoClient);
60+
view.stop();
61+
}
62+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
3+
*/
4+
5+
package io.afero.aferolab.resetPassword;
6+
7+
import android.content.Context;
8+
import android.support.annotation.AttrRes;
9+
import android.support.annotation.NonNull;
10+
import android.support.annotation.Nullable;
11+
import android.util.AttributeSet;
12+
import android.view.View;
13+
14+
import butterknife.BindView;
15+
import butterknife.ButterKnife;
16+
import butterknife.OnClick;
17+
import io.afero.aferolab.R;
18+
import io.afero.aferolab.widget.AferoEditText;
19+
import io.afero.aferolab.widget.ProgressSpinnerView;
20+
import io.afero.aferolab.widget.ScreenView;
21+
import io.afero.sdk.client.afero.AferoClient;
22+
23+
public class RequestCodeView extends ScreenView {
24+
25+
@BindView(R.id.edit_text_email)
26+
AferoEditText emailEditText;
27+
28+
@BindView(R.id.progress_request_code)
29+
ProgressSpinnerView progressView;
30+
31+
private RequestCodeController mController;
32+
33+
34+
public RequestCodeView(@NonNull Context context) {
35+
super(context);
36+
}
37+
38+
public RequestCodeView(@NonNull Context context, @Nullable AttributeSet attrs) {
39+
super(context, attrs);
40+
}
41+
42+
public RequestCodeView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
43+
super(context, attrs, defStyleAttr);
44+
}
45+
46+
public static RequestCodeView create(@NonNull View contextView) {
47+
return inflateView(R.layout.view_request_code, contextView);
48+
}
49+
50+
@Override
51+
public void onFinishInflate() {
52+
super.onFinishInflate();
53+
ButterKnife.bind(this);
54+
}
55+
56+
public RequestCodeView start(AferoClient aferoClient) {
57+
pushOnBackStack();
58+
59+
mController = new RequestCodeController(this, aferoClient);
60+
mController.start();
61+
62+
emailEditText.showKeyboard();
63+
64+
return this;
65+
}
66+
67+
@Override
68+
public void stop() {
69+
mController.stop();
70+
71+
super.stop();
72+
}
73+
74+
@Override
75+
public boolean onBackPressed() {
76+
return false;
77+
}
78+
79+
@OnClick(R.id.button_request_code)
80+
void onClickRequestCode() {
81+
emailEditText.hideKeyboard();
82+
mController.onClickRequestCode(emailEditText.getText().toString());
83+
}
84+
85+
@OnClick(R.id.button_already_have_code)
86+
void onClickAlreadyHaveCode() {
87+
emailEditText.hideKeyboard();
88+
mController.onClickAlreadyHaveCode();
89+
}
90+
91+
void showProgress() {
92+
progressView.show();
93+
}
94+
95+
void hideProgress() {
96+
progressView.hide();
97+
}
98+
}

0 commit comments

Comments
 (0)