Пример #1
0
class UpdateSubAccountView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self, user_id):
        abort_if_user_doesnt_exist(user_id)
        sub_account_validate(user_id)
        user =  User.query.get(user_id)
        return jsonify({"data": UserSerializer().dump(user).data})

    def put(self, user_id):
        abort_if_user_doesnt_exist(user_id)
        sub_account_validate(user_id)
        obj = User.query.get(user_id)
        data = ImmutableMultiDict(request.json)
        update_form = UpdateSubAccountForm(data, instance=obj, csrf_enabled=False)
        if update_form.validate():
            sub_account = update_form.save(user_id)
            return jsonify({"status": "success", "data": BaseUserSerializer().dump(sub_account).data})
        return update_form.errors

    def delete(self, user_id):
        abort_if_user_doesnt_exist(user_id)
        sub_account_validate(user_id)
        db.session.query(User).filter(User.id==user_id).update({"is_active": False})
        db.session.commit()
        return '', 204
Пример #2
0
class MessageDetailView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self, message_id):
        message = Message.query.get(message_id)
        abort_if_not_a_right_user(message.user)
        db.session.query(Message).filter(Message.id==message_id).update({"read": True})
        db.session.commit()
        return jsonify({"data": MessageSerializer().dump(message).data})
Пример #3
0
class ChangePasswordView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def put(self):
        data = ImmutableMultiDict(request.json)
        change_password_form = PasswordChangeForm(data, csrf_enabled=False)
        if change_password_form.validate():
            obj = User.query.filter(User.username == current_identity.username).first()
            change_password_form.save(obj)
            return jsonify({"status": "success", "message": "Password Changed"})
        return change_password_form.errors
Пример #4
0
class UpdateProfileView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def put(self):
        data = ImmutableMultiDict(request.json)
        obj = User.query.filter(User.username==current_identity.username).first()
        update_form = ProfileUpdateForm(data, csrf_enabled=False)
        if update_form.validate():
            profile = update_form.save(obj)
            return jsonify({"status": "success","data": BaseUserSerializer().dump(profile).data})
        return update_form.errors
Пример #5
0
class SubAccountChangePermissionView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def put(self, user_id):
        abort_if_user_doesnt_exist(user_id)
        sub_account_validate(user_id)
        data = ImmutableMultiDict(request.json)
        update_form = UpdateSubAccountPermissionForm(data, csrf_enabled=False)
        if update_form.validate():
            sub_account = update_form.save(user_id)
            return jsonify({"status": "success","data": BaseUserSerializer().dump(sub_account).data})
        return update_form.errors
Пример #6
0
class ContactGroupView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        groups = ContactGroup.query.filter(ContactGroup.owner==current_identity.id).all()
        return jsonify({"data": ContactGroupSerializer().dump(groups, many=True).data})

    def post(self):
        data = ImmutableMultiDict(request.json)
        create_group_form = CreateContactGroupForm(data, csrf_enabled=False)
        if create_group_form.validate():
            group = create_group_form.save()
            return jsonify({"status": "success", "data": ContactGroupSerializer().dump(group).data})
        return create_group_form.errors
Пример #7
0
class SubAccountView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        users = User.query.filter(User.parent==current_identity.id).all()
        return {"data": BaseUserSerializer().dump(users, many=True).data}

    def post(self):
        data = ImmutableMultiDict(request.json)
        create_form = CreateSubAccountForm(data, csrf_enabled=False)
        if create_form.validate():
            sub_account = create_form.save()
            return jsonify({"status": "success","data": BaseUserSerializer().dump(sub_account).data})
        return create_form.errors
Пример #8
0
class MessageView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        messages = Message.query.filter(Message.user==current_identity.id).all()
        return jsonify({"data": MessageSerializer().dump(messages, many=True).data})

    def post(self):
        abort_if_not_an_admin()
        data = ImmutableMultiDict(request.json)
        message_form = MessageForm(data, csrf_enabled=False)
        if message_form.validate():
            message_form.save()
            return {"status": "success"}
        return message_form.errors
Пример #9
0
class ContactGroupingView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def post(self):
        data = ImmutableMultiDict(request.json)
        contact_grouping_form = ContactGroupingForm(data, csrf_enabled=False)
        if contact_grouping_form.validate():
            group = contact_grouping_form.save()
            return jsonify({"status": "success", "data": ContactGroupSerializer().dump(group).data})
        return contact_grouping_form.errors

    def delete(self):
        data = ImmutableMultiDict(request.json)
        contact_grouping_form = ContactGroupingForm(data, csrf_enabled=False)
        if contact_grouping_form.validate():
            abort_if_not_a_right_owner(data['group'])
            contact_grouping_form.delete()
            return '', 204
        return contact_grouping_form.errors
Пример #10
0
class UpdateLogoView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def put(self):
        obj = User.query.filter(User.username==current_identity.username).first()
        logo_form = LogoUpdateForm(request.files, csrf_enabled=False)
        if logo_form.validate():
            file = logo_form.logo.data
            file_name = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], file_name))
            url = app.config['STATIC_FOLDER']+file_name
            logo_form.save(obj, url)
            return jsonify({"status": "success","data": UserSerializer().dump(obj).data})
        return logo_form.errors

    def delete(self):
        db.session.query(User).filter_by(id=current_identity.id).\
            update({"logo_image_name": "", "logo_image_path": ""})
        db.session.commit()
        return '', 204
Пример #11
0
class ContactGroupDetailView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self, group_id):
        group = ContactGroup.query.filter(ContactGroup.id==group_id).first()
        return jsonify({"data": ContactGroupSerializer().dump(group).data})

    def put(self, group_id):
        data = ImmutableMultiDict(request.json)
        contact_group_rename_form = ContactGroupRenameForm(data, csrf_enabled=False)
        if contact_group_rename_form.validate():
            instance = ContactGroup.query.filter(ContactGroup.id==group_id).first()
            group = contact_group_rename_form.save(instance)
            return jsonify({"status": "success", "data": ContactGroupSerializer().dump(group).data})
        return contact_group_rename_form.errors

    def delete(self, group_id):
        abort_if_not_a_right_owner(group_id)
        db.session.query(ContactGroup).filter(ContactGroup.id==group_id).delete()
        db.session.commit()
        return '', 204
Пример #12
0
class CardDetailsView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        card_details = CreditCard.query.filter(CreditCard.user_id==current_identity.id,
                                               CreditCard.is_active==True).first()
        return jsonify({"data": CardDetailsSerializer().dump(card_details).data})

    def put(self):
        data = ImmutableMultiDict(request.json)
        user = User.query.get(current_identity.id)
        credit_card_form = CreditCardForm(data, csrf_enabled=False)
        if credit_card_form.validate():
            credit_card = credit_card_form.save(instance=user)
            return jsonify({"status": "success", "data": CardDetailsSerializer().dump(credit_card).data})
        return credit_card_form.errors

    def delete(self):
        db.session.query(CreditCard).filter(CreditCard.user_id==current_identity.id,
                                            CreditCard.is_active==True).update({"is_active": False})
        db.session.commit()
        return '', 204
Пример #13
0
class UserDetailsView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        user = User.query.filter(User.username==current_identity.username).first()
        return jsonify({"data": UserSerializer().dump(user).data})
Пример #14
0
class PlanDetailsView(Resource):
    method_decorators = [plan_not_expired(), jwt_required()]

    def get(self):
        plan = Plan.query.filter(Plan.user_id==current_identity.id).first()
        return jsonify({"data": PlanSerializer().dump(plan).data})