UNPKG

@magic.batua/account

Version:

The Account modules powers the user account management features of the Magic Batua platform.

1,771 lines (416 loc) 22.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Account - Postman Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Account.html">Account</a><ul class='methods'><li data-type='method'><a href="Account.html#AddPoints">AddPoints</a></li><li data-type='method'><a href="Account.html#AddReferral">AddReferral</a></li><li data-type='method'><a href="Account.html#CanAuthenticateUsing">CanAuthenticateUsing</a></li><li data-type='method'><a href="Account.html#Delete">Delete</a></li><li data-type='method'><a href="Account.html#Export">Export</a></li><li data-type='method'><a href="Account.html#RedeemPoints">RedeemPoints</a></li><li data-type='method'><a href="Account.html#RemoveReferral">RemoveReferral</a></li><li data-type='method'><a href="Account.html#ResetPassword">ResetPassword</a></li><li data-type='method'><a href="Account.html#SetOTP">SetOTP</a></li><li data-type='method'><a href="Account.html#SetReferrer">SetReferrer</a></li><li data-type='method'><a href="Account.html#Undelete">Undelete</a></li><li data-type='method'><a href="Account.html#UnsetOTP">UnsetOTP</a></li></ul></li><li><a href="Registry.html">Registry</a><ul class='methods'><li data-type='method'><a href="Registry.html#Create">Create</a></li><li data-type='method'><a href="Registry.html#DidResetPassword">DidResetPassword</a></li><li data-type='method'><a href="Registry.html#DidSendOTP">DidSendOTP</a></li><li data-type='method'><a href="Registry.html#HasVerified">HasVerified</a></li><li data-type='method'><a href="Registry.html#IsDuplicate">IsDuplicate</a></li><li data-type='method'><a href="Registry.html#Modify">Modify</a></li><li data-type='method'><a href="Registry.html#Remove">Remove</a></li><li data-type='method'><a href="Registry.html#Retrieve">Retrieve</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-Database.html">Database</a><ul class='methods'><li data-type='method'><a href="module-Database.html#~Find">Find</a></li><li data-type='method'><a href="module-Database.html#~FindAndReplace">FindAndReplace</a></li><li data-type='method'><a href="module-Database.html#~GetAccountByID">GetAccountByID</a></li><li data-type='method'><a href="module-Database.html#~GetReferrer">GetReferrer</a></li><li data-type='method'><a href="module-Database.html#~Insert">Insert</a></li><li data-type='method'><a href="module-Database.html#~IsDuplicate">IsDuplicate</a></li><li data-type='method'><a href="module-Database.html#~UpdateInPlace">UpdateInPlace</a></li></ul></li><li><a href="module-Source.html">Source</a></li></ul> </nav> <div id="main"> <h1 class="page-title">Account</h1> <section> <header> <h2> Account </h2> <div class="class-description"><p>The <code>Account</code> class models the data and functions supported by Magic Batua accounts. Besides the standard profile information — name, email, phone, etc. — it also takes care of things such as referrals and loyalty points.</p> <p> Business logic used for password resets, salt generation, hashing and other such operations are also defined by the <code>Account</code> class.</p></div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="Account"><span class="type-signature"></span>new Account<span class="signature">(json, source)</span><span class="type-signature"></span></h4> <div class="description"> <p>In a server-side application, there are two instantiation scenarios: one where the input is provided by the client, and the other where the input is provided by the database.</p> <p> Client-side input is always lighter than database-side input, since auto-generated properties such as <code>_id</code> are missing in the client-side variant. Moreover, client-side input may contain less information than database-side input as some sensitive properties such as password, salt, etc. are never revealed to the client side.</p> <p> As such, we need a way to track the source of input and proceed with instantiation accordingly. This <code>source</code> parameter serves exactly this purpose.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>json</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="description last"><p>Input JSON</p></td> </tr> <tr> <td class="name"><code>source</code></td> <td class="type"> <span class="param-type"><a href="Source.html">Source</a></span> </td> <td class="description last"><p>Input source. See <code>Source/Source.ts</code> for definition of <code>Source</code>.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line22">line 22</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id="isDeleted"><span class="type-signature"></span>isDeleted<span class="type-signature"></span></h4> <div class="description"> <p>Flag used to soft-delete an account. Accounts are never deleted permanently. This is for administrative and data analytics reasons. When a user submits a account deletion request, this flag is set to true and the <code>recoverBy</code> date is set to 14 days ahead.</p> <p> If a user logs into their account within those 14 days, the deletion hold is lifted and this flag is set to <code>false</code> again.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line50">line 50</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="AddPoints"><span class="type-signature"></span>AddPoints<span class="signature">(points, reason)</span><span class="type-signature"></span></h4> <div class="description"> <p>Adds loyalty points to the account.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>points</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>Number of points to be awarded</p></td> </tr> <tr> <td class="name"><code>reason</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Reason for the generosity</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line128">line 128</a> </li></ul></dd> </dl> <h4 class="name" id="AddReferral"><span class="type-signature"></span>AddReferral<span class="signature">(id)</span><span class="type-signature"></span></h4> <div class="description"> <p>Adds a referral to the account's referrals list</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>User <code>_id</code> of the referral</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line113">line 113</a> </li></ul></dd> </dl> <h4 class="name" id="CanAuthenticateUsing"><span class="type-signature"></span>CanAuthenticateUsing<span class="signature">(password)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> <p>Salts the given <code>password</code> using the <code>salt</code> used at account creation, and then compares the hash with the hashed password stored in the database.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>password</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Client-provided password</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line84">line 84</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p><code>true</code> if the password is correct, otherwise <code>false</code></p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="Delete"><span class="type-signature"></span>Delete<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Puts the account into a 14-day deletion hold by setting <code>isDeleted</code> to <code>true</code> and setting the account <code>recoverBy</code> date to 14-days from now.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line204">line 204</a> </li></ul></dd> </dl> <h4 class="name" id="Export"><span class="type-signature"></span>Export<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Exports the <code>Account</code> object to a shareable JSON string. Used to compose HTTP response bodies. Prevents sensitive information such as password, salt etc. from leaking onto client-side.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line229">line 229</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>A stringified, sanitised version of the <code>Account</code> instance</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="RedeemPoints"><span class="type-signature"></span>RedeemPoints<span class="signature">(points, reason)</span><span class="type-signature"></span></h4> <div class="description"> <p>Redeems the given number of points. Throws an error if available points are fewer than the <code>points</code> requested.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>points</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>Numbe of points to be redeemed</p></td> </tr> <tr> <td class="name"><code>reason</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Purpose of redemption</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line141">line 141</a> </li></ul></dd> </dl> <h4 class="name" id="RemoveReferral"><span class="type-signature"></span>RemoveReferral<span class="signature">(id)</span><span class="type-signature"></span></h4> <div class="description"> <p>Removes a referral from the account's referral list. This is used only when a referral decides to permanently delete their account.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>User <code>_id</code> of the referral to be removed</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line155">line 155</a> </li></ul></dd> </dl> <h4 class="name" id="ResetPassword"><span class="type-signature"></span>ResetPassword<span class="signature">(newPass)</span><span class="type-signature"></span></h4> <div class="description"> <p>Changes the existing account password to <code>newPass</code>. This also changes the <code>salt</code> used before hashing.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>newPass</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>New password</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line170">line 170</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>A tuple of the form (salt, newPassword)</p> </div> <h4 class="name" id="SetOTP"><span class="type-signature"></span>SetOTP<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Generates a random 6-digit number and stores it in database as a verification code.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line184">line 184</a> </li></ul></dd> </dl> <h4 class="name" id="SetReferrer"><span class="type-signature"></span>SetReferrer<span class="signature">(id)</span><span class="type-signature"></span></h4> <div class="description"> <p>Sets <code>referredBy</code> to the <code>_id</code> of the user who referred this user to Magic Batua.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>User <code>_id</code> of the referrer</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line100">line 100</a> </li></ul></dd> </dl> <h4 class="name" id="Undelete"><span class="type-signature"></span>Undelete<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Removes the deletion hold on the account by setting <code>isDeleted</code> to <code>false</code> and setting the account <code>recoverBy</code> date to <code>undefined</code>.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line217">line 217</a> </li></ul></dd> </dl> <h4 class="name" id="UnsetOTP"><span class="type-signature"></span>UnsetOTP<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Sets the verification code <code>otp</code> to <code>undefined</code> after a successful verification</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Source_Account.js.html">Source/Account.js</a>, <a href="Source_Account.js.html#line194">line 194</a> </li></ul></dd> </dl> </article> </section> </div> <br class="clear"> <footer> Documentation generated at Mon Mar 19 2018 22:39:23 GMT+0530 (IST) </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>