Beispiel #1
0
    def post(self):
        try:
            login = self.json["login"]
            email = self.json["email"]
            is_admin = bool(self.json.get("is_admin", 0))
            password = self.json["password"]

            assert password and len(password) > 3
            assert LOGIN_EXP.match(login)
            assert EMAIL_EXP.match(email)
        except (KeyError, AssertionError, TypeError):
            raise HTTPError(400)

        if Users.select().where(Users.login == login).count():
            raise HTTPError(409)

        user = Users(
            login=login,
            email=email,
            is_admin=is_admin,
            password=password,
        )

        user.save()

        self.response({
            'id': user.id,
            'login': user.login,
            'email': user.email,
            'is_admin': user.is_admin,
        })
Beispiel #2
0
def create_default_user(migrator, db):
    Users(login='******',
          password='******',
          email="*****@*****.**",
          is_admin=True).save()