Created
May 20, 2020 14:38
-
-
Save petersirka/28b6dbc79b0406893db7c63e12b2ce08 to your computer and use it in GitHub Desktop.
OpenPlatform registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROUTE('-POST /create/ *Create --> @create'); | |
NEWSCHEMA('Create', function(schema) { | |
schema.define('gender', ['male', 'female'], true); | |
schema.define('reference', String); | |
schema.define('firstname', 'Capitalize(30)', true); | |
schema.define('lastname', 'Capitalize(30)', true); | |
schema.define('position', 'String(30)'); | |
schema.define('company', 'String(40)'); | |
schema.define('phone', 'Phone', true); | |
schema.define('locality', 'Upper(3)'); | |
schema.define('language', 'Lower(2)'); | |
schema.define('dateformat', ['yyyy-MM-dd', 'dd.MM.yyyy', 'MM.dd.yyyy'])('yyyy-MM-dd'); // date format | |
schema.define('timeformat', [12, 24])(24); | |
schema.define('numberformat', [1, 2, 3, 4])(1); | |
schema.define('email', 'Email'); | |
schema.define('password', 'String(30)', true); | |
schema.middleware(function($, next) { | |
DBMS().read('tbl_user').fields('id').where('email', $.model.email).callback(function(err, response) { | |
if (response) { | |
$.invalid('error-email-exists'); | |
next(true); | |
} else | |
next(); | |
}); | |
}); | |
schema.addWorkflow('create', function($) { | |
var model = $.clean(); | |
model.id = UID(); | |
model.welcome = true; | |
model.contractid = 5; // customer | |
model.groups = ['customers']; | |
model.darkmode = false; | |
model.desktop = 3; | |
model.volume = 50; | |
model.sounds = true; | |
model.notifications = true; | |
model.notificationsemail = true; | |
model.sa = false; | |
model.login = model.email; | |
model.repo = {}; | |
model.repo = JSON.stringify(model.repo); | |
model.statusid = 0; | |
$INSERT('Users', model, function(err, response) { | |
if (err) { | |
$.invalid(err); | |
return; | |
} | |
var ua = ($.headers['user-agent'] || '').parseUA(); | |
FUNC.loginid($.controller, response.value, function() { | |
// User is logged | |
$.success(true, 'redirect'); | |
}, ua + ' (' + $.ip + ')'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment