mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-15 04:41:25 +08:00
访问控制支持基本认证和子请求认证
This commit is contained in:
101
web/public/js/components/server/http-auth-basic-auth-user-box.js
Normal file
101
web/public/js/components/server/http-auth-basic-auth-user-box.js
Normal file
@@ -0,0 +1,101 @@
|
||||
// 基本认证用户配置
|
||||
Vue.component("http-auth-basic-auth-user-box", {
|
||||
props: ["v-users"],
|
||||
data: function () {
|
||||
let users = this.vUsers
|
||||
if (users == null) {
|
||||
users = []
|
||||
}
|
||||
return {
|
||||
users: users,
|
||||
isAdding: false,
|
||||
updatingIndex: -1,
|
||||
|
||||
username: "",
|
||||
password: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
this.username = ""
|
||||
this.password = ""
|
||||
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.username.focus()
|
||||
}, 100)
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
this.updatingIndex = -1
|
||||
},
|
||||
confirm: function () {
|
||||
let that = this
|
||||
if (this.username.length == 0) {
|
||||
teaweb.warn("请输入用户名", function () {
|
||||
that.$refs.username.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.password.length == 0) {
|
||||
teaweb.warn("请输入密码", function () {
|
||||
that.$refs.password.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.updatingIndex < 0) {
|
||||
this.users.push({
|
||||
username: this.username,
|
||||
password: this.password
|
||||
})
|
||||
} else {
|
||||
this.users[this.updatingIndex].username = this.username
|
||||
this.users[this.updatingIndex].password = this.password
|
||||
}
|
||||
this.cancel()
|
||||
},
|
||||
update: function (index, user) {
|
||||
this.updatingIndex = index
|
||||
|
||||
this.isAdding = true
|
||||
this.username = user.username
|
||||
this.password = user.password
|
||||
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.username.focus()
|
||||
}, 100)
|
||||
},
|
||||
remove: function (index) {
|
||||
this.users.$remove(index)
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="httpAuthBasicAuthUsersJSON" :value="JSON.stringify(users)"/>
|
||||
<div v-if="users.length > 0">
|
||||
<div class="ui label small basic" v-for="(user, index) in users">
|
||||
{{user.username}} <a href="" title="修改" @click.prevent="update(index, user)"><i class="icon pencil tiny"></i></a>
|
||||
<a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div v-show="isAdding">
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<input type="text" placeholder="用户名" v-model="username" size="15" ref="username"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<input type="password" placeholder="密码" v-model="password" size="15" ref="password"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button tiny" type="button" @click.prevent="confirm">确定</button>
|
||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!isAdding" style="margin-top: 1em">
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
@@ -25,23 +25,36 @@ Vue.component("http-auth-config-box", {
|
||||
teaweb.popup("/servers/server/settings/access/createPopup", {
|
||||
callback: function (resp) {
|
||||
that.authConfig.policyRefs.push(resp.data.policyRef)
|
||||
}
|
||||
},
|
||||
height: "28em"
|
||||
})
|
||||
},
|
||||
update: function (index, policyId) {
|
||||
let that = this
|
||||
teaweb.popup("/servers/server/settings/access/updatePopup?policyId=" + policyId, {
|
||||
callback: function (resp) {
|
||||
Vue.set(that.authConfig.policyRefs, index, resp.data.policyRef)
|
||||
}
|
||||
teaweb.success("保存成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
},
|
||||
height: "28em"
|
||||
})
|
||||
},
|
||||
delete: function (index) {
|
||||
that.authConfig.policyRefs.$remove(index)
|
||||
remove: function (index) {
|
||||
this.authConfig.policyRefs.$remove(index)
|
||||
},
|
||||
methodName: function (methodType) {
|
||||
switch (methodType) {
|
||||
case "basicAuth":
|
||||
return "BasicAuth"
|
||||
case "subRequest":
|
||||
return "子请求"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="text" name="authJSON" :value="JSON.stringify(authConfig)"/>
|
||||
<input type="hidden" name="authJSON" :value="JSON.stringify(authConfig)"/>
|
||||
<table class="ui table selectable definition">
|
||||
<prior-checkbox :v-config="authConfig" v-if="vIsLocation"></prior-checkbox>
|
||||
<tbody v-show="!vIsLocation || authConfig.isPrior">
|
||||
@@ -57,24 +70,43 @@ Vue.component("http-auth-config-box", {
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="margin"></div>
|
||||
<!-- 认证方法 -->
|
||||
<div>
|
||||
<!-- 认证方式 -->
|
||||
<div v-show="isOn()">
|
||||
<h4>认证方式</h4>
|
||||
<table class="ui table selectable celled" v-show="authConfig.policyRefs.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>认证方法</th>
|
||||
<th class="three wide">名称</th>
|
||||
<th class="three wide">认证方法</th>
|
||||
<th>参数</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="ref in authConfig.policyRefs" :key="ref.authPolicyId">
|
||||
<tbody v-for="(ref, index) in authConfig.policyRefs" :key="ref.authPolicyId">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>{{ref.authPolicy.name}}</td>
|
||||
<td>
|
||||
{{methodName(ref.authPolicy.type)}}
|
||||
</td>
|
||||
<td>
|
||||
<span v-if="ref.authPolicy.type == 'basicAuth'">{{ref.authPolicy.params.users.length}}个用户</span>
|
||||
<span v-if="ref.authPolicy.type == 'subRequest'">
|
||||
<span v-if="ref.authPolicy.params.method.length > 0" class="grey">[{{ref.authPolicy.params.method}}]</span>
|
||||
{{ref.authPolicy.params.url}}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<label-on :v-is-on="ref.authPolicy.isOn"></label-on>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="update(index, ref.authPolicyId)">修改</a>
|
||||
<a href="" @click.prevent="remove(index)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="ui button small" type="button" @click.prevent="add">+添加认证</button>
|
||||
<button class="ui button small" type="button" @click.prevent="add">+添加认证方式</button>
|
||||
</div>
|
||||
<div class="margin"></div>
|
||||
</div>`
|
||||
|
||||
Reference in New Issue
Block a user