Bug 958341 - Present "motivating service" to /account/create calls. r=rnewman

========

f9d27162dc
Author: Nick Alexander <nalexander@mozilla.com>
Date:   Tue Aug 26 17:47:33 2014 -0700

    Bug 958341 - Test and review comments.

========

7b82898363
Author: Nick Alexander <nalexander@mozilla.com>
Date:   Mon Aug 18 14:53:54 2014 -0700

    Bug 958341 - Present "motivating service" to /account/create calls.

    This is used for metrics and for personalizing the welcome emails.
    Since no email gets sent for /account/login, it is not needed there.
This commit is contained in:
Nick Alexander 2014-08-26 17:49:44 -07:00
Родитель cc72fb871c
Коммит 670e5edee5
1 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -4,7 +4,10 @@
package org.mozilla.gecko.background.fxa; package org.mozilla.gecko.background.fxa;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -94,13 +97,35 @@ public class FxAccountClient20 extends FxAccountClient10 implements FxAccountCli
post(resource, body, delegate); post(resource, body, delegate);
} }
public void createAccount(final byte[] emailUTF8, final byte[] quickStretchedPW, final boolean getKeys, final boolean preVerified, /**
* Create account/create URI, encoding query parameters carefully.
* <p>
* This is equivalent to <code>android.net.Uri.Builder</code>, which is not
* present in our JUnit 4 tests.
*/
protected URI getCreateAccountURI(final boolean getKeys, final String service) throws UnsupportedEncodingException, URISyntaxException {
if (service == null) {
throw new IllegalArgumentException("service must not be null");
}
final StringBuilder sb = new StringBuilder(serverURI); // serverURI always has a trailing slash.
sb.append("account/create?service=");
// Be very careful that query parameters are encoded correctly!
sb.append(URLEncoder.encode(service, "UTF-8"));
if (getKeys) {
sb.append("&keys=true");
}
return new URI(sb.toString());
}
public void createAccount(final byte[] emailUTF8, final byte[] quickStretchedPW,
final boolean getKeys,
final boolean preVerified,
final String service,
final RequestDelegate<LoginResponse> delegate) { final RequestDelegate<LoginResponse> delegate) {
BaseResource resource; final BaseResource resource;
JSONObject body; final JSONObject body;
final String path = getKeys ? "account/create?keys=true" : "account/create";
try { try {
resource = new BaseResource(new URI(serverURI + path)); resource = new BaseResource(getCreateAccountURI(getKeys, service));
body = new FxAccount20CreateDelegate(emailUTF8, quickStretchedPW, preVerified).getCreateBody(); body = new FxAccount20CreateDelegate(emailUTF8, quickStretchedPW, preVerified).getCreateBody();
} catch (Exception e) { } catch (Exception e) {
invokeHandleError(delegate, e); invokeHandleError(delegate, e);
@ -144,7 +169,7 @@ public class FxAccountClient20 extends FxAccountClient10 implements FxAccountCli
public void createAccountAndGetKeys(byte[] emailUTF8, PasswordStretcher passwordStretcher, RequestDelegate<LoginResponse> delegate) { public void createAccountAndGetKeys(byte[] emailUTF8, PasswordStretcher passwordStretcher, RequestDelegate<LoginResponse> delegate) {
try { try {
byte[] quickStretchedPW = passwordStretcher.getQuickStretchedPW(emailUTF8); byte[] quickStretchedPW = passwordStretcher.getQuickStretchedPW(emailUTF8);
createAccount(emailUTF8, quickStretchedPW, true, false, delegate); createAccount(emailUTF8, quickStretchedPW, true, false, "sync", delegate);
} catch (Exception e) { } catch (Exception e) {
invokeHandleError(delegate, e); invokeHandleError(delegate, e);
return; return;