Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createUser(userData) {
// Generate a userId if not provided
if (!userData.userId) {
userData.userId = uuid()
}
if (isUndefined(userData.name)) {
userData.name = ''
}
return this.userExists(userData.userId).bind(this)
.then(function(exists) {
if (exists) {
throw new Err('UserStore.CreateError', {
message: 'User already exists.'
})
}
return this._createUser(userData)
}.bind(this))
_createUser(userData) {
// at some point we should make this more secure
let loginKey = userData.loginKey || uuid()
let record = {
userId: userData.userId,
name: userData.name,
email: userData.email,
created: new Date(),
loginKey: loginKey,
password: userData.password,
access: userData.access,
super: userData.super
}
return new Promise(function(resolve, reject) {
this.db.users.insert(record, function(err, user) {
if (err) {
return reject(new Err('UserStore.CreateError', {
addAsset (file) {
let assetId = uuid()
let [name, ext] = _getNameAndExtension(file.name)
let filePath = this._getUniqueFileName(name, ext)
// TODO: this is not ready for collab
this._manifestSession.transaction(tx => {
let assetNode = tx.create({
type: 'asset',
id: assetId,
path: filePath,
assetType: file.type
})
documentHelpers.append(tx, ['dar', 'assets'], assetNode.id)
})
this.buffer.addBlob(assetId, {
id: assetId,
path: filePath,
blob: file
constructor(exprStr) {
super()
this.id = uuid()
this.source = exprStr
this.expr = null
this.error = null
this.updateExpression(exprStr)
}
createFile(file) {
let assetId
let fileExtension = last(file.name.split('.'))
let filePath = `${uuid()}.${fileExtension}`
this._sessions.manifest.transaction(tx => {
let assets = tx.find('assets')
let asset = tx.createElement('asset').attr({
path: filePath,
type: file.type
})
assetId = asset.id
assets.appendChild(asset)
})
this.buffer.addBlob(assetId, file)
this._pendingFiles[filePath] = URL.createObjectURL(file)
return filePath
}
createSession(session) {
let sessionToken = session.sessionToken || uuid()
let newSession = {
sessionToken: sessionToken,
created: new Date(),
userId: session.userId
}
return new Promise(function(resolve, reject) {
this.db.sessions.insert(newSession, function(err, session) {
if (err) {
return reject(new Err('SessionStore.CreateError', {
cause: err
}))
}
resolve(session)
_updateLoginKey(user) {
let userStore = this.userStore
let newLoginKey = uuid()
return userStore.updateUser(user.userId, {loginKey: newLoginKey})
}
_getWorkflowId () {
return uuid()
}
constructor () {
this.id = uuid()
this.values = new Map()
this.dirty = {}
this.updates = {}
}
function Model( data ) {
Substance.EventEmitter.call(this);
this.properties = Substance.extend({}, this.getDefaultProperties(), data);
this.properties.type = this.constructor.static.name;
this.properties.id = this.properties.id || Substance.uuid(this.properties.type);
}