Skip to content

Commit 651ca38

Browse files
author
Lucas Martins
committed
Add updateHostPassword API to UI
1 parent c80b886 commit 651ca38

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,7 @@
34803480
"message.success.change.bgp.peers": "Successfully changed BGP peers",
34813481
"message.success.change.offering": "Successfully changed offering",
34823482
"message.success.change.password": "Successfully changed password for User",
3483+
"message.success.change.host.password": "Successfully changed password for host \"{name}\"",
34833484
"message.success.clear.webhook.deliveries": "Successfully cleared webhook deliveries",
34843485
"message.success.change.scope": "Successfully changed scope for storage pool",
34853486
"message.success.config.backup.schedule": "Successfully configured Instance backup schedule",

ui/public/locales/pt_BR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,7 @@
23882388
"message.success.change.affinity.group": "Grupos de afinidade alterados com sucesso",
23892389
"message.success.change.offering": "Oferta alterada com sucesso",
23902390
"message.success.change.password": "Senha alterada com sucesso",
2391+
"message.success.change.host.password": "Senha do host \"{name}\" foi alterada com sucesso",
23912392
"message.success.config.backup.schedule": "Agendamento de backup de VM configurado com sucesso",
23922393
"message.success.config.sticky.policy": "Sticky policy configurada com sucesso",
23932394
"message.success.copy.clipboard": "Copiado com sucesso para a \u00e1rea de transfer\u00eancia",

ui/src/config/section/infra/hosts.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ export default {
7777
popup: true,
7878
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostUpdate')))
7979
},
80+
{
81+
api: 'updateHostPassword',
82+
icon: 'key-outlined',
83+
label: 'label.action.change.password',
84+
dataView: true,
85+
popup: true,
86+
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/ChangeHostPassword.vue')))
87+
},
8088
{
8189
api: 'provisionCertificate',
8290
icon: 'safety-certificate-outlined',
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
<template>
19+
<div class="form-layout" v-ctrl-enter="handleSubmit">
20+
<a-spin :spinning="loading">
21+
<a-form
22+
:ref="formRef"
23+
:model="form"
24+
:rules="rules"
25+
layout="vertical"
26+
@finish="handleSubmit">
27+
<a-form-item name="username" ref="username">
28+
<template #label>
29+
<tooltip-label :title="$t('label.username')" :tooltip="apiParams.username.description"/>
30+
</template>
31+
<a-input
32+
v-model:value="form.username"
33+
:placeholder="$t('label.username')"/>
34+
</a-form-item>
35+
<a-form-item name="password" ref="password">
36+
<template #label>
37+
<tooltip-label :title="$t('label.new.password')" :tooltip="apiParams.password.description"/>
38+
</template>
39+
<a-input-password
40+
v-model:value="form.password"
41+
:placeholder="$t('label.new.password')"/>
42+
</a-form-item>
43+
<a-form-item name="confirmpassword" ref="confirmpassword">
44+
<template #label>
45+
<tooltip-label :title="$t('label.confirmpassword')" :tooltip="apiParams.password.description"/>
46+
</template>
47+
<a-input-password
48+
v-model:value="form.confirmpassword"
49+
:placeholder="$t('label.confirmpassword.description')"/>
50+
</a-form-item>
51+
52+
<div :span="24" class="action-button">
53+
<a-button @click="closeAction">{{ $t('label.cancel') }}</a-button>
54+
<a-button :loading="loading" ref="submit" type="primary" @click="handleSubmit">{{ $t('label.ok') }}</a-button>
55+
</div>
56+
</a-form>
57+
</a-spin>
58+
</div>
59+
</template>
60+
61+
<script>
62+
import { ref, reactive, toRaw } from 'vue'
63+
import { api } from '@/api'
64+
import TooltipLabel from '@/components/widgets/TooltipLabel'
65+
66+
export default {
67+
name: 'ChangeHostPassword',
68+
components: {
69+
TooltipLabel
70+
},
71+
props: {
72+
resource: {
73+
type: Object,
74+
required: true
75+
}
76+
},
77+
data () {
78+
return {
79+
loading: false
80+
}
81+
},
82+
beforeCreate () {
83+
this.apiParams = this.$getApiParams('updateHostPassword')
84+
},
85+
created () {
86+
this.initForm()
87+
},
88+
methods: {
89+
initForm () {
90+
this.formRef = ref()
91+
this.form = reactive({})
92+
this.rules = reactive({
93+
username: [{ required: true, message: this.$t('message.error.host.username') }],
94+
password: [{ required: true, message: this.$t('message.error.new.password') }],
95+
confirmpassword: [
96+
{ required: true, message: this.$t('message.error.confirm.password') },
97+
{ validator: this.validateTwoPassword }
98+
]
99+
})
100+
},
101+
async validateTwoPassword (rule, value) {
102+
const messageConfirm = this.$t('message.validate.equalto')
103+
const passwordVal = this.form.password
104+
if (passwordVal && passwordVal !== value) {
105+
return Promise.reject(messageConfirm)
106+
}
107+
},
108+
handleSubmit (e) {
109+
e.preventDefault()
110+
if (this.loading) return
111+
this.formRef.value.validate().then(() => {
112+
const values = toRaw(this.form)
113+
this.loading = true
114+
const params = {
115+
username: values.username,
116+
hostId: this.resource.id,
117+
password: values.password
118+
}
119+
api('updateHostPassword', {}, 'POST', params).then(json => {
120+
this.$notification.success({
121+
message: this.$t('label.action.change.password'),
122+
description: `${this.$t('message.success.change.host.password', { name: this.resource.name })}`
123+
})
124+
this.$emit('refresh-data')
125+
this.closeAction()
126+
}).catch(error => {
127+
this.$notifyError(error)
128+
}).finally(() => {
129+
this.loading = false
130+
})
131+
}).catch(error => {
132+
this.formRef.value.scrollToField(error.errorFields[0].name)
133+
})
134+
},
135+
closeAction () {
136+
this.$emit('close-action')
137+
}
138+
}
139+
}
140+
</script>
141+
142+
<style scoped lang="less">
143+
.form-layout {
144+
width: 80vw;
145+
146+
@media (min-width: 600px) {
147+
width: 450px;
148+
}
149+
}
150+
</style>

0 commit comments

Comments
 (0)