Browse Source

add support for `email-prompt`

master
Guillermo Rauch 9 years ago
parent
commit
d26a6242ac
  1. 20
      lib/login.js
  2. 3
      package.json

20
lib/login.js

@ -3,23 +3,7 @@ import fetch from 'node-fetch';
import * as cfg from './cfg';
import { stringify as stringifyQuery } from 'querystring';
import { validate } from 'email-validator';
function readEmail ({ invalid = false } = {}) {
return new Promise((resolve, reject) => {
const decorate = invalid ? chalk.red : (v) => v;
const prompt = decorate('> Enter your email address: ');
process.stdout.write(prompt);
const data = [];
process.stdin.on('data', (d) => {
data.push(d);
if (d.indexOf('\n') > -1) {
process.stdin.pause();
resolve(Buffer.concat(data).toString().trim());
}
});
process.stdin.resume();
});
}
import readEmail from 'email-prompt';
async function getVerificationToken (url, email) {
const data = JSON.stringify({ email });
@ -59,6 +43,8 @@ function sleep (ms) {
async function register (url, { retryEmail = false } = {}) {
const email = await readEmail({ invalid: retryEmail });
process.stdout.write('\n');
if (!validate(email)) return register(url, { retryEmail: true });
const verificationToken = await getVerificationToken(url, email);

3
package.json

@ -32,7 +32,8 @@
"split-array": "1.0.1",
"text-table": "0.2.0",
"spdy": "3.3.3",
"email-validator": "1.0.4"
"email-validator": "1.0.4",
"email-prompt": "0.1.3"
},
"devDependencies": {
"alpha-sort": "1.0.2",

Loading…
Cancel
Save