Flask-HTTPAuth用户访问级别

时间:2018-01-03 08:21:58

标签: python rest flask flask-restful flask-httpauth

我目前正在使用Flask-RESTful构建REST API,并使用Flask-HTTPAuth来保护一些put和get方法。我想允许基于我存储在数据库中的预定义用户权限来访问这些方法。

我的问题是,如何修改或拦截下面函数的结果,以便根据端点/方法改变访问权限?清除基本身份验证后,我希望能够检查用户是否在我的数据库中具有相关权限。使用Flask-Session这很简单,但这里的API是无状态的。

@auth.verify_password
def verify_password(user, password):
    query_set = models.User.objects(username=user)
    if query_set:
        return helpers.verify(password, query_set[0].password)
    else:
        return False

非常感谢。

1 个答案:

答案 0 :(得分:5)

要使用基于角色的身份验证,您需要在传递密码步骤后添加第二项检查。

您有两种选择。更直接的是在每个端点函数中添加角色检查。如果你想要更复杂的东西来避免代码重复,那么你可以定义一个自定义装饰器,例如我在这里使用的装饰器:https://github.com/miguelgrinberg/flasky/blob/master/app/decorators.py

您需要调整它以使用您自己的用户对象而不是document.getElementById().innerHTML = active;,但除此之外,这是一个很好的示例:

    function writeDateAndTime() {
        let date= new Date();
        let currentMonth = date.getMonth();
        let nameMonth = ["January", "February", "March", "April", "May", "June", "July","August", "September", "October", "November", "December"];
        let day = date.getDate();
        let year = date.getFullYear();
        let hour = date.getHours();
        let minutes= date.getMinutes();
        let seconds=date.getSeconds();

       let active =  '' + nameMonth[currentMonth] + " " + day + ', ' + year + " " + hour + ":" + minutes + ":" + seconds;
       document.getElementById().innerHTML = active;
       setInterval(writeDateAndTime(),1000);
    }
</script>

那么在你的路线中,你这样做:

<form id="form">
    <div class="column100 trans t-center" style="font-size:0;">
        <div class="column20 trans t-center">
        </div>
        <div class="column60 trans t-center">
            <div class="column60 trans t-center" style="font-size:0;">
                <div class="column60 trans t-center">
                    Block
                    <input name="block" type="text" style="width:90%;" placeholder='stone'>
                </div>
                <div class="column10 trans t-center"><br>
                    :
                </div>
                <div class="column20 trans t-center">
                    Type
                    <input name="type" type="text" style="width:50%;" placeholder='0'>
                </div>
            </div>
            <br><br>
            <div class="column50 trans t-center" style="font-size:0;">
                <div class="column33 trans t-center">
                    1.11<br>
                    <div class="pretty p-svg p-curve p-pulse" style="margin:auto;margin-top:10px;font-size:50px;">
                        <input type="radio" id="1.11" name="radio">

                        <div class="state p-success">
                            <svg class="svg svg-icon" viewBox="0 0 20 20">
                                <path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z"
                                      style="stroke: white;fill:white;"></path>
                            </svg>
                            <label></label>
                        </div>
                    </div>
                </div>
                <div class="column33 trans t-center">
                    1.12<br>
                    <div class="pretty p-svg p-curve p-pulse" style="margin:auto;margin-top:10px;font-size:50px;">
                        <input type="radio" id="1.12" name="radio">

                        <div class="state p-success">
                            <svg class="svg svg-icon" viewBox="0 0 20 20">
                                <path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z"
                                      style="stroke: white;fill:white;"></path>
                            </svg>
                            <label></label>
                        </div>
                    </div>
                </div>
            </div>
            <br><br>
            Essentials installed?<br>
            <div class="pretty p-svg p-curve p-pulse" style="margin:auto;margin-top:10px;font-size:50px;">
                <input id="essentials" type="checkbox"/>
                <div class="state p-success">
                    <!-- svg path -->
                    <svg class="svg svg-icon" viewBox="0 0 20 20">
                        <path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z"
                              style="stroke: white;fill:white;"></path>
                    </svg>
                    <label></label>
                </div>
            </div>
            <br><br>
            Add glow<br>
            <div class="pretty p-svg p-curve p-pulse" style="margin:auto;margin-top:10px;font-size:50px;">
                <input id="glow" type="checkbox"/>
                <div class="state p-success">
                    <!-- svg path -->
                    <svg class="svg svg-icon" viewBox="0 0 20 20">
                        <path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z"
                              style="stroke: white;fill:white;"></path>
                    </svg>
                    <label></label>
                </div>
            </div>
        </div>
        <div class="column20 trans t-center">
        </div>
    </div>
</form><br>
<button id="submit" class="button" onclick="command()">Submit & Copy</button><br><br>
<script>
    document.getElementById('submit').onclick = command;
    function command() {
        if (document.getElementById('essentials').checked) {
            initiation = "/minecraft:";
        } else {
            initiation = "/";
        }
        if (document.getElementById('glow').checked) {
            glow = "glowstone";
        } else {
            glow = "glass";
        }
        var x = document.getElementById("form");
        var type = x.elements["type"].value;
        var block = x.elements["block"].value;
        if (block == "") {
            block = "stone";
        }
        if (type == "") {
            type = "0";
        }
        if (document.getElementById('1.11').checked) {
            var command = `/summon falling_block ~ ~1 ~ { Block:command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/fill ~1 ~-1 ~1 ~-1 ~53 ~-1 air" } ,Passengers:[{ id:falling_block,Block:command_block,Data:1,Time:1,TileEntityData:{ auto:0,Command:"/fill ~1 ~ ~1 ~-1 ~53 ~-1 air" } ,Passengers:[{ id:falling_block,Block:repeating_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.063 ~-1.9981 ~0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.063 ~-1.9982 ~-0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.063 ~-1.9983 ~-0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.063 ~-1.9984 ~0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~ ~-1.998 ~ /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.3 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.113 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.074 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.261 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.261 ~-0.579 ~0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[315f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.074 ~-0.579 ~0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[315f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.113 ~-0.579 ~0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[315f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.3 ~-0.579 ~0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[315f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.059 ~-0.579 ~-0.302 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[45f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.059 ~-0.579 ~-0.115 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[45f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.059 ~-0.579 ~0.072 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[45f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.059 ~-0.579 ~0.259 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[45f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.060 ~-0.579 ~-0.260 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[225f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.060 ~-0.579 ~-0.073 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[225f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.060 ~-0.579 ~0.114 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[225f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.060 ~-0.579 ~0.301 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[225f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.2203 ~-1.495 ~0.156 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.2206 ~-1.495 ~-0.156 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.2209 ~-1.432 ~0.155 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.2212 ~-1.432 ~-0.156 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.156 ~-1.495 ~0.2203 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[90f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.155 ~-1.495 ~0.2206 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[90f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.156 ~-1.432 ~0.2209 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[90f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.155 ~-1.432 ~0.2212 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[90f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.2203 ~-1.495 ~-0.156 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[180f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.2206 ~-1.495 ~0.155 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[180f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.2209 ~-1.432 ~-0.156 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[180f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.2212 ~-1.432 ~0.155 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[180f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.156 ~-1.495 ~-0.2206 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[270f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.155 ~-1.495 ~-0.2203 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[270f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.156 ~-1.432 ~-0.2212 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[270f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.155 ~-1.432 ~-0.2209 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[270f],Small:1b,ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~ ~-1 ~ /setblock ~ ~ ~ glowstone 0" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.1881 ~-2.8751 ~0.1881 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.1883 ~-2.8753 ~-0.1883 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.1885 ~-2.8755 ~0.1885 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.1887 ~-2.8757 ~-0.1887 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/minecraft:tp @e[type=Creeper,name=Chest] ~ -100 ~" } ,Passengers:[{ id:falling_block,Block:repeating_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Remove] ~ ~ ~ /minecraft:kill @e[type=armor_stand,r=3,name=Chest]" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/minecraft:tp @e[type=Creeper,name=Remove] ~ -100 ~" } ,Passengers:[{ id:falling_block,Block:command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/give @p minecraft:spawn_egg 1 51 {HideFlags:33,display:{Name:\\"Create Chest\\"},ench:[{id:1,lvl:0}],EntityTag:{id:minecraft:creeper,CustomName:\\"Chest\\", ActiveEffects:[{Id:14,Amplifier:0,Duration:100,ShowParticles:0b}]}}" } ,Passengers:[{ id:falling_block,Block:command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/give @p minecraft:spawn_egg 1 51 {HideFlags:33,display:{Name:\\"Remove Chest\\"},ench:[{id:1,lvl:0}],EntityTag:{id:minecraft:creeper,CustomName:\\"Remove\\", ActiveEffects:[{Id:14,Amplifier:0,Duration:100,ShowParticles:0b}]}}"}}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}`;
        }
        if (document.getElementById('1.12').checked) {
            var command = `/summon falling_block ~ ~1 ~ { Block:command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/fill ~1 ~-1 ~1 ~-1 ~53 ~-1 air" } ,Passengers:[{ id:falling_block,Block:command_block,Data:1,Time:1,TileEntityData:{ auto:0,Command:"/fill ~1 ~ ~1 ~-1 ~53 ~-1 air" } ,Passengers:[{ id:falling_block,Block:repeating_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.063 ~-1.9981 ~0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.063 ~-1.9982 ~-0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.063 ~-1.9983 ~-0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~-0.063 ~-1.9984 ~0.063 /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\ock,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~ ~-1.998 ~ /summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, ArmorItems:[{},{},{},{id:\\"stone\\",Damage:0s,Count:1b}],HandItems:[{},{}],CustomName:\\"Chest\\",DisabledSlots:2039583}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.3 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},{}],CustomName:\\"Chest\\",DisabledSlots:2039583,Pose:{RightArm:[345f,0f,0f]}}" } ,Passengers:[{ id:falling_block,Block:chain_command_block,Data:1,Time:1,TileEntityData:{ auto:1,Command:"/execute @e[type=Creeper,name=Chest] ~0.113 ~-0.579 ~-0.06 /summon armor_stand ~ ~ ~ {Small:1b,Invisible:1b,Invulnerable:1b,PersistenceRequired:1b,NoBasePlate:1b,NoGravity:1b, Rotation:[135f],ArmorItems:[{},{},{},{}],HandItems:[{id:\\"stone\\",Damage:0s,Count:1b},[{Id:14,Amplifier:0,Duration:100,ShowParticles:0b}]}}"}}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}`;
        }

        var replace_block = '"stone';
        var replace_type = 'Damage:0s';
        var replace_initiation = "/minecraft:";
        var replace_glowstone = "glowstone";
        var filter1 = new RegExp(replace_block, 'g');
        var filter2 = new RegExp(replace_type, 'g');
        var filter3 = new RegExp(replace_glowstone, 'g');
        var filter4 = new RegExp(replace_initiation, 'g');
        var result1 = command.replace(filter1, '"' + block);
        var result2 = result1.replace(filter2, 'Damage:' + type + 's');
        var result3 = result2.replace(filter3, glow);
        var result4 = result3.replace(filter4, initiation);
        var temp = document.createElement("textarea");
        document.body.appendChild(temp);
        temp.value = result4;
        temp.select();
        document.execCommand("copy");
        document.body.removeChild(temp);
        document.getElementById("submit").style.background = 'rgba(92,184,92,1)';
        var form = document.getElementById("form");
        form.addEventListener("input", function () {
            alert("changed!");
        });
    }
</script>