Add Groups

This commit is contained in:
2017-01-10 08:08:45 -05:00
parent bea8be18ff
commit 9ed692aa10
20 changed files with 740 additions and 62 deletions

View File

@ -10,6 +10,8 @@ function getJSONObj(json_input) {
function User() {
this.UserId = -1;
this.GroupId = -1;
this.GroupPassword = "";
this.Name = "";
this.Username = "";
this.Password = "";
@ -19,6 +21,8 @@ function User() {
User.prototype.toJSON = function() {
var json_obj = {};
json_obj.UserId = this.UserId;
json_obj.GroupId = this.GroupId;
json_obj.GroupPassword = this.GroupPassword;
json_obj.Name = this.Name;
json_obj.Username = this.Username;
json_obj.Password = this.Password;
@ -31,6 +35,10 @@ User.prototype.fromJSON = function(json_input) {
if (json_obj.hasOwnProperty("UserId"))
this.UserId = json_obj.UserId;
if (json_obj.hasOwnProperty("GroupId"))
this.GroupId = json_obj.GroupId;
if (json_obj.hasOwnProperty("GroupPassword"))
this.GroupPassword = json_obj.GroupPassword;
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
if (json_obj.hasOwnProperty("Username"))
@ -43,10 +51,42 @@ User.prototype.fromJSON = function(json_input) {
User.prototype.isUser = function() {
var empty_user = new User();
return this.UserId != empty_user.UserId ||
return this.UserId != empty_user.UserId &&
this.GroupId != empty_user.GroupId &&
this.Username != empty_user.Username;
}
function Group() {
this.GroupId = -1;
this.Name = "";
this.Password = "";
}
Group.prototype.toJSON = function() {
var json_obj = {};
json_obj.GroupId = this.GroupId;
json_obj.Name = this.Name;
json_obj.Password = this.Password;
return JSON.stringify(json_obj);
}
Group.prototype.fromJSON = function(json_input) {
var json_obj = getJSONObj(json_input);
if (json_obj.hasOwnProperty("GroupId"))
this.GroupId = json_obj.GroupId;
if (json_obj.hasOwnProperty("Name"))
this.Name = json_obj.Name;
if (json_obj.hasOwnProperty("Password"))
this.Password = json_obj.Password;
}
Group.prototype.isGroup = function() {
var empty_group = new Group();
return this.GroupId != empty_group.GroupId &&
this.Name != empty_group.Name;
}
function Session() {
this.SessionId = -1;
this.UserId = -1;
@ -253,6 +293,7 @@ module.exports = models = {
// Classes
User: User,
Group: Group,
Session: Session,
Error: Error,
Attendee: Attendee,