Files
palemoon27/services/sync/modules/userapi.js
T
roytam1 b4a9437711 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1199171 part 0 - Add spewInst function for debugging Jit code. r=lth (12cd32209d)
- Bug 1192786 - support an installed printer, for profiling. r=nbp (59fe21c4a5)
- Bug 1199171 part 1 - Assembler::GetCF32Target: Decode instructions as needed. r=h4writer (b120e75c4f)
- Bug 1192786 - add forgotten ifdeffery on CLOSED TREE. r=me (7ccf2e792c)
- Bug 1195263 - ARM: Instruction::extractCond asserts that the instruction has a condition flag. r=h4writer (fe30c9a6ae)
- Bug 1207449: Conservatively mark MFilterTypeSet with phis as not float32-compatible; r=h4writer (9062bae786)
- revert 1130679 that was never commited (a9c6fcc984)
- Bug 1201793 - correct scratch register scope r=nbp CLOSED TREE (6df1d46059)
- Bug 1202643 - bailout from udiv on nonzero remainder. r=nbp (b001fc7c42)
- Bug 1206650 - Part 1/2 - Clean up load8ZeroExtend(). r=nbp (288a451461)
- Bug 1206650 - Part 2/2 - Use the dest register for scratch in alu_dbl(). r=nbp (4e601cff7f)
- Bug 1201793 - ScratchRegisterScope: ma_alu expect to have scratch register owned by the caller. r=sstangl (6783084545)
- pointer style (04d2b491cc)
- Bug 1202757 - disassemble more instructions. r=sstangl (39e29fbc98)
- Bug 1211832 - Disable functions that can easily cause artificial OOMs. r=jonco (3264e2dcb6)
- Bug 1188390 - Fail when Sprinter in disassemble ooms. r=h4writer (f59e3b00ca)
- Bug 1191635 - Fix stack limit for evalInWorker runtime. r=bhackett (b4b8f37dc1)
- Bug 1209873 - IonMonkey: MIPS: Add AssemblerMIPSShared::as_sync. r=arai (80dbd653b7)
- Bug 1212469 - Fix some OOM handling issues shown up by the previous patch r=jandem (ca7e25d243)
- Bug 1215058 - Fix various OOM handling issues related to off-thread compilation r=jandem (6d95767f75)
- Bug 1207827 - Copy pool data into buffer immediately. r=nbp (d3fcd69e1e)
- Bug 1207827 - Stop perforating AssemblerBuffers. r=nbp (8ac7947355)
- Bug 1207827 - Use a Vector for poolInfo_. r=nbp (d97f814916)
- Bug 1207827 - Switch jit::Pool to a LifoAllocPolicy. r=nbp (caf547349e)
- Bug 1207827 - Eliminate poolSizeBefore(). r=nbp (adad1dfa68)
- Bug 1181612: Hoist codeLabels_ and associated common functions into Assembler-shared; r=luke (5086762e53)
- Bug 1207827 - Remove ARM temporary offset buffers. r=nbp (7bc80ab795)
- Bug 1207827 - Delete Assembler::actualOffset() and transitive closure. r=nbp (34141fde56)
- Bug 1213146 - IonMonkey: MIPS: Remove AssemblerMIPSShared::asAsm. r=arai (8d71e648c9)
- const-var (f860ce4da7)
- Bug 944164 - set the shell variable scriptPath to communicate the currently running script to the debugger, r=jorendorff (5ca9508912)
- align to firefox (f895d43a07)
- Bug 1213146 - IonMonkey: MIPS: Move Assembler::PatchDataWithValueCheck to architecture specific. r=lth (c8a7b478f6)
- Bug 944164 - make the shell actually quit when you call quit(), r=jorendorff (8e737a7450)
2022-10-06 11:43:07 +08:00

225 lines
6.0 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
this.EXPORTED_SYMBOLS = [
"UserAPI10Client",
];
var {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/rest.js");
Cu.import("resource://services-common/utils.js");
Cu.import("resource://services-sync/identity.js");
Cu.import("resource://services-sync/util.js");
/**
* A generic client for the user API 1.0 service.
*
* http://docs.services.mozilla.com/reg/apis.html
*
* Instances are constructed with the base URI of the service.
*/
this.UserAPI10Client = function UserAPI10Client(baseURI) {
this._log = Log.repository.getLogger("Sync.UserAPI");
this._log.level = Log.Level[Svc.Prefs.get("log.logger.userapi")];
this.baseURI = baseURI;
}
UserAPI10Client.prototype = {
USER_CREATE_ERROR_CODES: {
2: "Incorrect or missing captcha.",
4: "User exists.",
6: "JSON parse failure.",
7: "Missing password field.",
9: "Requested password not strong enough.",
12: "No email address on file.",
},
/**
* Determine whether a specified username exists.
*
* Callback receives the following arguments:
*
* (Error) Describes error that occurred or null if request was
* successful.
* (boolean) True if user exists. False if not. null if there was an error.
*/
usernameExists: function usernameExists(username, cb) {
if (typeof(cb) != "function") {
throw new Error("cb must be a function.");
}
let url = this.baseURI + username;
let request = new RESTRequest(url);
request.get(this._onUsername.bind(this, cb, request));
},
/**
* Obtain the Weave (Sync) node for a specified user.
*
* The callback receives the following arguments:
*
* (Error) Describes error that occurred or null if request was successful.
* (string) Username request is for.
* (string) URL of user's node. If null and there is no error, no node could
* be assigned at the time of the request.
*/
getWeaveNode: function getWeaveNode(username, password, cb) {
if (typeof(cb) != "function") {
throw new Error("cb must be a function.");
}
let request = this._getRequest(username, "/node/weave", password);
request.get(this._onWeaveNode.bind(this, cb, request));
},
/**
* Change a password for the specified user.
*
* @param username
* (string) The username whose password to change.
* @param oldPassword
* (string) The old, current password.
* @param newPassword
* (string) The new password to switch to.
*/
changePassword: function changePassword(username, oldPassword, newPassword, cb) {
let request = this._getRequest(username, "/password", oldPassword);
request.onComplete = this._onChangePassword.bind(this, cb, request);
request.post(CommonUtils.encodeUTF8(newPassword));
},
createAccount: function createAccount(email, password, captchaChallenge,
captchaResponse, cb) {
let username = IdentityManager.prototype.usernameFromAccount(email);
let body = JSON.stringify({
"email": email,
"password": Utils.encodeUTF8(password),
"captcha-challenge": captchaChallenge,
"captcha-response": captchaResponse
});
let url = this.baseURI + username;
let request = new RESTRequest(url);
if (this.adminSecret) {
request.setHeader("X-Weave-Secret", this.adminSecret);
}
request.onComplete = this._onCreateAccount.bind(this, cb, request);
request.put(body);
},
_getRequest: function _getRequest(username, path, password=null) {
let url = this.baseURI + username + path;
let request = new RESTRequest(url);
if (password) {
let up = username + ":" + password;
request.setHeader("authorization", "Basic " + btoa(up));
}
return request;
},
_onUsername: function _onUsername(cb, request, error) {
if (error) {
cb(error, null);
return;
}
let body = request.response.body;
if (body == "0") {
cb(null, false);
return;
} else if (body == "1") {
cb(null, true);
return;
} else {
cb(new Error("Unknown response from server: " + body), null);
return;
}
},
_onWeaveNode: function _onWeaveNode(cb, request, error) {
if (error) {
cb.network = true;
cb(error, null);
return;
}
let response = request.response;
if (response.status == 200) {
let body = response.body;
if (body == "null") {
cb(null, null);
return;
}
cb(null, body);
return;
}
error = new Error("Sync node retrieval failed.");
switch (response.status) {
case 400:
error.denied = true;
break;
case 404:
error.notFound = true;
break;
default:
error.message = "Unexpected response code: " + response.status;
}
cb(error, null);
return;
},
_onChangePassword: function _onChangePassword(cb, request, error) {
this._log.info("Password change response received: " +
request.response.status);
if (error) {
cb(error);
return;
}
let response = request.response;
if (response.status != 200) {
cb(new Error("Password changed failed: " + response.body));
return;
}
cb(null);
},
_onCreateAccount: function _onCreateAccount(cb, request, error) {
let response = request.response;
this._log.info("Create account response: " + response.status + " " +
response.body);
if (error) {
cb(new Error("HTTP transport error."), null);
return;
}
if (response.status == 200) {
cb(null, response.body);
return;
}
error = new Error("Could not create user.");
error.body = response.body;
cb(error, null);
return;
},
};
Object.freeze(UserAPI10Client.prototype);