Example #1
0
    def post(self, username):
        data = self.parser()
        with lock.lock:
            acc = AccountsModel.find_by_username(username)
            if acc:
                return {'message': "username  with id [{}] already exists".format(id)}, 404
            else:
                available_money = data['available_money'] if data["available_money"] else AVAILABLE_MONEY
                is_admin = data['is_admin'] if data["is_admin"]  else IS_ADMIN

                acc = AccountsModel(username, available_money=available_money, is_admin=is_admin)
                acc.hash_password(data['password'])
                acc.save_to_db()

                return {'message' : acc.json()}, 201

            return {'account': acc.json()}, 201
Example #2
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('firstname',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('surname',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('email',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('username',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('password',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('dni',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('dataEndDrivePermission',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        #parser.add_argument('status', type=str, required=True, help="This field cannot be left blank")
        parser.add_argument('creditCard',
                            type=str,
                            required=True,
                            help="This field cannot be left blank")
        #######parser.add_argument('availableMoney', type=int, required=True, help="This field cannot be left blank")
        parser.add_argument('type',
                            type=int,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('latitude',
                            type=float,
                            required=True,
                            help="This field cannot be left blank")
        parser.add_argument('longitude',
                            type=float,
                            required=True,
                            help="This field cannot be left blank")
        data = parser.parse_args()

        user = AccountsModel.find_by_username(data['username'])
        if user:
            return {"message": "User already exists"}, 400
        else:
            new_user = AccountsModel(data['firstname'], data['surname'],
                                     data['email'], data['username'],
                                     data['dni'],
                                     data['dataEndDrivePermission'],
                                     data['creditCard'], data['type'],
                                     data['latitude'], data['longitude'])
            new_user.hash_password(data['password'])
            try:
                new_user.save_to_db()
                return new_user.json(), 200
            except Exception as e:
                return {"message": "Database error"}, 500