How to use the shortid.isValid function in shortid

To help you get started, we’ve selected a few shortid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github doramart / DoraCMS / routes / users.js View on Github external
}
        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("数据有误,请稍后重试");
                        }
github doramart / DoraCMS / server / lib / controller / manage / contentTemplate.js View on Github external
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']
github 1ven / do / test / server / models / Board.spec.js View on Github external
.then(board => {
          assert.isTrue(shortid.isValid(board.id));
        });
    });
github 1ven / do / test / server / models / List.spec.js View on Github external
.then(list => {
          assert.isTrue(shortid.isValid(list.id));
        });
    });
github doramart / DoraCMS / models / Dbopt.js View on Github external
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){//查找指定对象所有记录
github doramart / DoraCMS / src / index / views / ArticleList.vue View on Github external
checkCateList() {
                let typeId = this.$route.params.typeId
                return typeId != 'indexPage' && shortid.isValid(typeId);
            },
            currentCate() {
github doramart / DoraCMS / models / ContentCategory.js View on Github external
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查询类别信息
github doramart / DoraCMS / models / db / adminFunc.js View on Github external
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);
        }

    },
github doramart / DoraCMS / server / lib / controller / content.js View on Github external
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'
                },
github doramart / DoraCMS / app / controller / page / home.js View on Github external
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");
            }

shortid

Amazingly short non-sequential url-friendly unique id generator.

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis