Exemplo n.º 1
0
    def post(self):
        '''creates a user'''
        self.username = request.form['username']
        self.password = request.form['password']

        # check that arguments are not empty
        if self.username is None or self.password is None:
            abort(400, message='username/password missing')

        # check if user already exists
        if User.query.filter(User.username == self.username).first() is not None:
            abort(400, message='username unavailable')

        # create a user and commit to database
        u = User(self.username, self.password)
        db_session.add(u)
        db_session.commit()

        schema = UserSchema()
        return schema.dump(u).data, 200
Exemplo n.º 2
0
 def get(self):
     '''returns a user'''
     usr = g.user
     schema = UserSchema()
     return schema.dump(usr).data, 200