How to use the wilson/models.model function in wilson

To help you get started, we’ve selected a few wilson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chrisdickinson / wilson / tests / application.js View on Github external
function(assert) {
        "ApplicationInstance.resolveModels triggers any resolvers with the name of an instantiated model class";
        var randomTag = 'random'+Math.random(),
            randomName = 'randomName'+Math.random(),
            ourAppOptions = {
                'models':{'FakeModel':models.model({'field':models.CharField({'max_length':255})})}
            };
            app = application.app(ourAppOptions),
            appInstance = app.instantiate(randomName+Math.random()),
            trigger = 0;
        appInstance.resolvers = {
            'FakeModel':[function(model) {
                assert.strictEqual(appInstance.models.FakeModel, model);
                ++trigger;
            }]
        };
        appInstance.resolveModels();
        assert.equal(trigger, 1);
    }
);
github chrisdickinson / wilson / lib / contrib / sessions / models.js View on Github external
var models = require('wilson/models'),
    settings = require('wilson/conf').settings,
    Buffer = require('buffer').Buffer,
    crypto = require('crypto');

exports.Session = models.model({
    'session_key':models.CharField({'max_length':40, primary_key:true}),
    'session_data':models.TextField(),
    'expire_date':models.DateTimeField(),
    'get_encoded':function(data) {
        var pickled = JSON.stringify(data),
            md5 = crypto.createHash('md5').update(pickled + settings.SECRET_KEY).digest('hex'),
            result = new Buffer(pickled + md5, 'utf8').toString('base64');
        return result;
    },
    'get_decoded':function() {
        var encodedData = (new Buffer(this.session_data, 'base64')).toString('utf8'),
            pickled = encodedData.slice(0, -32),
            tamperCheck = encodedData.slice(-32),
            md5sum = crypto.createHash('md5').update(pickled + settings.SECRET_KEY).digest('hex');
        if(md5sum !== tamperCheck) {
            throw new Error("User tampered with session cookie.");
github chrisdickinson / wilson / lib / contrib / auth / models.js View on Github external
var models = require('wilson/models');

exports.User = models.model({
    'username':models.CharField({'max_length':255}),
    'first_name':models.CharField({'max_length':255, 'nullable':true, 'blank':true}),
    'last_name':models.CharField({'max_length':255, 'nullable':true, 'blank':true}),
    'email':models.CharField({'max_length':255, 'nullable':true, 'blank':true}),
    'password':models.CharField({'max_length':40}),
    'is_staff':models.BooleanField(),
    'is_active':models.BooleanField(),
    'is_superuser':models.BooleanField(),
    'last_login':models.DateTimeField(),
    'date_joined':models.DateTimeField(),
    'toString':function() {
        return this.username;
    },
    'isAnonymous':function() {
        return false;
    },