Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if(!validator.isPsd(userPsd) || !validator.isLength(userPsd,6,12)){
errors = "6-12位,只能包含字母、数字和下划线";
}
if(userPsd === oldPassword){
errors = "新密码和原密码不能相同";
}
if(errors){
res.end(errors)
}else{
// 密码加密
var oldPsd = DbOpt.encrypt(oldPassword,settings.encrypt_key);
var newPsd = DbOpt.encrypt(userPsd,settings.encrypt_key);
if(shortid.isValid(userId)){
User.findOne({_id:userId},function(err,user){
if(user){
// 验证是否是本人操作,提高安全性
if(oldPsd === user.password){
// 更新密码
User.update({_id:userId}, {password : newPsd}, function (err,result) {
if(err){
res.end(err);
}else{
res.end("success");
}
})
}
else{
res.end("数据有误,请稍后重试");
}
exports.enableTemp = async (req, res, next) => {
var tempId = req.query.tempId;
try {
if (!tempId || !shortid.isValid(tempId)) {
throw new Error(res.__("validate_error_params"));
}
// 重置所有模板
await contentTemplateService.updateMany(res, '', {
'using': false
})
await contentTemplateService.update(res, tempId, {
'using': true
})
// 更新缓存
let defaultTemp = await contentTemplateService.item(res, {
query: {
'using': true
},
populate: ['items']
.then(board => {
assert.isTrue(shortid.isValid(board.id));
});
});
.then(list => {
assert.isTrue(shortid.isValid(list.id));
});
});
del : function(obj,req,res,logMsg){
var params = url.parse(req.url,true);
var targetId = params.query.uid;
if(shortid.isValid(targetId)){
obj.remove({_id : params.query.uid},function(err,result){
if(err){
res.end(err);
}else{
console.log(logMsg+" success!");
res.end("success");
}
})
}else{
res.end(settings.system_illegal_param);
}
},
findAll : function(obj,req,res,logMsg){//查找指定对象所有记录
checkCateList() {
let typeId = this.$route.params.typeId
return typeId != 'indexPage' && shortid.isValid(typeId);
},
currentCate() {
updateCategoryTemps : function(req,res,cateId){
if(shortid.isValid(cateId)){
var cateQuery = {'sortPath': { $regex: new RegExp(cateId, 'i') }};
ContentCategory.update(cateQuery,{$set:{contentTemp:req.body.contentTemp}},{multi : true},function(err){
if(err){
res.end(err);
}
})
}else{
res.end(settings.system_illegal_param);
}
},
//根据Id查询类别信息
delNotifiesById : function(req,res,nid,callBack){
if(shortid.isValid(nid)){
Notify.delOneNotify(res,nid,function(){
var notifyQuery = {'notify': { $regex: new RegExp(nid, 'i') }};
UserNotify.remove(notifyQuery,function(err){
if(err){
res.end(err);
}else{
callBack();
}
});
});
}else{
res.end(settings.system_illegal_param);
}
},
async getMyContent(req, res, next) {
try {
let targetId = req.query.id;
if (!shortid.isValid(targetId)) {
throw new siteFunc.UserException(res.__('validate_error_params'));
}
let queryObj = {
_id: targetId,
uAuthor: req.session.user._id
};
const content = await ContentModel.findOne(queryObj).populate([{
path: 'author',
select: 'userName _id id logo'
},
{
path: 'uAuthor',
select: 'userName name logo _id group'
},
async getDataForEditContent() {
const ctx = this.ctx;
let contentId = ctx.params.id;
if (!shortid.isValid(contentId)) {
ctx.redirect("/users/userCenter");
} else {
let contentInfo = await ctx.helper.reqJsonData('content/getContent', {
id: contentId,
userId: ctx.session.user._id,
token: ctx.session.user.token
});
if (!_.isEmpty(contentInfo)) {
ctx.tempPage = 'users/userAddContent.html';
ctx.pageType = 'editContent';
ctx.title = "编辑创作";
ctx.contentId = contentId;
await this.getPageData(this);
} else {
ctx.redirect("/users/userCenter");
}