Skip to content

Commit 7f591e7

Browse files
Hoang Nguyenyadvr
authored andcommitted
iam: Add user - duplicated password field (#217)
Fixes #175 Signed-off-by: Rohit Yadav <[email protected]>
1 parent bb1e135 commit 7f591e7

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

ui/src/config/section/account.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default {
5353
icon: 'plus',
5454
label: 'label.add.account',
5555
listView: true,
56-
args: ['username', 'password', 'email', 'firstname', 'lastname', 'domainid', 'account', 'roleid', 'timezone', 'networkdomain']
56+
args: ['username', 'password', 'confirmpassword', 'email', 'firstname', 'lastname', 'domainid', 'account', 'roleid', 'timezone', 'networkdomain']
5757
},
5858
{
5959
api: 'ldapCreateAccount',

ui/src/config/section/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
icon: 'plus',
3030
label: 'label.add.user',
3131
listView: true,
32-
args: ['username', 'password', 'email', 'firstname', 'lastname', 'timezone', 'account', 'domainid']
32+
args: ['username', 'password', 'confirmpassword', 'email', 'firstname', 'lastname', 'timezone', 'account', 'domainid']
3333
},
3434
{
3535
api: 'updateUser',

ui/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@
539539
"label.confirmation": "Confirmation",
540540
"label.confirmdeclineinvitation": "Are you sure you want to decline this project invitation?",
541541
"label.confirmpassword": "Confirm Password",
542+
"label.confirmpassword.description": "Please type the same password again",
542543
"label.congratulations": "Congratulations!",
543544
"label.connectiontimeout": "Connection Timeout",
544545
"label.conservemode": "Conserve mode",

ui/src/views/AutogenView.vue

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,21 @@
231231
:placeholder="field.description"
232232
/>
233233
</span>
234-
<span v-else-if="field.name==='password' || field.name==='currentpassword'">
234+
<span v-else-if="field.name==='password' || field.name==='currentpassword' || field.name==='confirmpassword'">
235235
<a-input-password
236236
v-decorator="[field.name, {
237-
rules: [{ required: field.required, message: `${$t('message.error.required.input')}` }]
237+
rules: [
238+
{
239+
required: field.required,
240+
message: `${$t('message.error.required.input')}`
241+
},
242+
{
243+
validator: validateTwoPassword
244+
}
245+
]
238246
}]"
239247
:placeholder="field.description"
248+
@blur="($event) => handleConfirmBlur($event, field.name)"
240249
/>
241250
</span>
242251
<span v-else-if="field.name==='certificate' || field.name==='privatekey' || field.name==='certchain'">
@@ -357,7 +366,8 @@ export default {
357366
treeData: [],
358367
treeSelected: {},
359368
actionData: [],
360-
formModel: {}
369+
formModel: {},
370+
confirmDirty: false
361371
}
362372
},
363373
computed: {
@@ -609,6 +619,7 @@ export default {
609619
this.currentAction = {}
610620
},
611621
execAction (action) {
622+
const self = this
612623
this.form = this.$form.createForm(this)
613624
this.formModel = {}
614625
this.actionData = []
@@ -635,6 +646,14 @@ export default {
635646
}
636647
if (args.length > 0) {
637648
this.currentAction.paramFields = args.map(function (arg) {
649+
if (arg === 'confirmpassword') {
650+
return {
651+
type: 'password',
652+
name: 'confirmpassword',
653+
required: true,
654+
description: self.$t('label.confirmpassword.description')
655+
}
656+
}
638657
return paramFields.filter(function (param) {
639658
return param.name.toLowerCase() === arg.toLowerCase()
640659
})[0]
@@ -908,6 +927,40 @@ export default {
908927
},
909928
finishLoading () {
910929
this.loading = false
930+
},
931+
handleConfirmBlur (e, name) {
932+
if (name !== 'confirmpassword') {
933+
return
934+
}
935+
const value = e.target.value
936+
this.confirmDirty = this.confirmDirty || !!value
937+
},
938+
validateTwoPassword (rule, value, callback) {
939+
if (!value || value.length === 0) {
940+
callback()
941+
} else if (rule.field === 'confirmpassword') {
942+
const form = this.form
943+
const messageConfirm = this.$t('message.validate.equalto')
944+
const passwordVal = form.getFieldValue('password')
945+
if (passwordVal && passwordVal !== value) {
946+
callback(messageConfirm)
947+
} else {
948+
callback()
949+
}
950+
} else if (rule.field === 'password') {
951+
const form = this.form
952+
const confirmPasswordVal = form.getFieldValue('confirmpassword')
953+
if (!confirmPasswordVal || confirmPasswordVal.length === 0) {
954+
callback()
955+
} else if (value && this.confirmDirty) {
956+
form.validateFields(['confirmpassword'], { force: true })
957+
callback()
958+
} else {
959+
callback()
960+
}
961+
} else {
962+
callback()
963+
}
911964
}
912965
}
913966
}

0 commit comments

Comments
 (0)