Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Handle new Barclays login for OTP method only
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Nov 25, 2020
1 parent df04e20 commit 62cab59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
36 changes: 10 additions & 26 deletions session.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,17 @@ class Session {

async loginStage1(credentials) {
// Stage 1 of login - enter surname and membership number.
await u.wait(this.page, '#membershipNum0');
await u.wait(this.page, '#membership0');
await u.fillFields(this.page, {
'#surname0': credentials['surname'],
'#membershipNum0': credentials['membershipno'],
'#surnameMem': credentials['surname'],
'#membership0': credentials['membershipno'],
});
await u.click(this.page, 'button[title="Next Step"]');
await u.click(this.page, 'button#continue');
}

async loginSelectMethod(method) {
// Stage 2: If multiple auth methods are enabled for this account,
// select the correct one.
let selector = '[ng-controller="authTFACtrl"] ';

// Wait for the login button which hopefully means the page has loaded.
await u.wait(this.page, 'button[title="Log in to Online Banking"]')
if (method == 'motp') {
selector += 'input#radio-c3';
} else if (method == 'otp') {
selector += 'input#radio-c4';
} else if (method == 'plogin') {
selector += 'input#radio-c2';
}

const sel = await this.page.$(selector);
if (sel) {
await this.page.$eval(selector, el => { el.click() })
}
// TODO: re-implement this - OTP is the default for me.
// There's now a tab bar along the top of the page which needs clicking to switch method.
}

async ensureLoggedIn() {
Expand All @@ -58,13 +42,13 @@ class Session {
// Log in using a one time password (PinSentry).
await this.loginStage1(credentials);
await this.loginSelectMethod('otp');
await u.wait(this.page, '#pinsentryCode0');
await u.wait(this.page, '#mobilePinsentryCode-input-1');
await u.fillFields(this.page, {
'#lastDigits0': credentials['card_digits'],
'#pinsentryCode0': credentials['otp'].slice(0, 4),
'#pinsentryCode1': credentials['otp'].slice(4, 8),
'#mobilePinsentryCode-input-1': credentials['otp'].slice(0, 4),
'#mobilePinsentryCode-input-2': credentials['otp'].slice(4, 8),
});
await u.click(this.page, 'button[title="Log in to Online Banking"]');
await u.click(this.page, 'button#submitAuthentication');
await this.ensureLoggedIn();
}

Expand Down
3 changes: 2 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ exports.click = async (page, selector) => {
exports.fillFields = async (page, form) => {
// Disappointingly, you can't type into multiple fields simultaneously.
for (let key of Object.keys(form)) {
await page.click(key);
await page.type(key, form[key]);
}
};
Expand All @@ -53,4 +54,4 @@ exports.wait = async (page, selector) => {

exports.cssEsc = (string) => {
return string.replace(/([\\'"])/g, '\\$1');
};
};

0 comments on commit 62cab59

Please sign in to comment.