ozserver
Version:
API for OZ
52 lines (40 loc) • 1.31 kB
JavaScript
var Edit, Schema, exports, sha1, validate;
sha1 = require('sha1');
validate = require('validate');
Schema = require(global.home + '/script/views/validate/security');
Edit = (function() {
function Edit(model) {
this.model = model != null ? model : {};
}
Edit.prototype.check = function() {
this.model.success = false;
this.model.password_new = this.model.password_new.trim();
this.model.notice = validate(Schema, this.model);
if (Array.isArray(this.model.notice)) {
this.model.notice = this.model.notice[0].toString().replace('Error: ', '');
} else {
this.model.success = true;
this.model.key_new = sha1(this.model.password_new);
}
return this.model.success;
};
Edit.prototype.success = function() {
this.model.success = true;
this.model.key = this.model.key_new;
this.model.key_new = null;
this.model.password_new = null;
return this.model.notice = 'Пароль успешно изменен';
};
Edit.prototype.fail = function() {
this.model.success = false;
return this.model.notice = 'Не удалось изменить пароль';
};
return Edit;
})();
exports = module.exports = function(model) {
if (model == null) {
model = {};
}
return new Edit(model);
};
exports.Edit = Edit;