Skip to content

Commit 983d48a

Browse files
committed
save
1 parent 7cff8ad commit 983d48a

File tree

2 files changed

+61
-75
lines changed

2 files changed

+61
-75
lines changed

src/components/identityForm/actions.vue

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ div.flex
3030
q-card(style="width:800px")
3131
q-card-section(class="text-h6 bg-primary text-white") definition du mot de passe
3232
q-card-section
33-
input-new-password(v-model="newpassword"
34-
:min="passwordPolicies.len"
35-
:min-upper="passwordPolicies.hasUpperCase"
36-
:min-lower="passwordPolicies.hasLowerCase"
37-
:min-number="passwordPolicies.hasNumbers"
38-
:min-special="passwordPolicies.hasSpecialChars"
39-
:min-entropy="passwordPolicies.minComplexity"
40-
:entropy-bad="passwordPolicies.minComplexity"
41-
:entropy-good="passwordPolicies.goodComplexity"
42-
:check-pwned="passwordPolicies.checkPwned")
33+
input-new-password(v-model="newpassword")
4334
q-card-actions(align="right" class="bg-white text-teal")
4435
q-btn( label="Abandonner" color="negative" @click="resetPasswordModal = false" )
45-
q-btn( label="Sauver" color="positive" @click="resetPasswordModal = false" :disabled="newpassword === ''")
36+
q-btn( label="Sauver" color="positive" @click="doChangePassword" :disabled="newpassword === ''")
4637

4738
</template>
4839

@@ -57,20 +48,7 @@ import { useIdentityStates } from '~/composables'
5748
import { useErrorHandling } from '#imports'
5849
import InputNewPassword from "~/components/inputNewPassword.vue";
5950
const resetPasswordModal=ref(false)
60-
const passwordPolicies = ref({
61-
bannedTime: 3600,
62-
checkPwned: true,
63-
goodComplexity: 60,
64-
hasLowerCase: 1,
65-
hasNumbers: 1,
66-
hasSpecialChars: 1,
67-
hasUpperCase: 1,
68-
len: 10,
69-
maxRetry: 10,
70-
minComplexity: 20,
71-
resetBySms: false,
72-
redirectUrl: ''
73-
})
51+
7452
7553
const newpassword=ref('')
7654
type IdentityResponse = operations['IdentitiesController_search']['responses']['200']['content']['application/json']
@@ -97,6 +75,27 @@ const { handleError } = useErrorHandling()
9775
9876
const emits = defineEmits(['submit', 'sync', 'logs', 'create', 'delete'])
9977
78+
async function doChangePassword(){
79+
const requestOptions={method: 'POST',
80+
body:JSON.stringify({id:props.identity._id,newPassword: newpassword.value})}
81+
try{
82+
const data=await $http.post('/management/identities/forcepassword', requestOptions)
83+
$q.notify({
84+
message: 'Le mot de passe a été changé : ',
85+
color: 'positive',
86+
position: 'top-right',
87+
icon: 'mdi-check-circle-outline',
88+
})
89+
}catch(error){
90+
$q.notify({
91+
message: 'Impossible de modifier le mot de passe : ' + error.response._data.message,
92+
color: 'negative',
93+
position: 'top-right',
94+
icon: 'mdi-alert-circle-outline',
95+
})
96+
}
97+
resetPasswordModal.value = false
98+
}
10099
async function submit() {
101100
// console.log('submit from actions')
102101
emits('submit')
@@ -135,7 +134,6 @@ async function activate(){
135134
bouton="Activer"
136135
initialStatus=0
137136
}
138-
debugger
139137
if (showActivate() === false){
140138
props.identity.dataStatus = initialStatus
141139
return

src/components/inputNewPassword.vue

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<q-icon :name="has_len" :color="has_len_color" size="xs" style="margin: 0px;"></q-icon>
2121
&nbsp;doit avoir au moins {{min}} caractères
2222
</p>
23-
<p v-show="minUpper > 0" style="margin: 0px;">
23+
<p style="margin: 0px;">
2424
<q-icon :name="has_upper" :color="has_upper_color" size="xs" ></q-icon>
2525
&nbsp;doit comporter au moins {{minUpper}} majuscules
2626
</p>
@@ -79,44 +79,29 @@ const progress=ref(0)
7979
const progress_color=ref('red')
8080
const typePasswordProp=ref('password')
8181
const typeConfirmProp=ref('password')
82-
const props = defineProps({
83-
min: {
84-
type: Number,
85-
default:8},
86-
minUpper:{
87-
type: Number,
88-
default:1
89-
},
90-
minLower:{
91-
type: Number,
92-
default:1
93-
},
94-
minNumber:{
95-
type: Number,
96-
default:1
97-
},
98-
minSpecial:{
99-
type:Number,
100-
default:1
101-
},
102-
minEntropy:{
103-
type:Number,
104-
default:30
105-
},
106-
entropyBad:{
107-
type:Number,
108-
default:10
109-
},
110-
entropyGood:{
111-
type:Number,
112-
default:80
113-
},
114-
checkPwned:{
115-
type:Boolean,
116-
default:true
117-
}
118-
})
82+
const minLower=ref(1)
83+
const minUpper=ref(1)
84+
const minNumber=ref(1)
85+
const minSpecial=ref(1)
86+
const minEntropy=ref(20)
87+
const checkPwned=ref(false)
88+
const min=ref(5)
89+
const { data: props} = await useHttp('/management/passwd/getpolicies',
90+
{
91+
method:'GET',
92+
transform:(result)=> {
93+
return result.data
94+
}
11995
96+
}
97+
)
98+
minLower.value=props.value.hasLowerCase
99+
minUpper.value=props.value.hasUpperCase
100+
minNumber.value=props.value.hasNumbers
101+
minSpecial.value=props.value.hasSpecialChars
102+
minEntropy.value=props.value.minComplexity
103+
checkPwned.value=props.value.checkPwned
104+
min.value=props.value.len
120105
async function checkPassword(ev, type) {
121106
let newP = newPassword.value
122107
let confirmP = confirmNewPassword.value
@@ -130,13 +115,16 @@ async function checkPassword(ev, type) {
130115
console.log('emit ' + newPassword.value)
131116
//avant d accepter on cherche dans l api de pwned
132117
try{
133-
if (props.checkPwned === true ){
118+
if (checkPwned.value === true ){
134119
const numPwns = await pwnedPassword(newP);
135120
136121
if (numPwns >0){
137122
iconIsPwnedOK(false)
138123
$q.notify({
139124
message: '<text-weight-medium>Ce mot de passe est déjà apparu lors d\'une violation de données. Vous ne pouvez pas l\'utiliser</text-weight-medium>',
125+
html:true,
126+
color: 'negative',
127+
multiLine: true,
140128
})
141129
emit('update:modelValue', '')
142130
return
@@ -164,7 +152,7 @@ async function checkPassword(ev, type) {
164152
function checkPolicy(password) {
165153
has_len.value='highlight_off'
166154
let statut=true
167-
if (props.minSpecial >= 1){
155+
if (minSpecial.value >= 1){
168156
if (/[!@#\$%\^\&*\)\(+=._-]/.test(password) === false){
169157
pwdColor.value = 'red'
170158
iconSpecialOK(false)
@@ -173,7 +161,7 @@ function checkPolicy(password) {
173161
iconSpecialOK(true)
174162
}
175163
}
176-
if (props.minNumber >= 1) {
164+
if (minNumber.value >= 1) {
177165
if (/\d/.test(password) === false) {
178166
pwdColor.value = 'red'
179167
iconNumberOK(false)
@@ -182,7 +170,7 @@ function checkPolicy(password) {
182170
iconNumberOK(true)
183171
}
184172
}
185-
if (props.minLower >= 1) {
173+
if (minLower.value >= 1) {
186174
if (/[a-z]/.test(password) === false) {
187175
pwdColor.value = 'red'
188176
iconLowerOK(false)
@@ -191,7 +179,7 @@ function checkPolicy(password) {
191179
iconLowerOK(true)
192180
}
193181
}
194-
if (props.minUpper >= 1) {
182+
if (minUpper.value >= 1) {
195183
if (/[A-Z]/.test(password) === false) {
196184
pwdColor.value = 'red'
197185
iconUpperOK(false)
@@ -200,8 +188,8 @@ function checkPolicy(password) {
200188
iconUpperOK(true)
201189
}
202190
}
203-
if (password.length < props.min) {
204-
console.log('trop court ' + props.min)
191+
if (password.length < min.value) {
192+
console.log('trop court ' + min.value)
205193
iconLenOK(false)
206194
statut=false
207195
}else{
@@ -287,18 +275,18 @@ function iconIsPwnedOK(value){
287275
}
288276
function complexity(password){
289277
console.log(stringEntropy(password))
290-
if (props.minEntropy > 0){
278+
if (minEntropy.value > 0){
291279
let c = stringEntropy(password)
292280
progress.value = c / 100
293281
console.log('entropy' + c)
294-
if (c < props.entropyBad) {
282+
if (c < props.value.minComplexity) {
295283
progress_color.value = 'red'
296-
} else if (c >= props.entropyBad && c < props.entropyGood) {
284+
} else if (c >= props.value.minComplexity && c < props.value.goodComplexity) {
297285
progress_color.value = 'warning'
298286
} else {
299287
progress_color.value = 'green'
300288
}
301-
if (c >= props.minEntropy) {
289+
if (c >= minEntropy.value) {
302290
return true
303291
} else {
304292
return false

0 commit comments

Comments
 (0)