小编The*_*e E的帖子

为什么我不能访问mongoose模式的方法?

我在Nodejs应用程序中有这个Mongoose模式:

const mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    sodium = require('sodium').api;

const UserSchema = new Schema({
    username: {
        type: String,
        required: true,
        index: { unique: true }
    },
    salt: {
        type: String,
        required: false
    },
    password: {
        type: String,
        required: true
    }
});

UserSchema.methods.comparePassword = function(candidatePassword, targetUser) {
    let saltedCandidate = candidatePassword + targetUser.salt;
    if (sodium.crypto_pwhash_str_verify(saltedCandidate, targetUser.password)) {
        return true;
    };
    return false;
};

module.exports = mongoose.model('User', UserSchema);
Run Code Online (Sandbox Code Playgroud)

我创建了这个路由文件.

const _ = require('lodash');
const User = require('../models/user.js'); // yes, this …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js mongoose-populate

4
推荐指数
1
解决办法
2085
查看次数

Git 强制使用 HTTPS

我创建了一个 GitHub 存储库,然后使用 SSH 克隆它:

git clone git@github.com:BenReilly/all-the-characters.git
Run Code Online (Sandbox Code Playgroud)

我添加了一些文件。

git add .
git commit -m "some message"
git push
Run Code Online (Sandbox Code Playgroud)

这导致系统提示我输入用户名和密码。这本身就有点奇怪,但我还是输入了它们。然后我得到:

> remote: Anonymous access to BenReilly/all-the-characters.git denied.
> fatal: Authentication failed for 'https://github.com/BenReilly/all-the-characters.git/'
Run Code Online (Sandbox Code Playgroud)

HTTPS?什么?

git remote -v
> origin  https://github.com/BenReilly/all-the-characters.git (fetch)
> origin  https://github.com/BenReilly/all-the-characters.git (push)
Run Code Online (Sandbox Code Playgroud)

啊。

git remote set-url origin git@github.com:BenReilly/all-the-characters.git
git remote -v
> origin  https://github.com/BenReilly/all-the-characters.git (fetch)
> origin  https://github.com/BenReilly/all-the-characters.git (push)
Run Code Online (Sandbox Code Playgroud)

这是因为它不在我的 osxkeychain 中吗?

只是为了确保我这样做ssh-add -K ~/.ssh/<key id>并确保~/.ssh/config文件已定义。行为没有改变。我还验证了密钥位于我的 GitHub 设置中。

我使用的是 MacOS Mojave (10.14.1),使用 Git …

git ssh github macos-mojave

3
推荐指数
1
解决办法
1万
查看次数

以角度解决包裹的承诺

我对角度很新,而且我被推进了一个相当大的项目.我有一个情况,我已简化为以下代码:

var beforeClose = function() {
    var closeDeferred = $q.defer(),
    a = $q.defer(),
    b = $q.defer(),
    c = $q.defer(),
    promiseArray = [a.promise, b.promise, c.promise];

    /* logic that resolves or rejects a, b, and c */

    $q.all(promiseArray).then(
        function() {
            closeDeferred.resolve();
        },
        function() {
            closeDeferred.reject();
        }
    );
    return closeDeferred.promise;
}

var modalClose = function() {
    beforeClose().then(
        function() {
            //close the modal
        },
        function() {
            //warn and don't close modal
        }
    )
}
Run Code Online (Sandbox Code Playgroud)

使用Chrome的DevTools,似乎代码完全解决或拒绝之前返回了closeDeferred承诺.所以我猜我的问题是这样的, promiseArray

什么时候承诺退回?可以在解决或拒绝之前退回吗?如果没有,我怎么能阻止它返回?

将return语句放入函数(例如,在 …

javascript angularjs angular-promise

1
推荐指数
1
解决办法
676
查看次数

灰烬初始化无法识别_super

所以我的应用程序具有这个component.js:

import Component from '@ember/component';
import layout from './template';
export default class MyComponent extends Component {
    layout = layout;

    init() {
        this._super(...arguments);
    }
}
Run Code Online (Sandbox Code Playgroud)

呈现组件时,我在chrome控制台中收到此错误:

Assertion Failed: You must call `this._super(...arguments);` when overriding `init` on a framework object. Please update <savings-toolkit@component:my-component::ember2445> to call `this._super(...arguments);` from `init`.

内容未加载。我希望我能说更多,但说真的,这到底是什么?

是的,当我开始时,最初内容更多。然而,这实际上只是以上内容。

components ember.js

1
推荐指数
1
解决办法
144
查看次数