Ejemplo n.º 1
0
    def post(self):
        """Create a new user.

        Required in Payload:
            userame: Username of the new user to be created.
            password: Passowrd of the user to be created.

        Optional in Payload:
            bio: Bio of the user to be created.
        """
        args = post_parser.parse_args(strict=True)
        LOGGER.info({"Args": args})

        user = User.get_user(args.username)
        if user is None:
            hashed = bcrypt.hashpw(args.password.encode("utf8"),
                                   bcrypt.gensalt())
            record = User(
                username=args.username,
                pw_hash=hashed,
                bio=args.bio,
                displayName=args.displayName,
            )
            record.save()
            data = {"message": f"user {args.username} created"}
            return Success(data).to_json(), 201
        return Fail(f"user {args.username} exists").to_json(), 400
Ejemplo n.º 2
0
def init_forum():
    db.create_all()
    if User.get_user(username=FORUM_ADMIN.get("username")) is None:
        hashed = bcrypt.hashpw(
            FORUM_ADMIN.get("password").encode("utf8"), bcrypt.gensalt())
        admin = User(
            username=FORUM_ADMIN.get("username"),
            pw_hash=hashed,
            is_admin=True,
            is_mod=True,
        )
        admin.save()
Ejemplo n.º 3
0
 def tearDownClass(self):
     with app.app_context():
         db.drop_all()
         db.create_all()
         if User.get_user(username=FORUM_ADMIN.get("username")) is None:
             hashed = bcrypt.hashpw(
                 FORUM_ADMIN.get("password").encode("utf8"),
                 bcrypt.gensalt())
             admin = User(
                 username=FORUM_ADMIN.get("username"),
                 pw_hash=hashed,
                 is_admin=True,
                 is_mod=True,
             )
             admin.save()