Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { protocol, username, password, host, pathname } = new URL(
`ent://${spec}`
);
if (protocol !== 'ent:') {
warnings.push('Contained unexpected protocol portion');
return false;
}
if (password) {
warnings.push('Contained unexpected password in namespace portion');
return false;
}
try {
validate.username(username);
} catch (err) {
warnings.push('Username: ' + err.message);
return false;
}
const name = pathname.slice(1);
const errors = packageNameOK(name, username);
if (errors) {
warnings.push(String(errors));
return false;
}
return {
canonical: `${username}@${host}/${encodeURIComponent(name)}`,
namespace: username,
host: host,
function readUsername (username, opts) {
if (username) {
const error = userValidate.username(username)
if (error) {
opts.log && opts.log.warn(error.message)
} else {
return username.trim()
}
}
return read({prompt: 'Username: ', default: username || ''})
.then(username => readUsername(username, opts))
}
function readUsername (msg, username, opts, isRetry) {
if (!msg) msg = 'npm username: '
if (isRetry && username) {
const error = userValidate.username(username)
if (error) {
opts.log && opts.log.warn(error.message)
} else {
return Promise.resolve(username.trim())
}
}
return read({prompt: msg, default: username || ''})
.then((username) => readUsername(msg, username, opts, true))
}
async function signupAction(context) {
const remoteAuth = context.session.get('remoteAuth');
if (!remoteAuth) {
return response.redirect('/login');
}
const { username, email } = querystring.parse(await text(context.request));
context.username = username;
context.email = email;
try {
validate.username(username);
} catch (err) {
context.errors = { username: err.message };
return signup(context);
}
if (!isEmailMaybe(email)) {
context.errors = { email: 'Sorry, that does not look like an email.' };
return signup(context);
}
const [err, user] = await context.storageApi
.signup({
username,
email,
remoteAuth
})