我需要在用户浏览器中生成一个安全的50个字符的随机字符串.
看看sjcl.prng到目前为止我有这个:
$(document).ready(function () {
sjcl.random = new sjcl.prng(8);
sjcl.random.startCollectors();
$("body").on('mousemove', function() {
console.log(sjcl.random.getProgress(8));
if(sjcl.random.isReady(8) === 2) {
sjcl.random.stopCollectors();
console.log(sjcl.random.randomWords(5,8));
}
});
});
Run Code Online (Sandbox Code Playgroud)
将鼠标移动一段时间后,我得到一个像这样的字节数组:[-579285364, 1099191484, 94979086, -1572161987, -570940948].
但我正在寻找的是一个50个字符的字母数字字符串.我对这个主题的了解有限,我在这里寻求帮助.
首先让我说这些是我在Go玩弄的第几天.
我正在尝试使用像Gorm这样的Revel框架:
app/controllers/gorm.go
package controllers
import (
"fmt"
"go-testapp/app/models"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/revel/revel"
)
var DB gorm.DB
func InitDB() {
var err error
DB, err = gorm.Open("mysql", "root:@/go-testapp?charset=utf8&parseTime=True")
if err != nil {
panic(err)
}
DB.LogMode(true)
DB.AutoMigrate(models.User{})
}
type GormController struct {
*revel.Controller
DB *gorm.DB
}
Run Code Online (Sandbox Code Playgroud)
app/controller/app.go
package controllers
import (
"fmt"
"go-bingo/app/models"
_ "github.com/go-sql-driver/mysql"
"github.com/revel/revel"
)
type App struct {
GormController
}
func (c App) Index() revel.Result {
user := models.User{Name: "Jinzhu", Age: 18}
fmt.Println(c.DB)
c.DB.NewRecord(user)
c.DB.Create(&user)
return c.RenderJson(user) …Run Code Online (Sandbox Code Playgroud) 我有一个包含许多消息的游戏模型。为了让它们实时同步,我使用了这样的计算属性:
gameMessages: function () {
var gameId, messages;
gameId = this.get('id');
return this.get('store').filter('message', function (message) {
return (message.get('game.id') === gameId);
});
}.property('messages'),
Run Code Online (Sandbox Code Playgroud)
如何限制它返回的消息数量?我只想展示 10 个最新的。
假设我有某种游戏.我有一个像这样的buyItem函数:
buyItem: function (req, res) {
// query the users balance
// deduct user balance
// buy the item
}
Run Code Online (Sandbox Code Playgroud)
如果我在扣除用户余额之前发送该路由(第二个查询),则用户的余额仍为正数.
我尝试过的:
buyItem: function (req, res) {
if(req.session.user.busy) return false;
req.session.user.busy = true;
// query the users balance
// deduct user balance
// buy the item
}
Run Code Online (Sandbox Code Playgroud)
问题是req.session.user.busy将undefined在第一〜5项要求.所以这也不起作用.
我们如何处理这种情况?我正在使用Sails.JS框架,如果这很重要的话.
concurrency ×1
ember-data ×1
ember.js ×1
express ×1
go ×1
go-gorm ×1
javascript ×1
mysql ×1
node.js ×1
prng ×1
random ×1
revel ×1
sails.js ×1
sjcl ×1