我正在MEAN.js上运行一些项目,我遇到了以下问题.我想做一些用户的配置文件计算并将其保存到数据库.但是用户模型中的方法存在问题:
UserSchema.pre('save', function(next) {
if (this.password && this.password.length > 6) {
this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
this.password = this.hashPassword(this.password);
}
next();
});
Run Code Online (Sandbox Code Playgroud)
如果我将使用我的更改发送密码,它将更改凭据,因此用户下次无法登录.我想在保存之前从用户对象中删除密码,但是我无法做到(让我们看看下面代码中的注释):
exports.signin = function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err || !user) {
res.status(400).send(info);
} else {
/* Some calculations and user's object changes */
req.login(user, function(err) {
if(err) {
res.status(400).send(err);
} else {
console.log(delete user.password); // returns true
console.log(user.password); // still returns password :(
//user.save();
//res.json(user);
}
});
}
})(req, res, next);
}; …
Run Code Online (Sandbox Code Playgroud) 我有一个手机游戏,当用户结束游戏时,我希望他能够向下滚动以获得网站的其他信息。现在他做不到,因为画布正在收集所有触摸和其他输入信息:-(游戏在Pixi.js中
我有svg stroke-linecap属性的问题.我在AngularJS中有圆形进度条,我想将外圆(蓝色圆圈)设置为圆形"端".看看这个小提琴.
<svg ... height="130" width="130">
<!-- ngIf: background -->
<circle ...
ng-if="background"
fill="#fff"
class="ng-scope"
stroke-width="13"
stroke="#cc3399"
r="57.5"
cy="65"
cx="65"
stroke-linecap="round"
/>
<!-- end ngIf: background -->
<circle ...
fill="none"
stroke-dashoffset="36.12831551628261"
stroke-dasharray="361.28315516282623"
stroke-width="13"
stroke="#432db3"
stroke-linecap="round"
r="57.5"
cy="65"
cx="65"
transform="rotate(-89.9, 65, 65)"
/>
</svg>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个以这种方式定义的文件路径:
const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg";
Run Code Online (Sandbox Code Playgroud)
这是我用来加载图像的函数:
bool loadTexImage2D(const string &fileName, GLenum target) {
...
// this will load image data to the currently bound image
// at first, we must convert fileName, for ascii, this method is fine?
wstring file(fileName.begin(), fileName.end());
if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题?ilLoadImage
调用时为什么程序会掉线?我认为,file.c_str()
作为一种wchar_t *
类型应该可以正常工作吗?谢谢你的回答:)
我想修改create-react-app
service worker文件并实现弹出消息,如果新的 service worker 准备好激活,它将要求用户更新应用程序。我几乎完成了解决方案,但有一个陷阱。我想在用户确认 service worker 更新弹出窗口时重新加载应用程序,所以我在register
函数的末尾添加了一些代码,见下文:
export default function register(config) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used …
Run Code Online (Sandbox Code Playgroud) 我的Twitter API created_at date有一个大问题,它具有以下格式:Tue Apr 18 07:24:05 +0000 2017
...我想从中创建javascript Date对象,但无法找到跨浏览器的解决方案。到目前为止,我已经尝试过:
new Date(Date.parse(input.replace(/( \+)/, ' UTC$1')));
–在Safari中返回nullnew Date((input || "").replace(/-/g,"/").replace(/[TZ]/g," "));
–在IE11中返回null有人可以帮我弄清楚吗?非常感谢你!
我有以下输入:
["56", "+", "49", "-", "2", "+", "15]
Run Code Online (Sandbox Code Playgroud)
所以它是一个字符串列表,我想得到"+" - [1,5]的索引.我怎样才能实现它?