Accounts
Extends:
Method Summary
Public Methods | ||
public |
Attempts to activate the user's account. This only applies to accounts which haven't been activated yet. |
|
public |
Generates a new activation code for a newly created account. |
|
public |
Starts a new session with PageProof given an already existing user. |
|
public |
Invalidates the current session. |
|
public |
Creates a new PageProof account. |
Public Methods
public activate(activationCode: string): Promise source
Attempts to activate the user's account. This only applies to accounts which haven't been activated yet.
You can request a new activation code by calling Accounts#generateActivationCode. There is currently no way to easily extract the user's activation code from an email - it does require manual HTML traversal.
An activation code is automatically sent to any new accounts.
Params:
Name | Type | Attribute | Description |
activationCode | string | The user's activation code, sent to them via email |
Example:
try {
await client.accounts.activate('N7HLA9');
} catch (err) {
console.log('Invalid activation code!');
}
public generateActivationCode(): Promise source
Generates a new activation code for a newly created account. The activation code is sent to the user's email address, and contains a link for them to click.
This method is automatically called when calling Accounts#register. The only reason you would want to call this method is if the user entered the activation code incorrectly - as activation codes invalidate if the attempt is incorrect. This feature is intended to prevent spam accounts.
If you're looking to automate the process, you will need to manually traverse the HTML.
public login(email: string, password: string): Promise<Session> source
Starts a new session with PageProof given an already existing user.
Too many attempts to this API will temporarily cause any any further requests to be immediately rejected by the server.
Example:
const session = await client.accounts.login('user@example.com', '<password>');
const sessionJSON = JSON.stringify(session);
localStorage.setItem('session', sessionJSON);
public logout(): Promise source
Invalidates the current session.
Rejects if there is no current session, or if the session has already been invalidated.
public register(email: string, password: string): Promise<Session> source
Creates a new PageProof account.
This method does a few different things;
- Hashes the user's password
- Locally generates a 2048-bit RSA key pair
- Encrypts the user's RSA private key with their unhashed password
- Sends the encrypted private key, and the user's hashed password to PageProof
- Sends the user an activation email with their activation code
The Session object contains the user's secure credentials. These credentials are never transmitted over HTTP. Only encrypted & hashed data is ever sent to PageProof. It's recommended that you serialise the Session object so you can re-authenticate using PageProof#setSession at a later stage. Doing this means you should be careful about where you store the serialised data, as the Session contains the user's unencrypted RSA private key.
Note: You can expect this method to take some time to resolve, as generating a RSA key pair is usually very time consuming.
Example:
try {
const session = await client.accounts.register('user@example.com', '<password>');
const sessionJSON = JSON.stringify(session);
localStorage.setItem('session', sessionJSON);
} catch (err) {
// This most commonly occurs when the email address is already registered...
console.log('Unable to create account:', err);
}