|
|
@ -1,4 +1,7 @@ |
|
|
|
from mongoengine import * |
|
|
|
from mongoengine import * |
|
|
|
|
|
|
|
from werkzeug.security import generate_password_hash |
|
|
|
|
|
|
|
from string import printable |
|
|
|
|
|
|
|
from random import choices |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Union(Document): |
|
|
|
class Union(Document): |
|
|
@ -7,12 +10,22 @@ class Union(Document): |
|
|
|
description = StringField() |
|
|
|
description = StringField() |
|
|
|
legal_registration_number = StringField() |
|
|
|
legal_registration_number = StringField() |
|
|
|
headquarter = StringField() |
|
|
|
headquarter = StringField() |
|
|
|
|
|
|
|
email = StringField() |
|
|
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
def save(self, *args, **kwargs): |
|
|
|
super(Union, self).save(*args, **kwargs) |
|
|
|
super(Union, self).save(*args, **kwargs) |
|
|
|
from .Group import Group |
|
|
|
from .Group import Group |
|
|
|
|
|
|
|
from .User import User |
|
|
|
group = Group() |
|
|
|
group = Group() |
|
|
|
group.union = self |
|
|
|
group.union = self |
|
|
|
group.name = 'Root' |
|
|
|
group.name = 'Root' |
|
|
|
group.rights = ["*::*::{}}/*".format(self.id)] |
|
|
|
group.rights = ["*::*::{}}/*".format(self.id)] |
|
|
|
group.save() |
|
|
|
group.save() |
|
|
|
|
|
|
|
user = User() |
|
|
|
|
|
|
|
user.username = "{}@root".format(self.legal_registration_number) |
|
|
|
|
|
|
|
user.user_group = group |
|
|
|
|
|
|
|
user.union = self |
|
|
|
|
|
|
|
password = choices(printable, k=10) |
|
|
|
|
|
|
|
user.password = generate_password_hash(password) |
|
|
|
|
|
|
|
# TODO: send mail or etc |
|
|
|
|
|
|
|
user.save() |
|
|
|