How to use shortid - 10 common examples

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 Restuta / rcn.io / src / shared / _packages / events-core / gen-event-id.js View on Github external
/*
generate id manually by hitting
https://rcn.io/admin/create-event-id
*/

const slugify = require('shared/utils/slugify')
const shortid = require('shortid')
// custom alphabet, since by default it includes "-" which we are using as a separator as well
// must include 64 distinct characters
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$')

//so we don't end-up with crazy long URLs, 100 is pessimistic for really long event names
const MAX_SLUG_LENGTH = 100

/**
 * Creates just a prefix of the event id without unique id part
 * @param {[type]} eventYear Yeah this even is taking place at
 * @param {[type]} eventName Name of the event
 * @param {[type]} shortSegmentName Typically used to improve event identificaiton
 * by just looking at it id, for example for NCNCA it would be "ncnca"
 * @returns {[type]} String
 */
const createEventIdPrefix = (eventYear, eventName, shortSegmentName) =>
  shortSegmentName
    ? `evt-${shortSegmentName}-${eventYear}-${slugify(eventName, MAX_SLUG_LENGTH)}`
    : `evt-${eventYear}-${slugify(eventName, MAX_SLUG_LENGTH)}`
github sirceljm / aws-lambda-blog / lambdas / src / admin / upload_image.js View on Github external
// uploadImage
var co = require('co');
var shortid = require('shortid');
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');

var imageSize = require('image-size');
var Jimp = require("jimp");

var AWS = require('aws-sdk');
var docClient = new AWS.DynamoDB.DocumentClient();
var s3 = new AWS.S3({
    signatureVersion: 'v4'
});

var auth = require('../../lib/auth.js');
var dynamoObjects = require('../../lib/dynamoObjects.js');

exports.handler = (event, context, callback) => {
    // STAGE VARIABLES FROM API GATEWAY
    var stage = event.stage;
github jsonmvc / jsonmvc / src / views.js View on Github external
const Vue = require('vue/dist/vue.common.js')
const Emitter = require('events').EventEmitter
const most = require('most')
const shortid = require('shortid')
const PROP_REGEX = /<([a-z]+)>/g
const _ = require('lodash')

shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%^')

function updateInstanceData(db, schema, props, data, self, prop, val) {

  // Unsubscribe all listeners for this prop
  props.schema.subscribes[prop].forEach(y => y())
  props.schema.subscribes[prop] = []

  // For all the paths that are impacted by this prop
  props.schema.tokens[prop].props.forEach(x => {
    let path = getPath(schema, props, self, x)

    let listener = createDataListener(db, path, data, x)

    props.schema.subscribes[prop].push(listener)
  })
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 vinz243 / cassette / src / server / features / jobs / JobTorrent.js View on Github external
constructor (props) {
    this.props = Object.assign({}, this.defaultProps, props);
    assert(/^(\d|[a-f]){40}$/i.test(this.props.infoHash));

    if (!this.props._id) {
      this.props._id = shortid.generate();
    }
  }
  getData() {
github topcoder-platform / community-app / src / shared / containers / SubmissionPage.jsx View on Github external
getCommunitiesList: (auth) => {
      const uuid = shortId();
      dispatch(ca.getListInit(uuid));
      dispatch(ca.getListDone(uuid, auth));
    },
    submit: (tokenV3, tokenV2, submissionId, body, track) => {
github samuelmaddock / metastream / app / renderer / lobby / actions / mediaPlayer.ts View on Github external
try {
    res = await resolveMediaUrl(url)
  } catch (e) {
    console.error(e)
  }

  if (!res) {
    console.log(`Failed to fetch media for ${url}`)
    return null
  }

  console.log('Media response', res)

  const userId = context.client.id.toString()
  const media: IMediaItem = {
    id: shortid(),
    type: res.type,
    url: res.url,
    title: res.title || res.url,
    duration: res.duration,
    description: res.description,
    imageUrl: res.thumbnails && res.thumbnails[MediaThumbnailSize.Default],
    requestUrl: url,
    ownerId: userId,
    ownerName: getUserName(getState(), userId),
    hasMore: res.hasMore
  }

  if (res.state) {
    media.state = res.state
  }

shortid

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

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis