How to use registrationId method in wpt

Best JavaScript code snippet using wpt

registration-manager.js

Source:registration-manager.js Github

copy

Full Screen

1"use strict";2/**3 * Manages the business logic for registration of a new account.4 *5 * The process the client follows:6 *7 * 1. Collect data for createRequest, then send it to this module's "register"8 * function. This generates the registration record and sends the client the9 * necessary information so they can generate a password hash and MFA codes.10 * This registration record will only exist for a very limited amount of time.11 *12 * 2. The client generates the necessary information to secure the account and13 * sends it to the "secure" function. This simply will send a URL via an email14 * message. The registration record could still expire soon. The MFA codes15 * are validated at this point. Failure to validate will not send an email nor16 * will it accept the password hash.17 *18 * 3. The user retrieves the email, clicks the link and the registration is19 * converted into an account. The confirmation code is sent to the20 * "confirmEmail" function. A new account is generated, whose ID is unreleated21 * to the registration ID.22 */23/**24 * Creation of a registration record.25 *26 * @typedef {Object} registrationManager~registerRequest27 * @property {string} email28 * @see {@link ../../schema/registration/register-request.json}29 */30/**31 * Necessary information for securing the account. This is returned32 * in order to perform step 2 of registration. It is a filtered version33 * of the registration record.34 *35 * @typedef {Object} registrationManager~recordResponse36 * @property {string} id37 * @property {Object} record38 * @property {Object} record.mfa39 * @property {Object} record.mfa.totp40 * @property {string} record.mfa.totp.key Base-32 encoded secret41 * @property {accountManager~passwordHashConfig} record.passwordHash42 */43/**44 * What the user sends us to secure the registration. When this is sent in,45 * the registration record is deleted and the account record is created.46 *47 * @typedef {Object} registrationManager~secureRequest48 * @property {string} passwordHash49 * @property {Object} mfa50 * @property {Object} mfa.totp51 * @property {string} mfa.totp.current52 * @property {string} mfa.totp.previous53 * @see {@link ../../schema/registration/secure-request.json}54 */55/**56 * The returned information from confirming the email address. This is57 * everything needed to hash the password and generate MFA codes.58 *59 * @typedef {Object} registrationManager~confirmEmailResponse60 * @property {accountManager~passwordHashConfig} passwordHash61 * @property {Object} mfa62 * @property {Object} mfa.totp63 * @property {string} mfa.totp.key Base-32 encoded secret64 */65/**66 * A registration record that's stored in OpenToken. It's different from67 * registrationManager~recordResponse because this one is unfiltered.68 *69 * @typedef {Object} registrationManager~record70 * @property {string} confirmationCode71 * @property {string} email Email address for account verification.72 * @property {string} passwordHash73 * @property {accountManager~passwordHashConfig} passwordHashConfig74 * @property {Object} mfa75 * @property {Object} mfa.totp76 * @property {boolean} mfa.totp.confirmed If true, this was confirmed77 * @property {string} mfa.totp.key Buffer, raw binary TOTP key78 */79module.exports = (accountManager, config, encoding, promise, random, storageServiceFactory, template, totp) => {80 var confirmationCodeLength, idLength, storageService;81 /**82 * Returns the information necessary for securing the account (step 2 of83 * registration).84 *85 * @param {string} registrationId86 * @param {Object} record87 * @return {registrationManager~recordResponse}88 */89 function recordResponse(registrationId, record) {90 var response;91 response = {92 id: registrationId,93 record: {94 passwordHashConfig: record.passwordHashConfig95 }96 };97 if (!record.mfa.totp.confirmed) {98 response.record.mfa = {99 totp: {100 keyBase32: encoding.encode(record.mfa.totp.key, "base32-uri"),101 keyHex: encoding.encode(record.mfa.totp.key, "hex"),102 keyUri: totp.generateUrl(record.mfa.totp.key, record.email)103 }104 };105 }106 return response;107 }108 /**109 * Confirm the email address. It compares the confirmation code. If it110 * matches, the account is created, otherwise an error is thrown.111 *112 * @param {string} registrationId113 * @param {string} confirmationCode114 * @return {Promise.<string>} accountId115 */116 function confirmEmailAsync(registrationId, confirmationCode) {117 return storageService.getAsync(registrationId).then((record) => {118 if (!record.passwordHash || !record.mfa.totp.confirmed) {119 throw new Error("Registration not secured");120 }121 if (record.confirmationCode !== confirmationCode) {122 throw new Error("Confirmation code does not match");123 }124 // Convert the record125 return accountManager.createAsync({126 email: record.email,127 mfa: {128 totp: record.mfa.totp129 },130 passwordHash: record.passwordHash,131 passwordHashConfig: record.passwordHashConfig132 });133 }).then((accountId) => {134 return storageService.deleteAsync(registrationId).then(() => {135 return accountId;136 });137 });138 }139 /**140 * Return a Buffer that's the contents of a QR Code image in PNG format.141 *142 * @param {string} registrationId143 * @return {Promise.<Buffer>}144 */145 function qrCodeImageAsync(registrationId) {146 return storageService.getAsync(registrationId).then((record) => {147 if (record.mfa.totp.confirmed) {148 throw new Error("Already confirmed");149 }150 return totp.generateQrCodeAsync(record.mfa.totp.key, record.email);151 });152 }153 /**154 * Begin a registration.155 *156 * @param {registrationManager~registerRequest} request157 * @return {Promise.<registrationManager~recordResponse>} registration ID and info158 */159 function registerAsync(request) {160 return promise.props({161 confirmationCode: random.idAsync(confirmationCodeLength),162 passwordHashConfig: accountManager.passwordHashConfigAsync(),163 registrationId: random.idAsync(idLength),164 totpKey: totp.generateSecretAsync()165 }).then((bits) => {166 // Build a lot of the registration record167 // @see {registrationManager~record}168 var record;169 if (!request.email) {170 throw new Error("Email is required");171 }172 record = {173 confirmationCode: bits.confirmationCode,174 email: request.email,175 mfa: {176 totp: {177 confirmed: false,178 key: bits.totpKey179 }180 },181 passwordHashConfig: bits.passwordHashConfig182 };183 return storageService.putAsync(bits.registrationId, record).then(() => {184 return recordResponse(bits.registrationId, record);185 });186 });187 }188 /**189 * Secure the registration with MFA and password.190 *191 * Note: the request object must have some properties defined otherwise192 * this code will fail.193 *194 * @param {string} registrationId195 * @param {secureRequest} request196 * @param {restify} server197 * @return {Promise.<*>}198 */199 function secureAsync(registrationId, request, server) {200 return storageService.getAsync(registrationId).then((record) => {201 if (!totp.verifyCurrentAndPrevious(record.mfa.totp.key, request.mfa.totp.current, request.mfa.totp.previous)) {202 throw new Error("TOTP validation failed");203 }204 record.passwordHash = request.passwordHash;205 record.mfa.totp.confirmed = true;206 return storageService.putAsync(registrationId, record).then(() => {207 return template.sendEmailAsync(record.email, "registration", {208 // URL is not fully qualified - template needs more info209 // https://github.com/opentoken-io/opentoken/issues/96210 confirmUrl: server.router.render("registration-confirm", {211 code: record.confirmationCode,212 id: registrationId213 })214 });215 }).then(() => {216 return recordResponse(registrationId, record);217 });218 });219 }220 /**221 * Retrieve the secure info data222 *223 * @param {string} registrationId224 * @return {Promise.<accountManager~recordResponse>}225 */226 function getRecordAsync(registrationId) {227 return storageService.getAsync(registrationId).then((record) => {228 return recordResponse(registrationId, record);229 });230 }231 confirmationCodeLength = config.registration.confirmationCodeLength;232 idLength = config.registration.idLength;233 storageService = storageServiceFactory(config.registration.idHash, config.registration.lifetime, config.registration.storagePrefix);234 return {235 confirmEmailAsync,236 getRecordAsync,237 qrCodeImageAsync,238 registerAsync,239 secureAsync240 };...

Full Screen

Full Screen

wnsservice-registrations-tests.js

Source:wnsservice-registrations-tests.js Github

copy

Full Screen

1// 2// Copyright (c) Microsoft and contributors. All rights reserved.3// 4// Licensed under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7// http://www.apache.org/licenses/LICENSE-2.08// 9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// 13// See the License for the specific language governing permissions and14// limitations under the License.15// 16var _ = require('underscore');17var should = require('should');18var sinon = require('sinon');19// Test includes20var testutil = require('../../util/util');21var notificationhubstestutil = require('../../framework/notificationhubs-test-utils');22var azure = testutil.libRequire('azure');23var hubNames = [];24var hubNamePrefix = 'xplathubnxt';25var testPrefix = 'wnsservice-registrations-tests';26describe('WNS notifications registrations', function () {27 var service;28 var suiteUtil;29 var sandbox;30 before(function (done) {31 sandbox = sinon.sandbox.create();32 service = azure.createServiceBusService()33 .withFilter(new azure.ExponentialRetryPolicyFilter());34 suiteUtil = notificationhubstestutil.createNotificationHubsTestUtils(service, testPrefix);35 suiteUtil.setupSuite(done);36 });37 after(function (done) {38 sandbox.restore();39 suiteUtil.teardownSuite(done);40 });41 beforeEach(function (done) {42 suiteUtil.setupTest(function () {43 service.listNotificationHubs(function (err, hubs, rsp) {44 var xplatHubs = hubs.filter(function (hub) {45 return hub.NotificationHubName.substr(0, hubNamePrefix.length) === hubNamePrefix;46 });47 _.each(xplatHubs, function (hub) {48 service.deleteNotificationHub(hub.NotificationHubName, function () { });49 });50 done();51 });52 });53 });54 afterEach(function (done) {55 // Schedule deleting notification hubs56 _.each(hubNames, function (notificationHub) {57 service.deleteNotificationHub(notificationHub, function () {});58 });59 suiteUtil.baseTeardownTest(done);60 });61 describe('registrations', function () {62 var hubName;63 var notificationHubService;64 beforeEach(function (done) {65 hubName = testutil.generateId(hubNamePrefix, hubNames, suiteUtil.isMocked);66 notificationHubService = azure.createNotificationHubService(hubName);67 suiteUtil.setupService(notificationHubService);68 service.createNotificationHub(hubName, done);69 });70 describe('native', function () {71 describe('create', function () {72 var registrationId;73 afterEach(function (done) {74 notificationHubService.deleteRegistration(registrationId, done);75 });76 it('should work', function (done) {77 notificationHubService.wns.createNativeRegistration('http://db3.notify.windows.com/fake/superfake', null, function (error, registration) {78 should.not.exist(error);79 registrationId = registration.RegistrationId;80 done();81 });82 });83 });84 describe('delete', function () {85 var registrationId;86 beforeEach(function (done) {87 notificationHubService.wns.createNativeRegistration('http://db3.notify.windows.com/fake/superfake', null, function (err, registration) {88 registrationId = registration.RegistrationId;89 done();90 });91 });92 it('should work', function (done) {93 notificationHubService.deleteRegistration(registrationId, function (err) {94 should.not.exist(err);95 done();96 });97 });98 });99 describe('get', function () {100 var registrationId;101 beforeEach(function (done) {102 notificationHubService.wns.createNativeRegistration('http://db3.notify.windows.com/fake/superfake', null, function (err, registration) {103 registrationId = registration.RegistrationId;104 done();105 });106 });107 it('should work', function (done) {108 notificationHubService.getRegistration(registrationId, function (err, registration) {109 should.not.exist(err);110 should.exist(registration);111 registration['ExpirationTime'].should.not.be.null;112 registration['ETag'].should.not.be.null;113 done();114 });115 });116 });117 describe('list', function () {118 beforeEach(function (done) {119 notificationHubService.wns.createNativeRegistration('http://db3.notify.windows.com/fake/superfake', [ 'mytag'], done);120 });121 it('should work without filtering', function (done) {122 notificationHubService.listRegistrations(function (err, list) {123 should.not.exist(err);124 should.exist(list);125 list.length.should.equal(1);126 done();127 });128 });129 it('should work with tag filtering with the wrong tag', function (done) {130 notificationHubService.listRegistrationsByTag('tag', { top: 10, skip: 0 }, function (err, list) {131 should.not.exist(err);132 should.exist(list);133 list.length.should.equal(0);134 done();135 });136 });137 it('should work with tag filtering with the right tag', function (done) {138 notificationHubService.listRegistrationsByTag('mytag', { top: 10, skip: 0 }, function (err, list) {139 should.not.exist(err);140 should.exist(list);141 list.length.should.equal(1);142 done();143 });144 });145 it('should work with channel filtering', function (done) {146 notificationHubService.wns.listRegistrationsByChannel('http://db3.notify.windows.com/fake/superfake', { top: 10, skip: 0 }, function (err, list, rsp) {147 should.not.exist(err);148 should.exist(list);149 list.length.should.equal(1);150 done();151 });152 });153 });154 });155 describe('template', function () {156 describe('create tile', function () {157 var registrationId;158 afterEach(function (done) {159 notificationHubService.deleteRegistration(registrationId, done);160 });161 it('should work', function (done) {162 notificationHubService.wns.createTileSquarePeekImageAndText01Registration(163 'http://db3.notify.windows.com/fake/superfake',164 null,165 {166 image1src: '$(myImageProp1)',167 image1alt: '$(myImageProp2)',168 text1: '$(myTextProp1)',169 text2: '$(myTextProp2)',170 text3: '$(myTextProp3)',171 text4: '$(myTextProp4)'172 },173 function (error, registration) {174 should.not.exist(error);175 registrationId = registration.RegistrationId;176 done();177 });178 });179 });180 describe('update tile', function () {181 var registrationId;182 beforeEach(function (done) {183 notificationHubService.wns.createTileSquarePeekImageAndText01Registration(184 'http://db3.notify.windows.com/fake/superfake',185 null,186 {187 image1src: '$(myImageProp1)',188 image1alt: '$(myImageProp2)',189 text1: '$(myTextProp1)',190 text2: '$(myTextProp2)',191 text3: '$(myTextProp3)',192 text4: '$(myTextProp4)'193 },194 function (error, registration) {195 registrationId = registration.RegistrationId;196 done();197 });198 });199 afterEach(function (done) {200 notificationHubService.deleteRegistration(registrationId, done);201 });202 it('should work', function (done) {203 notificationHubService.wns.updateTileSquarePeekImageAndText01Registration(204 registrationId,205 'http://db3.notify.windows.com/fake/superfake',206 null,207 {208 image1src: '$(myImageProp1)',209 image1alt: '$(myImageProp2)',210 text1: '$(myTextProp1)',211 text2: '$(myTextProp2)',212 text3: '$(myTextProp3)',213 text4: '$(myNewTextProp)'214 },215 function (error) {216 should.not.exist(error);217 done();218 });219 });220 });221 });222 });...

Full Screen

Full Screen

mpnsservice-registrations-tests.js

Source:mpnsservice-registrations-tests.js Github

copy

Full Screen

1// 2// Copyright (c) Microsoft and contributors. All rights reserved.3// 4// Licensed under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7// http://www.apache.org/licenses/LICENSE-2.08// 9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// 13// See the License for the specific language governing permissions and14// limitations under the License.15// 16var _ = require('underscore');17var should = require('should');18var sinon = require('sinon');19// Test includes20var testutil = require('../../util/util');21var notificationhubstestutil = require('../../framework/notificationhubs-test-utils');22var azure = testutil.libRequire('azure');23var hubNames = [];24var hubNamePrefix = 'xplathubnxt';25var testPrefix = 'mpnsservice-registrations-tests';26describe('MPNS notifications registrations', function () {27 var service;28 var suiteUtil;29 var sandbox;30 before(function (done) {31 sandbox = sinon.sandbox.create();32 service = azure.createServiceBusService()33 .withFilter(new azure.ExponentialRetryPolicyFilter());34 suiteUtil = notificationhubstestutil.createNotificationHubsTestUtils(service, testPrefix);35 suiteUtil.setupSuite(done);36 });37 after(function (done) {38 sandbox.restore();39 suiteUtil.teardownSuite(done);40 });41 beforeEach(function (done) {42 suiteUtil.setupTest(function () {43 service.listNotificationHubs(function (err, hubs, rsp) {44 var xplatHubs = hubs.filter(function (hub) {45 return hub.NotificationHubName.substr(0, hubNamePrefix.length) === hubNamePrefix;46 });47 _.each(xplatHubs, function (hub) {48 service.deleteNotificationHub(hub.NotificationHubName, function () { });49 });50 done();51 });52 });53 });54 afterEach(function (done) {55 // Schedule deleting notification hubs56 _.each(hubNames, function (notificationHub) {57 service.deleteNotificationHub(notificationHub, function () {});58 });59 suiteUtil.baseTeardownTest(done);60 });61 describe('registrations', function () {62 var hubName;63 var notificationHubService;64 beforeEach(function (done) {65 hubName = testutil.generateId(hubNamePrefix, hubNames, suiteUtil.isMocked);66 notificationHubService = azure.createNotificationHubService(hubName);67 suiteUtil.setupService(notificationHubService);68 service.createNotificationHub(hubName, done);69 });70 describe('native', function () {71 describe('create', function () {72 var registrationId;73 afterEach(function (done) {74 notificationHubService.deleteRegistration(registrationId, done);75 });76 it('should work', function (done) {77 notificationHubService.mpns.createNativeRegistration('http://sn1.notify.live.net/fake/superfake', null, function (error, registration) {78 should.not.exist(error);79 registrationId = registration.RegistrationId;80 done();81 });82 });83 });84 describe('delete', function () {85 var registrationId;86 beforeEach(function (done) {87 notificationHubService.mpns.createNativeRegistration('http://sn1.notify.live.net/fake/superfake', null, function (err, registration) {88 registrationId = registration.RegistrationId;89 done();90 });91 });92 it('should work', function (done) {93 notificationHubService.deleteRegistration(registrationId, function (err) {94 should.not.exist(err);95 done();96 });97 });98 });99 describe('get', function () {100 var registrationId;101 beforeEach(function (done) {102 notificationHubService.mpns.createNativeRegistration('http://sn1.notify.live.net/fake/superfake', null, function (err, registration) {103 registrationId = registration.RegistrationId;104 done();105 });106 });107 it('should work', function (done) {108 notificationHubService.getRegistration(registrationId, function (err, registration) {109 should.not.exist(err);110 should.exist(registration);111 registration['ETag'].should.not.be.null;112 done();113 });114 });115 });116 describe('list', function () {117 beforeEach(function (done) {118 notificationHubService.mpns.createNativeRegistration('http://sn1.notify.live.net/fake/superfake', [ 'mytag'], done);119 });120 it('should work without filtering', function (done) {121 notificationHubService.listRegistrations(function (err, list) {122 should.not.exist(err);123 should.exist(list);124 list.length.should.equal(1);125 done();126 });127 });128 it('should work with tag filtering with the wrong tag', function (done) {129 notificationHubService.listRegistrationsByTag('tag', { top: 10, skip: 0 }, function (err, list) {130 should.not.exist(err);131 should.exist(list);132 list.length.should.equal(0);133 done();134 });135 });136 it('should work with tag filtering with the right tag', function (done) {137 notificationHubService.listRegistrationsByTag('mytag', { top: 10, skip: 0 }, function (err, list) {138 should.not.exist(err);139 should.exist(list);140 list.length.should.equal(1);141 done();142 });143 });144 it('should work with channel filtering', function (done) {145 notificationHubService.mpns.listRegistrationsByChannel('http://sn1.notify.live.net/fake/superfake', { top: 10, skip: 0 }, function (err, list, rsp) {146 should.not.exist(err);147 should.exist(list);148 list.length.should.equal(1);149 done();150 });151 });152 });153 });154 describe('template', function () {155 describe('create toast', function () {156 var registrationId;157 afterEach(function (done) {158 notificationHubService.deleteRegistration(registrationId, done);159 });160 it('should work', function (done) {161 notificationHubService.mpns.createToastRegistration(162 'http://sn1.notify.live.net/fake/superfake',163 null,164 {165 text1: '$(myTextProp1)',166 text2: '$(myTextProp2)'167 },168 function (error, registration) {169 should.not.exist(error);170 registrationId = registration.RegistrationId;171 done();172 });173 });174 });175 describe('update toast', function () {176 var registrationId;177 beforeEach(function (done) {178 notificationHubService.mpns.createToastRegistration(179 'http://sn1.notify.live.net/fake/superfake',180 null,181 {182 text1: '$(myTextProp1)',183 text2: '$(myTextProp2)'184 },185 function (error, registration) {186 registrationId = registration.RegistrationId;187 done();188 });189 });190 afterEach(function (done) {191 notificationHubService.deleteRegistration(registrationId, done);192 });193 it('should work', function (done) {194 notificationHubService.mpns.updateToastRegistration(195 registrationId,196 'http://sn1.notify.live.net/fake/superfake',197 null,198 {199 text1: '$(myTextProp1)',200 text2: '$(myTextProp2)'201 },202 function (error) {203 should.not.exist(error);204 done();205 });206 });207 });208 });209 });...

Full Screen

Full Screen

scout.js

Source:scout.js Github

copy

Full Screen

1import axios from 'axios';2import _ from 'lodash';3import Vue from 'vue';4import * as types from '../mutation-types';5import URLS from '../../urls';6const state = {7 scouts: []8};9const getters = {10 scouts(state) {11 return _.orderBy(state.scouts, 'lastname');12 }13};14const mutations = {15 [types.ADD_REGISTRATION] (state, registration) {16 let scout = _.find(state.scouts, { id: registration.scout_id });17 scout.registrations.push({18 preferences: [],19 purchases: [],20 event_id: registration.event_id,21 details: registration22 });23 },24 [types.ADD_SCOUT] (state, scout) {25 state.scouts.push(scout);26 },27 [types.DELETE_PURCHASE] (state, details) {28 let registrations = _.flatten(_.map(state.scouts, 'registrations'));29 let registration = _.find(registrations, (registration) => {30 return registration.details.id === details.registrationId;31 });32 registration.purchases = _.reject(registration.purchases, (purchase) => {33 return purchase.id === details.purchasableId;34 });35 },36 [types.DELETE_REGISTRATION] (state, details) {37 let scout = _.find(state.scouts, { id: details.scoutId });38 scout.registrations = _.reject(scout.registrations, (registration) => {39 return registration.event_id === details.eventId;40 });41 },42 [types.DELETE_SCOUT] (state, scoutId) {43 state.scouts = _.reject(state.scouts, (existingScout) => {44 return existingScout.id === scoutId;45 });46 },47 [types.SET_PURCHASES] (state, details) {48 let registrations = _.flatten(_.map(state.scouts, 'registrations'));49 let registration = _.find(registrations, (registration) => {50 return registration.details.id === details.registrationId;51 });52 Vue.set(registration, 'purchases', details.purchases);53 },54 [types.SET_PREFERENCES] (state, details) {55 let scout = _.find(state.scouts, { id: details.scoutId });56 let registration = _.find(scout.registrations, (registration) => {57 return registration.details.id === details.registrationId;58 });59 Vue.set(registration, 'preferences', _.sortBy(details.preferences, ['details.rank']));60 },61 [types.SET_SCOUTS] (state, scouts) {62 state.scouts = scouts;63 },64 [types.UPDATE_SCOUT](state, updatedScout) {65 if (state.scouts.length < 1) {66 return;67 }68 let scout = _.find(state.scouts, { id: updatedScout.id });69 state.scouts = _.reject(state.scouts, (existingScout) => {70 return existingScout.id === updatedScout.id;71 });72 updatedScout.registrations = scout.registrations;73 state.scouts.push(updatedScout);74 }75};76const actions = {77 addPurchase({ commit }, details) {78 return new Promise((resolve, reject) => {79 axios.post(URLS.SCOUTS_URL + details.scoutId + '/registrations/' +80 details.registrationId + '/purchases/', details.purchase)81 .then((response) => {82 commit(types.SET_PURCHASES, {83 registrationId: details.registrationId,84 purchases: response.data.registration.purchases85 });86 resolve(response.data.registration.purchases);87 })88 .catch(() => {89 reject();90 })91 });92 },93 addRegistration({ commit }, details) {94 return new Promise((resolve, reject) => {95 axios.post(URLS.SCOUTS_URL + details.scoutId + '/registrations/', {96 event_id: details.eventId97 })98 .then((response) => {99 commit(types.ADD_REGISTRATION, response.data.registration);100 resolve(response.data.registration);101 })102 .catch(() => {103 reject();104 })105 });106 },107 addScout({ commit }, details) {108 return new Promise((resolve, reject) => {109 axios.post(URLS.USERS_URL + details.userId + '/scouts', details.scout)110 .then((response) => {111 commit(types.ADD_SCOUT, response.data.scout);112 resolve(response.data.scout);113 })114 .catch((err) => {115 reject(err.response.data.message);116 })117 });118 },119 deletePurchase({ commit }, details) {120 return new Promise((resolve, reject) => {121 axios.delete(URLS.SCOUTS_URL + details.scoutId + '/registrations/' +122 details.registrationId + '/purchases/' + details.purchasableId)123 .then(() => {124 commit(types.DELETE_PURCHASE, details);125 resolve();126 })127 .catch(() => {128 reject();129 });130 });131 },132 deleteRegistration({ commit }, details) {133 return new Promise((resolve, reject) => {134 axios.delete(URLS.SCOUTS_URL + details.scoutId + '/registrations/' + details.eventId)135 .then(() => {136 commit(types.DELETE_REGISTRATION, details);137 resolve();138 })139 .catch(() => {140 reject();141 })142 });143 },144 deleteScout({ commit }, details) {145 return new Promise((resolve, reject) => {146 axios.delete(URLS.USERS_URL + details.userId + '/scouts/' + details.scoutId)147 .then(() => {148 commit(types.DELETE_SCOUT, details.scoutId);149 resolve()150 })151 .catch(() => {152 reject();153 })154 });155 },156 getPurchases({ commit }, details) {157 return new Promise((resolve, reject) => {158 axios.get(URLS.SCOUTS_URL + details.scoutId + '/registrations/' +159 details.registrationId + '/purchases')160 .then((response) => {161 commit(types.SET_PURCHASES, {162 scoutId: details.scoutId,163 registrationId: details.registrationId,164 purchases: response.data165 });166 resolve();167 })168 .catch(() => {169 reject();170 })171 });172 },173 getPreferences({ commit }, details) {174 return new Promise((resolve, reject) => {175 axios.get(URLS.SCOUTS_URL + details.scoutId + '/registrations/' +176 details.registrationId + '/preferences')177 .then((response) => {178 commit(types.SET_PREFERENCES, {179 scoutId: details.scoutId,180 registrationId: details.registrationId,181 preferences: response.data182 });183 resolve();184 })185 .catch(() => {186 reject();187 })188 });189 },190 getScouts({ commit }, userId) {191 return new Promise((resolve, reject) => {192 axios.get(URLS.USERS_URL + userId + '/scouts/registrations')193 .then((response) => {194 commit(types.SET_SCOUTS, response.data);195 resolve(response.data);196 })197 .catch(() => {198 reject();199 })200 });201 },202 setPreferences({ commit }, details) {203 return new Promise((resolve, reject) => {204 axios.post(URLS.SCOUTS_URL + details.scoutId + '/registrations/' +205 details.registrationId + '/preferences', details.preferences)206 .then((response) => {207 commit(types.SET_PREFERENCES, {208 scoutId: details.scoutId,209 registrationId: details.registrationId,210 preferences: response.data.registration.preferences211 });212 resolve(response.data.registration.preferences);213 })214 .catch(() => {215 reject();216 })217 });218 },219 updateScout({ commit }, details) {220 return new Promise((resolve, reject) => {221 axios.put(URLS.USERS_URL + details.userId + '/scouts/' + details.scout.id, details.scout)222 .then((response) => {223 commit(types.UPDATE_SCOUT, response.data.scout);224 resolve();225 })226 .catch(() => {227 reject();228 })229 })230 }231};232export default {233 state,234 getters,235 actions,236 mutations...

Full Screen

Full Screen

DeviceClient.js

Source:DeviceClient.js Github

copy

Full Screen

1/**2 * Created by hlliu on 2018/2/27.3 * 设备相关接口4 */5var httpCommon = require("./../utils/HttpUtils");6var deviceUrl = "http://api.push.mob.com";7var deviceClient = {8 /**9 * 获取设备别名10 * @param registrationId11 * @return alias 别名12 */13 getDeviceAlias: function (appkey, appSecret, registrationId, callback) {14 if (registrationId == null || registrationId == undefined || registrationId == "") {15 callback("registrationId is null ", null);16 return false;17 }18 var path = deviceUrl + "/alias/" + registrationId;19 httpCommon.get(appkey, appSecret, path, function (err, data) {20 if (err != null) {21 callback(err, data);22 } else {23 if (typeof data == 'string') {24 data = JSON.parse(data);25 }26 callback(null, data['alias']);27 }28 });29 },30 /**31 * 绑定设备别名,如果存在则覆盖原有别名32 * @param alias33 * @param registrationId34 * @return (true 表示成功)35 */36 setDeviceAlias: function (appkey, appSecret, alias, registrationId, callback) {37 if (registrationId == null || registrationId == undefined || registrationId == "") {38 callback("registrationId is null ", null);39 return false;40 }41 var path = deviceUrl + "/alias/";42 var json = {43 'registrationId': registrationId,44 'alias': alias45 }46 httpCommon.post(appkey, appSecret, path, json, function (err, data) {47 if (err != null) {48 callback && callback(err, data);49 } else {50 callback && callback(null, true);51 }52 });53 },54 /**55 * 清空设备别名56 * @param registrationId57 * @return (true 表示成功)58 */59 cleanDeviceAlias: function (appkey, appSecret, registrationId, callback) {60 if (registrationId == null || registrationId == undefined || registrationId == "") {61 callback("registrationId is null ", null);62 return false;63 }64 var path = deviceUrl + "/alias/";65 var json = {66 'registrationId': registrationId,67 'alias': ''68 }69 httpCommon.post(appkey, appSecret, path, json, function (err, data) {70 if (err != null) {71 callback && callback(err, data);72 } else {73 callback && callback(null, true);74 }75 });76 },77 /**78 * 获取设备标签79 * @param registrationId80 * @return tags 标签集合81 */82 getDeviceTags: function (appkey, appSecret, registrationId, callback) {83 if (registrationId == null || registrationId == undefined || registrationId == "") {84 callback("registrationId is null ", null);85 return false;86 }87 var path = deviceUrl + "/tags/" + registrationId;88 httpCommon.get(appkey, appSecret, path, function (err, data) {89 if (err != null) {90 callback(err, data);91 } else {92 if (typeof data == 'string') {93 data = JSON.parse(data);94 }95 callback(null, data['tags']);96 }97 })98 },99 /**100 * 设备绑定标签101 * @param tags102 * @param registrationId103 * @return (true 表示成功)104 */105 addDeviceTags: function (appkey, appSecret, tags, registrationId, callback) {106 if (registrationId == null || registrationId == undefined || registrationId == "") {107 callback("registrationId is null ", null);108 return false;109 }110 if (tags instanceof Array) {111 if (tags == null || tags.length < 1) {112 callback("tags is null ", null);113 return false;114 }115 } else {116 callback("tags type should be array ", null);117 return false;118 }119 var path = deviceUrl + "/tags/";120 var json = {121 'registrationId': registrationId,122 'tags': tags,123 'opType': 1124 }125 httpCommon.post(appkey, appSecret, path, json, function (err, data) {126 if (err != null) {127 callback && callback(err, data);128 } else {129 callback && callback(null, true);130 }131 });132 },133 /**134 * 删除设备指定标签135 * @param tags136 * @param registrationId137 * @return (true 表示成功)138 */139 removeDeviceTags: function (appkey, appSecret, tags, registrationId, callback) {140 if (registrationId == null || registrationId == undefined || registrationId == "") {141 callback("registrationId is null ", null);142 return false;143 }144 if (tags instanceof Array) {145 if (tags == null || tags.length < 1) {146 callback("tags is null ", null);147 return false;148 }149 } else {150 callback("tags type should be array ", null);151 return false;152 }153 var path = deviceUrl + "/tags/";154 var json = {155 'registrationId': registrationId,156 'tags': tags,157 'opType': 2158 }159 httpCommon.post(appkey, appSecret, path, json, function (err, data) {160 if (err != null) {161 callback && callback(err, data);162 } else {163 callback && callback(null, true);164 }165 });166 },167 /**168 * 清空设备标签169 * @param registrationId170 * @return (true 表示成功)171 */172 cleanDeviceTags: function (appkey, appSecret, registrationId, callback) {173 if (registrationId == null || registrationId == undefined || registrationId == "") {174 callback("registrationId is null ", null);175 return false;176 }177 var path = deviceUrl + "/tags/";178 var json = {179 'registrationId': registrationId,180 'opType': 3181 }182 httpCommon.post(appkey, appSecret, path, json, function (err, data) {183 if (err != null) {184 callback && callback(err, data);185 } else {186 callback && callback(null, true);187 }188 });189 }190}...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1/*2 * Please see the included README.md file for license terms and conditions.3 */4var version = "0.1.0, 8 March 2016";5/*jslint browser:true, devel:true, white:true, vars:true */6/*global $:false, intel:false app:false, dev:false, cordova:false */7function onAppReady() {8 if( navigator.splashscreen && navigator.splashscreen.hide ) {9 navigator.splashscreen.hide() ;10 }11 var registrationId = null;12 $("#version").text(version);13 $("#registrationId").val("Not set yet");14 $(document).on("click", ".ext-link", function (evt) {15 var linktarget = $(this).prop("href");16 window.open(linktarget, '_system');17 return false;18 })19 $(document).on("click", "#goOnline", function (evt) {20 if (registrationId == null) {21 alert("registrationId not set");22 return false;23 }24 var mt = "http://www.penrithedenfreegle.org.uk/modtools/simplepush.php?id=" + registrationId;25 window.open(mt, '_system');26 return false;27 });28 var push = PushNotification.init({29 /*android: {30 senderID: "12345679"31 },32 windows: {},*/33 ios: {34 alert: true,35 badge: true,36 sound: true37 }38 });39 push.on('registration', function (data) {40 registrationId = data.registrationId;41 $("#registrationId").val(data.registrationId);42 //alert("registration: " + data.registrationId);43 });44 push.on('notification', function (data) {45 $('#nTitle').text(data.title);46 $('#nMessage').text(data.message);47 $('#nCount').text(data.count);48 $('#nSound').text(data.sound);49 $('#nImage').text(data.image);50 $('#nAdditionalData').text(JSON.stringify(data.additionalData));51 $('#nData').text(JSON.stringify(data));52 push.finish(function () {53 //alert("finished");54 });55 });56 push.on('error', function (e) {57 alert("error: " + e.message);58 });59}60document.addEventListener("app.Ready", onAppReady, false) ;61// document.addEventListener("deviceready", onAppReady, false) ;62// document.addEventListener("onload", onAppReady, false) ;63// The app.Ready event shown above is generated by the init-dev.js file; it64// unifies a variety of common "ready" events. See the init-dev.js file for65// more details. You can use a different event to start your app, instead of66// this event. A few examples are shown in the sample code above. If you are67// using Cordova plugins you need to either use this app.Ready event or the68// standard Cordova deviceready event. Others will either not work or will69// work poorly.70// NOTE: change "dev.LOG" in "init-dev.js" to "true" to enable some console.log...

Full Screen

Full Screen

push.js

Source:push.js Github

copy

Full Screen

1var db = require('byteballcore/db');2var conf = require('byteballcore/conf');3var eventBus = require('byteballcore/event_bus.js');4var https = require('https');5eventBus.on('peer_sent_new_message', function(ws, objDeviceMessage) {6 sendPushAboutMessage(objDeviceMessage.to);7});8eventBus.on("enableNotification", function(deviceAddress, registrationId) {9 db.query("SELECT device_address FROM push_registrations WHERE device_address=? LIMIT 0,1", [deviceAddress], function(rows) {10 if (rows.length === 0) {11 db.query("INSERT "+db.getIgnore()+" INTO push_registrations (registrationId, device_address) VALUES (?, ?)", [registrationId, deviceAddress], function() {12 });13 } else if (rows.length) {14 if (rows[0].registration_id !== registrationId) {15 db.query("UPDATE push_registrations SET registrationId = ? WHERE device_address = ?", [registrationId, deviceAddress], function() {16 })17 }18 }19 });20});21eventBus.on("disableNotification", function(deviceAddress, registrationId) {22 db.query("DELETE FROM push_registrations WHERE registrationId=? and device_address=?", [registrationId, deviceAddress], function() {23 });24});25function sendRest(registrationIds) {26 var options = {27 host: 'android.googleapis.com',28 port: 443,29 path: '/gcm/send',30 method: 'POST',31 headers: {32 'Content-Type': 'application/json',33 'Authorization': 'key=' + conf.pushApiKey34 }35 };36 var req = https.request(options, function(res) {37 res.on('data', function(d) {38 if (res.statusCode !== 200) {39 console.log('Error push rest. code: ' + res.statusCode + ' Text: ' + d);40 console.log(registrationIds);41 }42 });43 });44 req.write(JSON.stringify({45 "registration_ids": registrationIds,46 "data": {47 "message": "New message",48 "title": "Byteball",49 "vibrate": 1,50 "sound": 151 }52 }));53 req.end();54 req.on('error', function(e) {55 console.error(e);56 });57}58function sendPushAboutMessage(device_address) {59 db.query("SELECT registrationId FROM push_registrations WHERE device_address=?", [device_address], function(rows) {60 if (rows.length > 0) {61 sendRest([rows[0].registrationId]);62 }63 });64}...

Full Screen

Full Screen

app.mjs

Source:app.mjs Github

copy

Full Screen

1import App from 'turbo-serv'2import sqlite from 'sqlite3'3let app = new App()4let router = app.getRouter()5let db = new sqlite.Database(':memory:')6db.serialize(function () {7 db.run(`CREATE TABLE users (registrationId PRIMARY KEY,8 pubSignedPreKey,9 signKeyId,10 signature,11 identityKey)`)12 db.run(`CREATE TABLE preKeys (registrationId, keyId, pubPreKey)`)13})14router.post('/register', function () {15 console.log(this.body)16 let stmt = db.prepare(`INSERT INTO users VALUES ($registrationId,17 $pubSignedPreKey,18 $signKeyId,19 $signature,20 $identityKey)`)21 stmt.run({22 $registrationId: this.body.registrationId,23 $pubSignedPreKey: this.body.pubSignedPreKey,24 $signKeyId: this.body.signKeyId,25 $signature: this.body.signature,26 $identityKey: this.body.identityKey27 })28 stmt.finalize()29 let preStmt30 this.body.pubPreKeys.forEach(keyObj => {31 preStmt = db.prepare(`INSERT INTO preKeys VALUES ($registrationId, $keyId, $pubPreKey)`)32 preStmt.run({33 $registrationId: this.body.registrationId,34 $keyId: keyObj.keyId,35 $pubPreKey: keyObj.pubKey36 })37 preStmt.finalize()38 })39 db.each(`SELECT * FROM users`,40 (err, row) => {41 this.res.send(row || err)42 })43})44router.get('/users', function () {45 db.all(`SELECT * FROM users`,46 (err, row) => {47 let result = row48 this.res.send(result)49 })50})51router.post('/newSession', function () {52 console.log(this.body)53 let registrationId = this.body54 let stmt = db.prepare(`SELECT * FROM users NATURAL JOIN prekeys WHERE registrationId = $registrationId`)55 stmt.get({$registrationId: registrationId}, (err, row) => {56 console.log(row)57 this.res.send(row)58 })59})...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10 var options = {11at new WebPageTest (C:\Users\shrey\AppData\Roaming12at Object. (C:\Users\shrey\Documents\Projects\test.js:4:13)13at Module._compile (module.js:410:26)14at Object.Module._extensions..js (module.js:416:10)15at Module.load (module.js:343:32)16at Function.Module._load (module.js:300:12)17at Function.Module.runMain (module.js:441:10)18at startup (node.js:139:18)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2console.log('registrationId: ' + wptoolkit.registrationId);3var wptoolkit = require('wptoolkit');4wptoolkit.registrationId(function(err, response) {5 console.log('registrationId: ' + response);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 console.log(data);5});6{ [Error: getaddrinfo ENOTFOUND www.webpagetest.org www.webpagetest.org:80]7 port: 80 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var regId = wptoolkit.registrationId();3console.log(regId);4var wptoolkit = require('wptoolkit');5var regId = wptoolkit.registrationId();6console.log(regId);7var wptoolkit = require('wptoolkit');8var regId = wptoolkit.registrationId();9console.log(regId);10var wptoolkit = require('wptoolkit');11var regId = wptoolkit.registrationId();12console.log(regId);13var wptoolkit = require('wptoolkit');14var regId = wptoolkit.registrationId();15console.log(regId);16var wptoolkit = require('wptoolkit');17var regId = wptoolkit.registrationId();18console.log(regId);19var wptoolkit = require('wptoolkit');20var regId = wptoolkit.registrationId();21console.log(regId);22var wptoolkit = require('wptoolkit');23var regId = wptoolkit.registrationId();24console.log(regId);25var wptoolkit = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var regId = wptoolkit.registrationId();3console.log(regId);4var wptoolkit = require('wptoolkit');5wptoolkit.registrationId(function(regId){6 console.log(regId);7});8var wptoolkit = require('wptoolkit');9wptoolkit.registrationId(function(regId){10 console.log(regId);11}, function(error){12 console.log(error);13});14var wptoolkit = require('wptoolkit');15wptoolkit.registrationId(function(regId){16 console.log(regId);17}, function(error){18 console.log(error);19});20var wptoolkit = require('wptoolkit');21wptoolkit.registrationId(function(regId){22 console.log(regId);23}, function(error){24 console.log(error);25});26var wptoolkit = require('wptoolkit');27wptoolkit.registrationId(function(regId){28 console.log(regId);29}, function(error){30 console.log(error);31});32var wptoolkit = require('wptoolkit');33wptoolkit.registrationId(function(regId){34 console.log(regId);35}, function(error){36 console.log(error);37});38var wptoolkit = require('wptoolkit');39wptoolkit.registrationId(function(regId){40 console.log(regId);41}, function(error){42 console.log(error);43});44var wptoolkit = require('wptoolkit');45wptoolkit.registrationId(function(regId){46 console.log(regId);47}, function(error){48 console.log(error);49});

Full Screen

Using AI Code Generation

copy

Full Screen

1var registrationId = require('wpt').registrationId;2registrationId(function(err, id) {3 if (err) {4 console.log(err);5 } else {6 console.log(id);7 }8});9var locations = require('wpt').locations;10locations(function(err, locations) {11 if (err) {12 console.log(err);13 } else {14 console.log(locations);15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptService = require('wpt-service');2var registrationId = wptService.registrationId();3var wptService = require('wpt-service');4var wptService = require('wpt-service');5 console.log(data);6});7var wptService = require('wpt-service');8var options = {9};10 console.log(data);11});12var wptService = require('wpt-service');13var options = {14};15 console.log(data);16});17var wptService = require('wpt-service');18var options = {19};20 console.log(data);21});22var wptService = require('wpt-service');23var options = {24};25 console.log(data);26});27var wptService = require('wpt-service');28var options = {29};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require("wptoolkit");2wptoolkit.registrationId("push", function(err, data) {3 if (err) {4 alert(err);5 } else {6 alert(data);7 }8});9var wptoolkit = require("wptoolkit");10wptoolkit.push("push", "Hello World", function(err, data) {11 if (err) {12 alert(err);13 } else {14 alert(data);15 }16});17var wptoolkit = require("wptoolkit");18wptoolkit.push("push", "Hello World", function(err, data) {19 if (err) {20 alert(err);21 } else {22 alert(data);23 }24});25var wptoolkit = require("wptoolkit");26wptoolkit.push("push", "Hello World", function(err, data) {27 if (err) {28 alert(err);29 } else {30 alert(data);31 }32});33var wptoolkit = require("wptoolkit");34wptoolkit.push("push", "Hello World", function(err, data) {35 if (err) {36 alert(err);37 } else {38 alert(data);39 }40});41var wptoolkit = require("wptoolkit");42wptoolkit.push("push", "Hello World", function(err, data) {43 if (err) {44 alert(err);45 } else {46 alert(data);47 }48});49var wptoolkit = require("wptoolkit");50wptoolkit.push("push", "Hello World", function(err, data

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful