Skip to content

Commit 3940def

Browse files
author
Tony Myles
committed
Fixed AferoClientAPI.resetPasswordWithCode by adding a ResetPasswordBody class that will be serialized into the proper json the service is expecting.
AferoLab: Added a basic Forgot Password/Request Code/Reset Password UI flow to the sample app. ## JIRA [ACE-274: HTTP 400 on Android resetPasswordWithCode](https://kibanlabs.atlassian.net/browse/ACE-274)
1 parent 4f59c25 commit 3940def

15 files changed

Lines changed: 548 additions & 30 deletions

File tree

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+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2014-2019 Afero, Inc. All rights reserved.
3+
*/
4+
5+
package io.afero.aferolab.resetPassword;
6+
7+
import io.afero.sdk.client.afero.AferoClient;
8+
import rx.Observer;
9+
import rx.android.schedulers.AndroidSchedulers;
10+
11+
class ResetPasswordController {
12+
13+
private ResetPasswordView view;
14+
private AferoClient aferoClient;
15+
16+
ResetPasswordController(ResetPasswordView resetPasswordView, AferoClient aferoClient) {
17+
this.view = resetPasswordView;
18+
this.aferoClient = aferoClient;
19+
}
20+
21+
public void start() {
22+
23+
}
24+
25+
public void stop() {
26+
27+
}
28+
29+
void onClickResetPassword(String code, String password) {
30+
view.showProgress();
31+
aferoClient.resetPasswordWithCode(code, password)
32+
.observeOn(AndroidSchedulers.mainThread())
33+
.subscribe(new Observer<Void>() {
34+
@Override
35+
public void onCompleted() {
36+
view.stop();
37+
}
38+
39+
@Override
40+
public void onError(Throwable e) {
41+
view.hideProgress();
42+
view.showError(e, aferoClient.getStatusCode(e));
43+
}
44+
45+
@Override
46+
public void onNext(Void aVoid) {
47+
48+
}
49+
});
50+
}
51+
}

0 commit comments

Comments
 (0)