@qubejs/cms
Advanced tools
Comparing version 0.4.0 to 0.5.0-beta.1
{ | ||
"name": "@qubejs/cms", | ||
"version": "0.4.0", | ||
"version": "0.5.0-beta.1", | ||
"dependencies": { | ||
@@ -9,6 +9,3 @@ "tslib": "^2.3.0" | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts", | ||
"scripts": { | ||
"publish-package": "npm version minor && pnpm publish --no-git-checks" | ||
} | ||
"typings": "./src/index.d.ts" | ||
} |
@@ -1,23 +0,21 @@ | ||
const utils = require('../utils'); | ||
var { getSettings } = require('../settings'); | ||
const tokenManager = require('../tokenManager'); | ||
const settings = getSettings(); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const core_1 = require("../../../core/src"); | ||
const settings_1 = tslib_1.__importDefault(require("../settings")); | ||
const settings = settings_1.default.getSettings(); | ||
const URL_CONFIG = { | ||
LOGIN: settings.urlMapping['login'], | ||
LOGIN: settings.urlMapping['login'], | ||
}; | ||
class UrlRepository { | ||
constructor() { | ||
this.init(); | ||
} | ||
init() {} | ||
getDefaultUrls() { | ||
return { | ||
loginUrl: utils.url.create(URL_CONFIG.LOGIN), | ||
}; | ||
} | ||
constructor() { | ||
this.init(); | ||
} | ||
init() { } | ||
getDefaultUrls() { | ||
return { | ||
loginUrl: core_1.utils.url.create(URL_CONFIG.LOGIN), | ||
}; | ||
} | ||
} | ||
module.exports = UrlRepository; | ||
exports.default = UrlRepository; |
@@ -1,49 +0,36 @@ | ||
const BaseRepository = require('../BaseRepository'); | ||
class UserPreferenceRepository extends BaseRepository { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
collection: 'userPreferences' | ||
}); | ||
} | ||
getByUser(userId) { | ||
return this.findOne({ | ||
createdBy: userId | ||
}).then((doc) => { | ||
return doc || {}; | ||
}); | ||
} | ||
save(preference, userId) { | ||
var newPref; | ||
var that = this; | ||
return new Promise((resolve) => { | ||
this.find({ | ||
createdBy: userId | ||
}).then(async (prefs) => { | ||
if (!prefs || prefs.length === 0) { | ||
newPref = { | ||
...preference, | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const BaseRepository_1 = tslib_1.__importDefault(require("../repositories/BaseRepository")); | ||
class UserPreferenceRepository extends BaseRepository_1.default { | ||
constructor(options) { | ||
super(Object.assign(Object.assign({}, options), { collection: 'userPreferences' })); | ||
} | ||
getByUser(userId) { | ||
return this.findOne({ | ||
createdBy: userId | ||
}; | ||
const insertedCat = await that.insert(newPref); | ||
resolve({ | ||
...insertedCat | ||
}); | ||
} else { | ||
var result = await this.update({ | ||
...preference, | ||
uid: prefs[0].uid | ||
}); | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
} | ||
}).then((doc) => { | ||
return doc || {}; | ||
}); | ||
} | ||
save(preference, userId) { | ||
var newPref; | ||
var that = this; | ||
return new Promise((resolve) => { | ||
this.find({ | ||
createdBy: userId | ||
}).then((prefs) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!prefs || prefs.length === 0) { | ||
newPref = Object.assign(Object.assign({}, preference), { createdBy: userId }); | ||
const insertedCat = yield that.insert(newPref); | ||
resolve(Object.assign({}, insertedCat)); | ||
} | ||
else { | ||
var result = yield this.update(Object.assign(Object.assign({}, preference), { uid: prefs[0].uid })); | ||
resolve(result); | ||
} | ||
})); | ||
}); | ||
} | ||
} | ||
module.exports = UserPreferenceRepository; | ||
exports.default = UserPreferenceRepository; |
@@ -1,247 +0,216 @@ | ||
const _bcrypt = require('bcryptjs'); | ||
var utils = require('../utils'); | ||
const BaseRepository = require('../BaseRepository'); | ||
// const MailRepository = require('./MailRepository'); | ||
const UserSessionRepository = require('./UserSessionRepository'); | ||
const UrlRepository = require('./UrlRepository'); | ||
const errors = require('../Error'); | ||
const appConfig = require('../settings'); | ||
class UserRepository extends BaseRepository { | ||
constructor({ | ||
urlRepo = new UrlRepository(), | ||
bcrypt = _bcrypt, | ||
...options | ||
} = {}) { | ||
super({ | ||
...options, | ||
collection: 'users', | ||
}); | ||
this.sessionRepo = new UserSessionRepository(options); | ||
this.urlRepo = urlRepo; | ||
this.bcrypt = bcrypt; | ||
} | ||
getAll() { | ||
return this.find().then((arr) => arr.map((i) => i.toObject())); | ||
} | ||
getUserById(uid) { | ||
return this.findOne({ | ||
_id: uid, | ||
}).then((user) => { | ||
if (user && user.countryCode) { | ||
user.country = this.countryRepo.getByIsoCode(user.countryCode); | ||
} | ||
return user; | ||
}); | ||
} | ||
getUserByEmail(email) { | ||
return this.findOne({ | ||
email: utils.filter.ignoreCase(email), | ||
}); | ||
} | ||
verifyEmail(uid) { | ||
return new Promise(async (resolve, reject) => { | ||
const user = await this.getUserById(uid).catch(reject); | ||
if (user.emailVerified === true) { | ||
reject(errors.emailalreadyverified()); | ||
return; | ||
} | ||
await this.update({ | ||
uid, | ||
emailVerified: true, | ||
}); | ||
resolve({ | ||
...user, | ||
emailVerified: true, | ||
}); | ||
}); | ||
} | ||
resetPassword(uid, password) { | ||
var hashedPassword = this.bcrypt.hashSync(password, 10); | ||
return this.update({ | ||
uid, | ||
password: hashedPassword, | ||
emailVerified: true, | ||
}).then((user) => { | ||
this.mailRepo.sendEmail('passwordchanged', user.email, { | ||
...user, | ||
}); | ||
}); | ||
} | ||
resendVerifyEmail(userName) { | ||
return new Promise((resolve) => { | ||
this.find({ | ||
$or: [ | ||
{ phone: userName }, | ||
{ email: utils.filter.ignoreCase(userName) }, | ||
], | ||
}).then(async (users) => { | ||
if (users && users.length > 0) { | ||
if (users[0].emailVerified !== true) { | ||
this.mailRepo.sendEmail('verifyemail', users[0].email, { | ||
...users[0], | ||
verifyLinkUrl: this.urlRepo.createEmailVerifyLink(users[0].uid), | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const bcryptjs_1 = tslib_1.__importDefault(require("bcryptjs")); | ||
const core_1 = require("../../../core/src"); | ||
const dbutils = tslib_1.__importStar(require("../dbutils")); | ||
const BaseRepository_1 = tslib_1.__importDefault(require("./BaseRepository")); | ||
// import MailRepository from './MailRepository'; | ||
const UserSessionRepository_1 = tslib_1.__importDefault(require("./UserSessionRepository")); | ||
const UrlRepository_1 = tslib_1.__importDefault(require("./UrlRepository")); | ||
const settings_1 = tslib_1.__importDefault(require("../settings")); | ||
class UserRepository extends BaseRepository_1.default { | ||
constructor(_a = {}) { | ||
var { urlRepo = new UrlRepository_1.default(), bcrypt = bcryptjs_1.default } = _a, options = tslib_1.__rest(_a, ["urlRepo", "bcrypt"]); | ||
super(Object.assign(Object.assign({}, options), { collection: 'users' })); | ||
this.settings = settings_1.default.getSettings(); | ||
this.sessionRepo = new UserSessionRepository_1.default(options); | ||
this.urlRepo = urlRepo; | ||
this.bcrypt = bcrypt; | ||
} | ||
getAll() { | ||
return this.find().then((arr) => arr.map((i) => i.toObject())); | ||
} | ||
getUserById(uid) { | ||
return this.findOne({ | ||
_id: uid, | ||
}).then((user) => { | ||
if (user && user.countryCode) { | ||
user.country = this.countryRepo.getByIsoCode(user.countryCode); | ||
} | ||
return user; | ||
}); | ||
} | ||
getUserByEmail(email) { | ||
return this.findOne({ | ||
email: dbutils.filter.ignoreCase(email), | ||
}); | ||
} | ||
verifyEmail(uid) { | ||
return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const user = yield this.getUserById(uid).catch(reject); | ||
if (user.emailVerified === true) { | ||
reject(core_1.Errors.emailalreadyverified()); | ||
return; | ||
} | ||
yield this.update({ | ||
uid, | ||
emailVerified: true, | ||
}); | ||
} | ||
} | ||
resolve({ | ||
emailSent: true, | ||
resolve(Object.assign(Object.assign({}, user), { emailVerified: true })); | ||
})); | ||
} | ||
resetPassword(uid, password) { | ||
const hashedPassword = this.bcrypt.hashSync(password, 10); | ||
return this.update({ | ||
uid, | ||
password: hashedPassword, | ||
emailVerified: true, | ||
}).then((user) => { | ||
this.mailRepo.sendEmail('passwordchanged', user.email, Object.assign({}, user)); | ||
}); | ||
}); | ||
}); | ||
} | ||
sendResetPasswordEmail(userName) { | ||
return new Promise((resolve) => { | ||
this.find({ | ||
$or: [ | ||
{ phone: userName }, | ||
{ email: utils.filter.ignoreCase(userName) }, | ||
], | ||
}).then(async (users) => { | ||
if (users && users.length > 0) { | ||
this.mailRepo.sendEmail('resetpassword', users[0].email, { | ||
...users[0], | ||
resetPasswordLink: this.urlRepo.createResetPasswordLink( | ||
users[0].uid | ||
), | ||
}); | ||
} | ||
resolve({ | ||
emailSent: true, | ||
} | ||
resendVerifyEmail(userName) { | ||
return new Promise((resolve) => { | ||
this.find({ | ||
$or: [ | ||
{ phone: userName }, | ||
{ email: dbutils.filter.ignoreCase(userName) }, | ||
], | ||
}).then((users) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (users && users.length > 0) { | ||
if (users[0].emailVerified !== true) { | ||
this.mailRepo.sendEmail('verifyemail', users[0].email, Object.assign(Object.assign({}, users[0]), { verifyLinkUrl: this.urlRepo.createEmailVerifyLink(users[0].uid) })); | ||
} | ||
} | ||
resolve({ | ||
emailSent: true, | ||
}); | ||
})); | ||
}); | ||
}); | ||
}); | ||
} | ||
validate(userName, password) { | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
$or: [{ email: utils.filter.ignoreCase(userName) }], | ||
}).then(async (users) => { | ||
if (!users || users.length === 0) { | ||
reject(errors.invalidcred()); | ||
} else { | ||
var result = this.bcrypt.compareSync(password, users[0].password); | ||
if (result === true) { | ||
if (users[0].active === false) { | ||
reject(errors.inactive()); | ||
} else if ( | ||
(users[0].emailVerified === true && | ||
appConfig.verifyEmailFeature) || | ||
!appConfig.verifyEmailFeature | ||
) { | ||
await this.sessionRepo.logSession(users[0].uid, true); | ||
resolve({ | ||
loginStatus: 'ok', | ||
user: users[0], | ||
}); | ||
} else { | ||
await this.sessionRepo.logSession(users[0].uid, true); | ||
resolve({ | ||
loginStatus: 'otp', | ||
source: 'email', | ||
user: users[0], | ||
}); | ||
// reject(errors.emailnotverified()); | ||
} | ||
} else { | ||
await this.sessionRepo.logSession(users[0].uid, false); | ||
reject(errors.invalidcred()); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
save(user, userId) { | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
_id: userId, | ||
}).then(async (users) => { | ||
if (!users || users.length === 0) { | ||
reject(errors.nodata()); | ||
} else { | ||
var result = await this.update({ | ||
} | ||
sendResetPasswordEmail(userName) { | ||
return new Promise((resolve) => { | ||
this.find({ | ||
$or: [ | ||
{ phone: userName }, | ||
{ email: dbutils.filter.ignoreCase(userName) }, | ||
], | ||
}).then((users) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (users && users.length > 0) { | ||
this.mailRepo.sendEmail('resetpassword', users[0].email, Object.assign(Object.assign({}, users[0]), { resetPasswordLink: this.urlRepo.createResetPasswordLink(users[0].uid) })); | ||
} | ||
resolve({ | ||
emailSent: true, | ||
}); | ||
})); | ||
}); | ||
} | ||
validate(userName, password) { | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
$or: [{ email: dbutils.filter.ignoreCase(userName) }], | ||
}).then((users) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!users || users.length === 0) { | ||
reject(core_1.Errors.invalidcred()); | ||
} | ||
else { | ||
var result = this.bcrypt.compareSync(password, users[0].password); | ||
if (result === true) { | ||
if (users[0].active === false) { | ||
reject(core_1.Errors.inactive()); | ||
} | ||
else if ((users[0].emailVerified === true && | ||
this.settings.verifyEmailFeature) || | ||
!this.settings.verifyEmailFeature) { | ||
yield this.sessionRepo.logSession(users[0].uid, true); | ||
resolve({ | ||
loginStatus: 'ok', | ||
user: users[0], | ||
}); | ||
} | ||
else { | ||
yield this.sessionRepo.logSession(users[0].uid, true); | ||
resolve({ | ||
loginStatus: 'otp', | ||
source: 'email', | ||
user: users[0], | ||
}); | ||
// reject(errors.emailnotverified()); | ||
} | ||
} | ||
else { | ||
yield this.sessionRepo.logSession(users[0].uid, false); | ||
reject(core_1.Errors.invalidcred()); | ||
} | ||
} | ||
})); | ||
}); | ||
} | ||
save(user, userId) { | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
_id: userId, | ||
}).then((users) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!users || users.length === 0) { | ||
reject(core_1.Errors.nodata()); | ||
} | ||
else { | ||
var result = yield this.update({ | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
roleCode: user.roleCode, | ||
phone: user.phone, | ||
uid: users[0].uid, | ||
}); | ||
resolve(result.toObject()); | ||
} | ||
})); | ||
}); | ||
} | ||
insertUser(userObj) { | ||
var user; | ||
var that = this; | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
$or: [{ email: dbutils.filter.ignoreCase(userObj.email) }], | ||
}).then((users) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!userObj.password) { | ||
userObj.password = core_1.utils.number.getRandomS6(); | ||
userObj.forceChangePassword = true; | ||
} | ||
var hashedPassword = this.bcrypt.hashSync(userObj.password, 10); | ||
if (!users || users.length === 0) { | ||
user = { | ||
firstName: userObj.firstName, | ||
lastName: userObj.lastName, | ||
userId: userObj.email, | ||
email: userObj.email, | ||
phone: userObj.phone, | ||
roleCode: userObj.roleCode, | ||
emailVerified: false, | ||
phoneVerified: false, | ||
password: hashedPassword, | ||
forceChangePassword: !!userObj.forceChangePassword, | ||
active: false, | ||
}; | ||
const insertedUser = yield this.insert(user); | ||
// this.mailRepo.sendEmail('welcome', user.email, { | ||
// ...user, | ||
// }); | ||
resolve(Object.assign(Object.assign({}, insertedUser.toObject()), { password: undefined })); | ||
} | ||
else { | ||
var errorSend = Object.assign(Object.assign({}, core_1.Errors.duprecord()), { errors: {} }); | ||
if (users[0].email.toLowerCase() === userObj.email.toLowerCase()) { | ||
errorSend.errors.email = { | ||
error: true, | ||
errorMessage: 'Email already registered', | ||
}; | ||
} | ||
reject(errorSend); | ||
} | ||
})); | ||
}); | ||
} | ||
info(user) { | ||
return { | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
roleCode: user.roleCode, | ||
phone: user.phone, | ||
uid: users[0].uid, | ||
}); | ||
resolve(result.toObject()); | ||
} | ||
}); | ||
}); | ||
} | ||
insertUser(userObj) { | ||
var user; | ||
var that = this; | ||
return new Promise((resolve, reject) => { | ||
this.find({ | ||
$or: [{ email: utils.filter.ignoreCase(userObj.email) }], | ||
}).then(async (users) => { | ||
if (!userObj.password) { | ||
userObj.password = utils.number.getRandomS6(); | ||
userObj.forceChangePassword = true; | ||
} | ||
var hashedPassword = this.bcrypt.hashSync(userObj.password, 10); | ||
if (!users || users.length === 0) { | ||
user = { | ||
firstName: userObj.firstName, | ||
lastName: userObj.lastName, | ||
userId: userObj.email, | ||
email: userObj.email, | ||
phone: userObj.phone, | ||
roleCode: userObj.roleCode, | ||
emailVerified: false, | ||
phoneVerified: false, | ||
password: hashedPassword, | ||
forceChangePassword: !!userObj.forceChangePassword, | ||
active: false, | ||
}; | ||
const insertedUser = await this.insert(user); | ||
// this.mailRepo.sendEmail('welcome', user.email, { | ||
// ...user, | ||
// }); | ||
resolve({ | ||
...insertedUser.toObject(), | ||
password: undefined, | ||
}); | ||
} else { | ||
var errorSend = { | ||
...errors.duprecord(), | ||
errors: {}, | ||
}; | ||
if (users[0].email.toLowerCase() === userObj.email.toLowerCase()) { | ||
errorSend.errors.email = { | ||
error: true, | ||
errorMessage: 'Email already registered', | ||
}; | ||
} | ||
reject(errorSend); | ||
} | ||
}); | ||
}); | ||
} | ||
info(user) { | ||
return { | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
roleCode: user.roleCode, | ||
email: user.email, | ||
uid: user.uid, | ||
}; | ||
} | ||
email: user.email, | ||
uid: user.uid, | ||
}; | ||
} | ||
} | ||
module.exports = UserRepository; | ||
exports.default = UserRepository; |
@@ -1,20 +0,18 @@ | ||
const BaseRepository = require('../BaseRepository'); | ||
class UserSessionRepository extends BaseRepository { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
collection: 'userSessions' | ||
}); | ||
} | ||
async logSession(userGuid, success) { | ||
return await this.insert({ | ||
userGuid, | ||
success | ||
}); | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const BaseRepository_1 = tslib_1.__importDefault(require("../repositories/BaseRepository")); | ||
class UserSessionRepository extends BaseRepository_1.default { | ||
constructor(options) { | ||
super(Object.assign(Object.assign({}, options), { collection: 'userSessions' })); | ||
} | ||
logSession(userGuid, success) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield this.insert({ | ||
userGuid, | ||
success | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = UserSessionRepository; | ||
exports.default = UserSessionRepository; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 3 instances in 1 package
10749278
361
116974
10