|
|
|
@ -1,4 +1,7 @@ |
|
|
|
|
from mongoengine import * |
|
|
|
|
from werkzeug.security import generate_password_hash |
|
|
|
|
from string import printable |
|
|
|
|
from random import choices |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Union(Document): |
|
|
|
@ -7,12 +10,22 @@ class Union(Document): |
|
|
|
|
description = StringField() |
|
|
|
|
legal_registration_number = StringField() |
|
|
|
|
headquarter = StringField() |
|
|
|
|
email = StringField() |
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
|
super(Union, self).save(*args, **kwargs) |
|
|
|
|
from .Group import Group |
|
|
|
|
from .User import User |
|
|
|
|
group = Group() |
|
|
|
|
group.union = self |
|
|
|
|
group.name = 'Root' |
|
|
|
|
group.rights = ["*::*::{}}/*".format(self.id)] |
|
|
|
|
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() |
|
|
|
|