-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathPasswordModal.vue
More file actions
139 lines (131 loc) · 3.58 KB
/
PasswordModal.vue
File metadata and controls
139 lines (131 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template lang='pug'>
modal-template(class='is-centered is-left-aligned' back-on-mobile=true ref='modalTemplate' data-test='PasswordModal' :a11yTitle='L("Change Password")')
template(slot='title') Change password
form(
novalidate
ref='form'
name='formData'
@submit.prevent='changePassword'
)
password-form(
name='current'
:label='L("Current Password")'
:value='form'
:$v='$v'
@enter='changePassword'
:showPlaceholder='false'
:showPassword='false'
size='is-large'
)
password-form(
name='newPassword'
:label='L("New Password")'
:value='form'
:$v='$v'
@enter='changePassword'
:showPlaceholder='false'
:showPassword='false'
size='is-large'
)
password-form(
name='confirm'
:label='L("Confirm new Password")'
:value='form'
:$v='$v'
@enter='changePassword'
:showPlaceholder='false'
:showPassword='false'
size='is-large'
)
banner-scoped(ref='formMsg')
.buttons
i18n.is-outlined(
tag='button'
type='button'
data-test='cancel'
@click='closeModal'
) Cancel
button-submit(
@click='changePassword'
data-test='submit'
:disabled='$v.form.$invalid || processing'
) {{ L('Change password') }}
</template>
<script>
import { validationMixin } from 'vuelidate'
import ModalTemplate from '@components/modal/ModalTemplate.vue'
import BannerScoped from '@components/banners/BannerScoped.vue'
import ButtonSubmit from '@components/ButtonSubmit.vue'
import PasswordForm from '@containers/access/PasswordForm.vue'
import { IDENTITY_PASSWORD_MIN_CHARS as passwordMinChars } from '@model/contracts/shared/constants.js'
import sbp from '@sbp/sbp'
import { required, minLength } from 'vuelidate/lib/validators'
import sameAs from 'vuelidate/lib/validators/sameAs.js'
import { L } from '@common/common.js'
import { Secret } from '@chelonia/lib/Secret'
export default ({
name: 'PasswordModal',
mixins: [validationMixin],
data () {
return {
form: {
current: null,
newPassword: null,
confirm: null
},
processing: false
}
},
validations: {
form: {
current: {
[L('Your current password is required.')]: required
},
newPassword: {
[L('A password is required.')]: required,
nonWhitespace: value => /^\S+$/.test(value),
[L('Your password must be at least {minChars} characters long.', { minChars: passwordMinChars })]: minLength(passwordMinChars)
},
confirm: {
[L('Please confirm your password.')]: required,
[L('Passwords do not match.')]: sameAs('newPassword')
}
}
},
components: {
BannerScoped,
ButtonSubmit,
ModalTemplate,
PasswordForm
},
methods: {
closeModal () {
// We access directly the modal here to avoid broacasting event to every possible modal
this.$refs.modalTemplate.close()
},
changePassword () {
if (this.processing) return
this.processing = true
;(async () => {
try {
await sbp('gi.app/identity/changePassword',
new Secret(this.form.current),
new Secret(this.form.newPassword)
)
this.closeModal()
} catch (error) {
console.error('[PasswordModal.vue]', error)
this.$refs.formMsg.danger(L('Invalid password'))
}
})().finally(() => {
this.processing = false
})
}
}
}: Object)
</script>
<style lang="scss" scoped>
.modal-card-body {
padding-top: 0;
}
</style>