Rename user.js to users.js
This commit is contained in:
@@ -12,8 +12,8 @@ exports = module.exports = {
|
||||
var assert = require('assert'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
user = require('../user.js'),
|
||||
UserError = user.UserError,
|
||||
users = require('../users.js'),
|
||||
UserError = users.UserError,
|
||||
_ = require('underscore');
|
||||
|
||||
function auditSource(req) {
|
||||
@@ -45,7 +45,7 @@ function update(req, res, next) {
|
||||
|
||||
var data = _.pick(req.body, 'email', 'fallbackEmail', 'displayName');
|
||||
|
||||
user.update(req.user.id, data, auditSource(req), function (error) {
|
||||
users.update(req.user.id, data, auditSource(req), function (error) {
|
||||
if (error && error.reason === UserError.BAD_FIELD) return next(new HttpError(400, error.message));
|
||||
if (error && error.reason === UserError.ALREADY_EXISTS) return next(new HttpError(409, error.message));
|
||||
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found'));
|
||||
@@ -61,7 +61,7 @@ function changePassword(req, res, next) {
|
||||
|
||||
if (typeof req.body.newPassword !== 'string') return next(new HttpError(400, 'newPassword must be a string'));
|
||||
|
||||
user.setPassword(req.user.id, req.body.newPassword, function (error) {
|
||||
users.setPassword(req.user.id, req.body.newPassword, function (error) {
|
||||
if (error && error.reason === UserError.BAD_FIELD) return next(new HttpError(400, error.message));
|
||||
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(403, 'Wrong password'));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
@@ -73,7 +73,7 @@ function changePassword(req, res, next) {
|
||||
function setTwoFactorAuthenticationSecret(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
user.setTwoFactorAuthenticationSecret(req.user.id, function (error, result) {
|
||||
users.setTwoFactorAuthenticationSecret(req.user.id, function (error, result) {
|
||||
if (error && error.reason === UserError.ALREADY_EXISTS) return next(new HttpError(409, 'TwoFactor Authentication is enabled, disable first'));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
@@ -87,7 +87,7 @@ function enableTwoFactorAuthentication(req, res, next) {
|
||||
|
||||
if (!req.body.totpToken || typeof req.body.totpToken !== 'string') return next(new HttpError(400, 'totpToken must be a nonempty string'));
|
||||
|
||||
user.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, function (error) {
|
||||
users.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, function (error) {
|
||||
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found'));
|
||||
if (error && error.reason === UserError.BAD_TOKEN) return next(new HttpError(403, 'Invalid token'));
|
||||
if (error && error.reason === UserError.ALREADY_EXISTS) return next(new HttpError(409, 'TwoFactor Authentication is already enabled'));
|
||||
@@ -100,7 +100,7 @@ function enableTwoFactorAuthentication(req, res, next) {
|
||||
function disableTwoFactorAuthentication(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
user.disableTwoFactorAuthentication(req.user.id, function (error) {
|
||||
users.disableTwoFactorAuthentication(req.user.id, function (error) {
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
|
||||
Reference in New Issue
Block a user