Skip to content

Commit

Permalink
Merge pull request #141 from jupiter-project/fix/is-account-registered
Browse files Browse the repository at this point in the history
patch the signup. dont allow register if already registered.
  • Loading branch information
reyesrene authored Feb 19, 2022
2 parents 1451358 + 2fc1bca commit 9e2b849
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions services/accountRegistrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,20 @@ class AccountRegistration {

/**
*
* @param clientAddress
* @param appRecords
* @return {boolean}
* @param address
* @return {Promise<boolean>}
*/
isAccountRegisteredWithApp(clientAddress, appRecords){
if(!gu.isWellFormedJupiterAddress(clientAddress)) throw new mError.MetisErrorBadJupiterAddress(`clientAddress: ${clientAddress}`)
// if(!gu.isWellFormedJupiterAddress(clientAddress)){throw new BadJupiterAddressError(clientAddress)}
// if(!gu.isWellFormedJupiterAddress(clientAddress)){throw new Error('clientAddress is not valid')}
if(!Array.isArray(appRecords)){throw new Error('appRecords is not an array')}
if(!appRecords.hasOwnProperty('account')){throw new Error('records is not valid. missing property: account')}
const record = appRecords.filter(record => record.account == clientAddress);
if(record.length === 0){
return false;
}
async isAccountRegisteredWithApp(address){
logger.verbose(`#### isAccountRegisteredWithApp(address)`);
logger.sensitive(`address=${JSON.stringify(address)}`);
if(!gu.isWellFormedJupiterAddress(address)) throw new mError.MetisErrorBadJupiterAddress(`address: ${address}`);
const tag = userConfig.userRecord;
const transactions = await this.jupiterTransactionsService.fetchConfirmedAndUnconfirmedBlockChainTransactionsByTag(address,tag);
console.log(`length: ${transactions.length}`);
if (!gu.isNonEmptyArray(transactions)) return false;
return true;
}

return true
}


/**
Expand Down Expand Up @@ -232,6 +229,15 @@ class AccountRegistration {
if(!(newAccountProperties instanceof GravityAccountProperties)) throw new mError.MetisErrorBadGravityAccountProperties(`newAccountProperties`)
if(!gu.isWellFormedJupiterAlias(newAccountAliasName)) throw new mError.MetisErrorBadJupiterAlias(newAccountAliasName);
try {
// First: check if Account is not already registered
console.log(`\n`);
logger.info(`-__-__-__-__-__-__-__-__-__-__-__-__-__-__-__--`);
logger.info(` First: check if Account is not already registered: ${newAccountProperties.address}`);
logger.info(`-__-__-__-__-__-__-__-__-__-__-__-__-__-__-__--\n`);
const isAlreadyRegistered = await this.isAccountRegisteredWithApp(newAccountProperties.address);
if (isAlreadyRegistered) {
throw new Error('Account is already registered');
}
// First: Make sure the alias is available
console.log(`\n`);
logger.info(`-__-__-__-__-__-__-__-__-__-__-__-__-__-__-__--`);
Expand Down Expand Up @@ -481,6 +487,7 @@ const {jupiterTransactionsService} = require("./jupiterTransactionsService");
const {instantiateGravityAccountProperties} = require("../gravity/instantiateGravityAccountProperties");
const {MetisError, MetisErrorWeakPassword} = require("../errors/metisError");
const mError = require("../errors/metisError");
const {userConfig} = require("../config/constants");
// const {binaryAccountJob, BinaryAccountJob} = require("../src/jim/jobs/binaryAccountJob");

module.exports.AccountRegistration = AccountRegistration;
Expand Down

0 comments on commit 9e2b849

Please sign in to comment.