UNPKG

ozserver

Version:

API for OZ

59 lines (45 loc) 1.61 kB
var Registration, Schema, exports, randomString, sha1, validate; randomString = require('random-string'); sha1 = require('sha1'); validate = require('validate'); Schema = require(global.home + '/script/views/validate/registration'); Registration = (function() { function Registration(model) { this.model = model; this.check(); this.validate(); } Registration.prototype.check = function() { this.model.firstname = this.model.firstname.toString().trim(); this.model.lastname = this.model.lastname.toString().trim(); this.model.email = this.model.email.toString().trim().toLowerCase(); return this.model.company = this.model.company.toString().trim(); }; Registration.prototype.validate = function() { this.model.notice = validate(Schema, this.model); if (Array.isArray(this.model.notice)) { this.model.notice = this.model.notice[0].toString().replace('Error: ', ''); return this.model.success = false; } else { return this.model.success = true; } }; Registration.prototype.genPwd = function() { this.model.password = randomString({ length: 5 }).toLowerCase(); return this.model.key = sha1(this.model.password).toString(); }; Registration.prototype.emailExists = function() { this.model.success = false; return this.model.notice = 'Данный email-адрес уже используется'; }; return Registration; })(); exports = module.exports = function(model) { if (model == null) { model = {}; } return new Registration(model); }; exports.Registration = Registration;