forked from oyd/Adunatio
parent
58c5d37a21
commit
a5e3dfbae8
@ -1,18 +1,31 @@ |
|||||||
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): |
||||||
name = StringField() |
name = StringField() |
||||||
logo = ImageField(thumbnail_size=(120,120)) |
logo = ImageField(thumbnail_size=(120, 120)) |
||||||
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() |
||||||
|
Loading…
Reference in new issue