membrane-reg
Version:
Membrane seemlessly connects Momentum Members to MCN's fully catalog of applications and services. Earn rewards for your ongoing engagement, participation, and support.
72 lines (61 loc) • 2.12 kB
JavaScript
//index.js
// Import required modules
const { Contract } = require('fabric-contract-api');
// Define the UserRegistration chaincode class
class UserRegistration extends Contract {
// Initialize the chaincode
async initLedger(ctx) {
console.log('Initializing the ledger');
}
// Register a new visitor account
async registerVisitor(ctx, firstName, lastName, username, phoneNumber, password) {
// Check if the username is already taken
const userExists = await ctx.stub.getState(username);
if (userExists) {
throw new Error('Username already exists. Please choose a different username.');
}
// Create a new visitor account object
const account = {
firstName,
lastName,
username,
phoneNumber,
password
};
// Persist the visitor account data on the cloud server
await ctx.stub.putState(username, Buffer.from(JSON.stringify(account)));
console.log('Visitor account registered successfully');
}
// Register a new member account
async registerMember(ctx, firstName, lastName, username, phoneNumber, emailAddress, dateOfBirth, postalCode, membershipTier) {
// Check if the username is already taken
const userExists = await ctx.stub.getState(username);
if (userExists) {
throw new Error('Username already exists. Please choose a different username.');
}
// Create a new member account object
const account = {
firstName,
lastName,
username,
phoneNumber,
emailAddress,
dateOfBirth,
postalCode,
membershipTier,
bio: '',
aboutMe: '',
tagline: '',
hobbiesInterests: '',
religion: '',
sexuality: '',
datingPreference: '',
height: ''
};
// Persist the member account data on the Membrane blockchain
await ctx.stub.putState(username, Buffer.from(JSON.stringify(account)));
console.log('Member account registered successfully');
}
}
// Export the MembraneAccountReg chaincode class
module.exports = MembraneAccountReg;