- 用户名+ 密码 =》 id + token
- str = [参数, random_number] 字典升序.join('')
- sign = md5( id + str + token);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp').factory('_', function(){ | |
return window._; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateRandomAlphaNum(len) { | |
var rdmString = ""; | |
for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2)); | |
return rdmString.substr(0, len); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res.type = function(type){ | |
return this.set('Content-Type', ~type.indexOf('/') | |
? type | |
: mime.lookup(type)); | |
}; | |
# 判断Cotent-Type中是否有/,比如application/json | |
# 如果有就去查询mime | |
# 在js中, null, undefined , '' 以及0都是false | |
# ~-1 === 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 将一个10进制的数字字符串转换成36进制 | |
*/ | |
function to36 (str) { | |
return Number(str).toString(36); | |
} | |
/** | |
* 从36进制的字符串转换成10进制 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ONLY TO MAKE $RESPONSE EASY TO USE | |
* in some case, Backend will respond every request with a 200 http status code | |
* and [error_or_not, data] array. | |
* It's very difficult to use when writing front-end code with angular. | |
* | |
* The purpose of this module is to transform it to legal one | |
*/ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var shasum = crypto.createHash('sha1'); // this will return a hash object | |
// It is a stream that is both readable and writable. The written data is used to compute the hash. | |
// Once the writable side of the stream is ended, use the read() method to get the computed hash digest. | |
// The legacy update and digest methods are also supported. | |
shasum.update('some data needs to be hashed and can be called many times'); | |
console.log(shasum.digest('hex')); | |
// hex, binary or base, a buffer is returned is no encoding provided |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var makeSalt = function() { | |
return crypto.randomBytes(16).toString('base64'); | |
}; | |
var hashPassword = function(password){ | |
var salt = new Buffer(makeSalt, 'base64'); | |
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.btn-container-selector ~ .btn-container-selector > .btn-container { | |
border-left: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// connect mongodb | |
var mongoose = require('mongoose'); | |
// 见https://github.com/LearnBoost/mongoose/issues/1251 | |
mongoose.models = {}; | |
mongoose.modelSchemas = {}; | |
var clearDB = function(done){ | |
async.parallel([ | |
function (cb) { | |
Coupon.collection.remove(cb) |
OlderNewer