Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
controller.silent = async function (req) {
const UserModel = ctx.models.UserModel || ctx.models.User;
const params = req.allParams();
if (params.username) params.username = canonize(params.username);
if (params.email) params.email = canonize(params.email);
const username = `__s${Date.now()}__`;
const user = new UserModel(Object.assign({
username,
type: 'silent',
}, params));
await user.save();
req.user = user;
return {
__pack: 1,
signup: true,
user: await UserModel.prepare(user, { req, withAppState: true }),
token: user.generateAuthToken(),
};
};
// get for create
controller.silent = async function (req) {
const UserModel = ctx.models.UserModel || ctx.models.User;
const params = req.allParams();
if (params.username) params.username = canonize(params.username);
if (params.email) params.email = canonize(params.email);
const username = `__s${Date.now()}__`;
const user = new UserModel(Object.assign({
username,
type: 'silent',
}, params));
await user.save();
req.user = user;
return {
__pack: 1,
signup: true,
user: await UserModel.prepare(user, { req, withAppState: true }),
token: user.generateAuthToken(),
};
};
// get for create
const params = req.allParams();
if (params.username) {
return {
username: canonize(params.username),
};
}
if (params.email) {
return {
email: canonize(params.email),
};
}
if (params.login) {
return {
$or: [
{
username: canonize(params.login),
},
{
email: canonize(params.login),
},
],
};
}
throw this.app.errors.e400('Параметр username, email, login не передан');
}
controller.getUserCriteria = function (req) {
const params = req.allParams();
if (params.username) {
return {
username: canonize(params.username),
};
}
if (params.email) {
return {
email: canonize(params.email),
};
}
if (params.login) {
return {
$or: [
{
username: canonize(params.login),
},
{
email: canonize(params.login),
},
username: canonize(params.username),
};
}
if (params.email) {
return {
email: canonize(params.email),
};
}
if (params.login) {
return {
$or: [
{
username: canonize(params.login),
},
{
email: canonize(params.login),
},
],
};
}
throw this.app.errors.e400('Параметр username, email, login не передан');
}
getUserCriteria(req) {
const params = req.allParams();
if (params.username) {
return {
username: canonize(params.username),
};
}
if (params.email) {
return {
email: canonize(params.email),
};
}
if (params.login) {
return {
$or: [
{
username: canonize(params.login),
},
{
email: canonize(params.login),
},