From 9d65e2ad17147eaf89daff957894034e119afc85 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Thu, 17 Dec 2015 22:35:04 +0700 Subject: [PATCH] Change to promote first register user to Administrator --- app/models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index 8203a73..9471d85 100644 --- a/app/models.py +++ b/app/models.py @@ -180,7 +180,12 @@ class User(db.Model): self.firstname = self.username self.lastname = '' - self.role_id = 2 + # first register user will be in Administrator role + if User.query.count() == 0: + self.role_id = 1 + else: + self.role_id = 2 + self.create_user() logging.info('Created user "%s" in the DB' % self.username) return True @@ -218,7 +223,12 @@ class User(db.Model): return 'Email already existed' try: - self.role_id = 2 + # first register user will be in Administrator role + if User.query.count() == 0: + self.role_id = 1 + else: + self.role_id = 2 + user = User(username=self.username, firstname=self.firstname, lastname=self.lastname, role_id=self.role_id, email=self.email, password=self.get_hashed_password(self.plain_text_password)) db.session.add(user) db.session.commit()