Skip to content

Commit 6ac0524

Browse files
committed
added current password field
1 parent 8e4f481 commit 6ac0524

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

frontend/src/components/app/settings/AccountInput.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@
3434
<textarea style="resize: none;" rows="4" type="text" placeholder="Biography" v-model="currentValue" class="matcha-input md:max-w-sm block"></textarea>
3535
<span class="matcha-input-error">{{ errors[0] }}</span>
3636
</ValidationProvider>
37+
<ValidationProvider v-if="type === 'password'" name="Current Password" rules="required" v-slot="{errors}">
38+
<input type="password" placeholder="Current Password" v-model="passwordOld" class="matcha-input md:max-w-sm">
39+
<span class="matcha-input-error">{{ errors[0] }}</span>
40+
</ValidationProvider>
3741
<ValidationProvider v-if="type === 'password'" name="Password" rules="required|min:6|validPassword" v-slot="{errors}">
38-
<input type="password" placeholder="New Password" v-model="currentValue" class="matcha-input md:max-w-sm">
42+
<input type="password" placeholder="New Password" v-model="currentValue" class="matcha-input md:max-w-sm mt-4">
3943
<span class="matcha-input-error">{{ passwordErrorHandler(errors[0]) }}</span>
4044
</ValidationProvider>
4145
<ValidationProvider v-if="type === 'password'" name="Repeat Password" rules="required|confirmed:Password" v-slot="{errors}">
42-
<input type="password" placeholder="Repeat Password" v-model="passwordRepeat" class="matcha-input mt-4">
46+
<input type="password" placeholder="Repeat New Password" v-model="passwordRepeat" class="matcha-input">
4347
<span class="matcha-input-error">{{ passwordErrorHandler(errors[0]) }}</span>
4448
</ValidationProvider>
4549
</div>
@@ -57,6 +61,7 @@ export default {
5761
currentValueBackup: '',
5862
currentValue: '',
5963
passwordRepeat: '',
64+
passwordOld: '',
6065
}),
6166
methods: {
6267
startEditing() {
@@ -67,17 +72,21 @@ export default {
6772
if (this.type === 'password') {
6873
this.currentValue = '';
6974
this.passwordRepeat = '';
75+
this.passwordOld = '';
7076
}
7177
this.currentValue = this.currentValueBackup;
7278
this.edit = false;
7379
},
7480
onSubmit() {
7581
this.edit = false;
7682
this.currentValueBackup = this.currentValue;
77-
this.$emit('saveSingleChoice', this.type, this.currentValue);
78-
if (this.type === 'password') {
83+
if (this.type !== 'password') {
84+
this.$emit('saveSingleChoice', this.type, this.currentValue);
85+
} else {
86+
this.$emit('saveSingleChoiceOldGiven', this.type, this.currentValue, this.passwordOld);
7987
this.currentValue = '';
8088
this.passwordRepeat = '';
89+
this.passwordOld = '';
8190
}
8291
},
8392
passwordErrorHandler(error) {

frontend/src/views/app/Settings.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<AccountInput
5252
v-bind:name="'Password'"
5353
v-bind:type="'password'"
54-
v-on:saveSingleChoice="saveSingleChoice"
54+
v-on:saveSingleChoiceOldGiven="saveSingleChoiceOldGiven"
5555
v-bind:currentValuePassed="''"></AccountInput>
5656
</section>
5757
<section v-if="getShow === 'profile'" class="flex flex-col items-start z-10 absolute bg-white-matcha w-full top-0 left-0 md:ml-4 md:relative md:shadow-md md:rounded-md">
@@ -233,11 +233,9 @@ export default {
233233
} else if (key === 'lastName') {
234234
await this.$http.patch('/profile/edit/last_name', { last_name: value });
235235
} else if (key === 'email') {
236-
await this.$http.patch('/profile/edit/email', { email: value });
236+
await this.$http.put('/profile/edit/email', { email: value });
237237
} else if (key === 'username') {
238238
await this.$http.patch('/profile/edit/username', { username: value });
239-
} else if (key === 'password') {
240-
await this.$http.patch('/profile/edit/password', { password: value });
241239
} else if (key === 'bio') {
242240
await this.$http.patch('/profile/edit/bio', { bio: value });
243241
} else if (key === 'gender') {
@@ -248,6 +246,15 @@ export default {
248246
const user = await this.$http.get(`/users/${this.$store.getters.getLoggedInUser.id}`);
249247
await this.$store.dispatch('login', user.data);
250248
},
249+
async saveSingleChoiceOldGiven(...args) {
250+
const [key, value, old] = args;
251+
if (key === 'password') {
252+
await this.$http.put('/profile/edit/password', {
253+
old_password: old,
254+
new_password: value,
255+
});
256+
}
257+
},
251258
async saveMultipleChoice(...args) {
252259
const [key, value] = args;
253260
if (key === 'interests') {

0 commit comments

Comments
 (0)