Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/password

Package Overview
Dependencies
Maintainers
3
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/password - npm Package Compare versions

Comparing version 1.0.0-alpha-20231119094526-b1fc68c7 to 1.0.0-alpha-20231120163547-4a461fcc

6

lib/endpoints/express.d.ts

@@ -5,4 +5,4 @@ import { type Injector } from 'graphql-modules';

export declare const infosMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
export declare const verifyEmail: (accountsPasswordOrInjector: Injector | AccountsPassword) => (req: Request, res: Response) => Promise<void>;
export declare const resetPassword: (accountsPasswordOrInjector: Injector | AccountsPassword) => (req: Request, res: Response) => Promise<void>;
export declare const resetPasswordForm: (req: Request, res: Response) => Response;
export declare const verifyEmail: (import("express-validator").ValidationChain | ((accountsPasswordOrInjector: Injector | AccountsPassword) => (req: Request, res: Response) => Promise<void>))[];
export declare const resetPassword: (import("express-validator").ValidationChain | ((accountsPasswordOrInjector: Injector | AccountsPassword) => (req: Request, res: Response) => Promise<void>))[];
export declare const resetPasswordForm: (import("express-validator").ValidationChain | ((req: Request, res: Response) => void))[];

@@ -5,4 +5,10 @@ "use strict";

const tslib_1 = require("tslib");
const validator_1 = tslib_1.__importDefault(require("validator"));
const accounts_password_1 = tslib_1.__importDefault(require("../accounts-password"));
const express_validator_1 = require("express-validator");
function matchOrThrow(...args) {
if (!(0, express_validator_1.validationResult)(args[0]).isEmpty()) {
throw new Error('Validation error');
}
return (0, express_validator_1.matchedData)(...args);
}
function getHtml(title, body) {

@@ -34,63 +40,72 @@ return `

exports.infosMiddleware = infosMiddleware;
const verifyEmail = (accountsPasswordOrInjector) => async (req, res) => {
try {
const { token } = req.params;
if (token == null) {
throw new Error('Token is missing');
}
const accountsPassword = accountsPasswordOrInjector instanceof accounts_password_1.default
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(accounts_password_1.default);
await accountsPassword.verifyEmail(token);
res.send(getHtml('Email successfully verified', `
exports.verifyEmail = [
(0, express_validator_1.param)('token').isString().notEmpty(),
(accountsPasswordOrInjector) => async (req, res) => {
try {
const { token } = matchOrThrow(req);
const accountsPassword = accountsPasswordOrInjector instanceof accounts_password_1.default
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(accounts_password_1.default);
await accountsPassword.verifyEmail(token);
res.send(getHtml('Email successfully verified', `
<h3>The email address has been successfully verified.</h3>
`));
}
catch (err) {
res.send(
//codeql[js/xss-through-exception]
getHtml('Email verification error', `
}
catch (err) {
res.send(
//codeql[js/xss-through-exception]
getHtml('Email verification error', `
<h3>The email address couldn't be verified: ${err.message ?? 'unknown error'}</h3>
`));
}
};
exports.verifyEmail = verifyEmail;
const resetPassword = (accountsPasswordOrInjector) => async (req, res) => {
try {
const { token, newPassword } = req.body;
if (token == null) {
throw new Error('Token is missing');
}
if (newPassword == null) {
throw new Error('New password is missing');
}
const accountsPassword = accountsPasswordOrInjector instanceof accounts_password_1.default
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(accounts_password_1.default);
await accountsPassword.resetPassword(token, newPassword, req.infos);
res.send(getHtml('Password successfully changed', `
},
];
exports.resetPassword = [
(0, express_validator_1.body)('token').isString().notEmpty(),
(0, express_validator_1.body)('newPassword').isString().notEmpty(),
(accountsPasswordOrInjector) => async (req, res) => {
try {
const { token, newPassword } = matchOrThrow(req);
const accountsPassword = accountsPasswordOrInjector instanceof accounts_password_1.default
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(accounts_password_1.default);
await accountsPassword.resetPassword(token, newPassword, req.infos);
res.send(getHtml('Password successfully changed', `
<h3>The password has been successfully changed.</h3>
`));
}
catch (err) {
//codeql[js/xss-through-exception]
res.send(getHtml('Password reset error', `
}
catch (err) {
//codeql[js/xss-through-exception]
res.send(getHtml('Password reset error', `
<h3>The password couldn't be changed: ${err.message ?? 'unknown error'}</h3>
`));
}
};
exports.resetPassword = resetPassword;
const resetPasswordForm = (req, res) => res.send(getHtml('Reset password', `
<div class="container">
<h1>Reset your password</h1>
<form action="/resetPassword" method="POST">
<input type="hidden" name="token" value=${validator_1.default.escape(req.params.token)} />
<div class="form-group">
<label for="newPassword">New password</label>
<input type="text" class="form-control" id="newPassword" value="" placeholder="Enter your new password" name="newPassword">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`));
exports.resetPasswordForm = resetPasswordForm;
}
},
];
exports.resetPasswordForm = [
(0, express_validator_1.param)('token').isString().notEmpty().escape(),
(req, res) => {
try {
const { token } = matchOrThrow(req);
res.send(getHtml('Reset password', `
<div class="container">
<h1>Reset your password</h1>
<form action="/resetPassword" method="POST">
<input type="hidden" name="token" value=${token} />
<div class="form-group">
<label for="newPassword">New password</label>
<input type="text" class="form-control" id="newPassword" value="" placeholder="Enter your new password" name="newPassword">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`));
}
catch (err) {
//codeql[js/xss-through-exception]
res.send(getHtml('Password reset error', `
<h3>The password couldn't be changed: ${err.message ?? 'unknown error'}</h3>
`));
}
},
];
//# sourceMappingURL=express.js.map
{
"name": "@accounts/password",
"version": "1.0.0-alpha-20231119094526-b1fc68c7",
"version": "1.0.0-alpha-20231120163547-4a461fcc",
"license": "MIT",

@@ -25,14 +25,13 @@ "main": "lib/index.js",

"dependencies": {
"@accounts/two-factor": "1.0.0-alpha-20231119094526-b1fc68c7",
"@accounts/two-factor": "1.0.0-alpha-20231120163547-4a461fcc",
"bcryptjs": "2.4.3",
"tslib": "2.6.2",
"validator": "^13.11.0"
"express-validator": "^7.0.1",
"tslib": "2.6.2"
},
"devDependencies": {
"@accounts/server": "1.0.0-alpha-20231119094526-b1fc68c7",
"@accounts/types": "1.0.0-alpha-20231119094526-b1fc68c7",
"@accounts/server": "1.0.0-alpha-20231120163547-4a461fcc",
"@accounts/types": "1.0.0-alpha-20231120163547-4a461fcc",
"@types/bcryptjs": "2.4.6",
"@types/express": "^4.17.21",
"@types/lodash.set": "4.3.9",
"@types/validator": "^13",
"graphql": "16.8.1",

@@ -44,3 +43,3 @@ "graphql-modules": "3.0.0-alpha-20231106133212-0b04b56e",

"peerDependencies": {
"@accounts/server": "1.0.0-alpha-20231119094526-b1fc68c7",
"@accounts/server": "1.0.0-alpha-20231120163547-4a461fcc",
"graphql": "^16.0.0",

@@ -47,0 +46,0 @@ "graphql-modules": "^3.0.0"

import { type Injector } from 'graphql-modules';
import type { Request, Response, NextFunction } from 'express';
import validator from 'validator';
import AccountsPassword from '../accounts-password';
import { body, matchedData, param, validationResult } from 'express-validator';
function matchOrThrow<T extends Record<string, any> = Record<string, any>>(
...args: Parameters<typeof matchedData>
): T {
if (!validationResult(args[0]).isEmpty()) {
throw new Error('Validation error');
}
return matchedData(...args) as T;
}
function getHtml(title: string, body: string) {

@@ -33,58 +42,89 @@ return `

export const verifyEmail =
export const verifyEmail = [
param('token').isString().notEmpty(),
(accountsPasswordOrInjector: Injector | AccountsPassword) =>
async (req: Request, res: Response) => {
try {
const { token } = req.params;
if (token == null) {
throw new Error('Token is missing');
}
const accountsPassword =
accountsPasswordOrInjector instanceof AccountsPassword
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(AccountsPassword);
await accountsPassword.verifyEmail(token);
res.send(
getHtml(
'Email successfully verified',
`
async (req: Request, res: Response) => {
try {
const { token } = matchOrThrow<{ token: string }>(req);
const accountsPassword =
accountsPasswordOrInjector instanceof AccountsPassword
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(AccountsPassword);
await accountsPassword.verifyEmail(token);
res.send(
getHtml(
'Email successfully verified',
`
<h3>The email address has been successfully verified.</h3>
`
)
);
} catch (err: any) {
res.send(
//codeql[js/xss-through-exception]
getHtml(
'Email verification error',
`
)
);
} catch (err: any) {
res.send(
//codeql[js/xss-through-exception]
getHtml(
'Email verification error',
`
<h3>The email address couldn't be verified: ${err.message ?? 'unknown error'}</h3>
`
)
);
}
};
)
);
}
},
];
export const resetPassword =
export const resetPassword = [
body('token').isString().notEmpty(),
body('newPassword').isString().notEmpty(),
(accountsPasswordOrInjector: Injector | AccountsPassword) =>
async (req: Request, res: Response) => {
async (req: Request, res: Response) => {
try {
const { token, newPassword } = matchOrThrow<{ token: string; newPassword: string }>(req);
const accountsPassword =
accountsPasswordOrInjector instanceof AccountsPassword
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(AccountsPassword);
await accountsPassword.resetPassword(token, newPassword, req.infos);
res.send(
getHtml(
'Password successfully changed',
`
<h3>The password has been successfully changed.</h3>
`
)
);
} catch (err: any) {
//codeql[js/xss-through-exception]
res.send(
getHtml(
'Password reset error',
`
<h3>The password couldn't be changed: ${err.message ?? 'unknown error'}</h3>
`
)
);
}
},
];
export const resetPasswordForm = [
param('token').isString().notEmpty().escape(),
(req: Request, res: Response) => {
try {
const { token, newPassword } = req.body;
if (token == null) {
throw new Error('Token is missing');
}
if (newPassword == null) {
throw new Error('New password is missing');
}
const accountsPassword =
accountsPasswordOrInjector instanceof AccountsPassword
? accountsPasswordOrInjector
: accountsPasswordOrInjector.get(AccountsPassword);
await accountsPassword.resetPassword(token, newPassword, req.infos);
const { token } = matchOrThrow<{ token: string }>(req);
res.send(
getHtml(
'Password successfully changed',
'Reset password',
`
<h3>The password has been successfully changed.</h3>
`
<div class="container">
<h1>Reset your password</h1>
<form action="/resetPassword" method="POST">
<input type="hidden" name="token" value=${token} />
<div class="form-group">
<label for="newPassword">New password</label>
<input type="text" class="form-control" id="newPassword" value="" placeholder="Enter your new password" name="newPassword">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`
)

@@ -103,21 +143,3 @@ );

}
};
export const resetPasswordForm = (req: Request, res: Response): Response =>
res.send(
getHtml(
'Reset password',
`
<div class="container">
<h1>Reset your password</h1>
<form action="/resetPassword" method="POST">
<input type="hidden" name="token" value=${validator.escape(req.params.token)} />
<div class="form-group">
<label for="newPassword">New password</label>
<input type="text" class="form-control" id="newPassword" value="" placeholder="Enter your new password" name="newPassword">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
`
)
);
},
];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc