GithubHelp home page GithubHelp logo

Comments (14)

lforge avatar lforge commented on July 18, 2024

Is there any update on this?

from jugglingdb.

tanema avatar tanema commented on July 18, 2024

I am seeing this issue as well

User.beforeCreate = function(next){
this.salt = crypto.createHmac('sha1', (new Date().getTime()) +' ').digest('hex');
this.password = crypto.createHmac('sha1', this.salt).update(this.password).digest('hex');
next();
}

but when I check the db the password is still plain text, if I do the hook as beforeSave it is fine though. But I can't use that because if I do one single callback of beforeSave the first save does not give true when I check the propertyChanged('password').

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

In my case, beforeSave only works when I update a record. When I create a new record, beforeSave does not appear to fire neither.

But beforeSave won't work because I don't want to update my date_created time stamp in this case when this is just an update operation.

It will be nice that this is fixed. I have verified that my hook is fired. But the data are not passed to the abstract_class.js and hence the db adapter class.

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

Any update on this?

from jugglingdb.

by5739 avatar by5739 commented on July 18, 2024

i meet this issue as well, i found this page from google and found it is unresolved...
at last, i found how to resolve...

in abstract-class.js, we can change like this:

AbstractClass.create = function (data, callback) {

if (stillConnecting(this.schema, this, arguments)) return;

var modelName = this.modelName;

if (typeof data === 'function') {
    callback = data;
    data = {};
}

if (typeof callback !== 'function') {
    callback = function () {};
}

var obj = null;
// if we come from save
if (data instanceof AbstractClass && !data.id) {
    obj = data;
    data = obj.toObject(true);//<-- you can comment this statement
    this.prototype._initProperties.call(obj, data, false);
    create();
} else {
    obj = new this(data);
    data = obj.toObject(true);//<-- you can comment this statement

    // validation required
    obj.isValid(function (valid) {
        if (!valid) {
            callback(new Error('Validation error'), obj);
        } else {
            create();
        }
    });
}

function create() {
    obj.trigger('create', function (done) {
        var data = this.toObject(true);//<-- add this statement here, so _adapter can get the latest data
        this._adapter().create(modelName, data, function (err, id) {
            if (id) {
                defineReadonlyProp(obj, 'id', id);
                addToCache(this.constructor, obj);
            }
            done.call(this, function () {
                if (callback) {
                    callback(err, obj);
                }
            });
        }.bind(this));
    });
}

};

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

@by5739

Yes, you did it! That line fixes the issue. Thanks!

from jugglingdb.

tanema avatar tanema commented on July 18, 2024

has this been submitted for a pull request I do not see it in the current version of the source.

from jugglingdb.

giano avatar giano commented on July 18, 2024

Please somebody reopen this. It's still present and the by5739 patch works well! Make a pull please!

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

@by5739 , would you mind making a pull for this please? If not, please send me some more details of yourself such as your name, etc so that we can give you credit for the fix in the pull request. If you pick up the fix from somewhere, please provide reference so that we can give credit the proper original owner of the fix.

I can try to issue a pull request on your behalf. I am kind of new to github. But I will try to make this work. Thanks.

from jugglingdb.

by5739 avatar by5739 commented on July 18, 2024

@lforge , thank you! I am a beginner of git, i have pull this issue, but i don't know is it enough? see from this: #87

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

@by5739,

What a pull request mean is that you fork the original code, make your change, then you can push your code back to your own github repository, then you can send the original author a pull request so that the original author can incorporate your change. Hope I explain this correctly. Like I said, I am kind of new to this. Anyway, I will check into this this weekend and see if I can make a pull request on this. Thanks.

from jugglingdb.

by5739 avatar by5739 commented on July 18, 2024

@lforge Thank you for telling me how to do that, hope you to make a pull for this, Thanks

from jugglingdb.

lforge avatar lforge commented on July 18, 2024

@by5739

Just issue a pull request for this. Let's see if this makes it to the master version. Thanks.

from jugglingdb.

by5739 avatar by5739 commented on July 18, 2024

Good!

from jugglingdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.