Skip to content

Commit 23e2c64

Browse files
committed
implement password reset integration
1 parent 0f1d5ce commit 23e2c64

3 files changed

Lines changed: 64 additions & 48 deletions

File tree

client/pages/reset-password.vue

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Please enter <wbr />your registered email.
1212
</p>
1313
</div>
14+
<div class="text-white" v-if="emailLoading">Sending email...</div>
1415
<InputField
1516
:id="emailField.id"
1617
:key="emailField.index"
@@ -28,11 +29,13 @@
2829
class="gap-5 text-2xl font-bold text-white place-items-center"
2930
>
3031
<h1 class="text-3xl">Reset Link Has Been Sent!</h1>
31-
<p>Please check your spam folder if you cannot find the email.</p>
3232
<font-awesome-icon
3333
:icon="['fas', 'fa-face-smile-beam']"
3434
class="text-[10rem] my-10"
3535
/>
36+
<p class="text-center">
37+
Please check your spam folder if you cannot find the email.
38+
</p>
3639
</AuthForm>
3740

3841
<AuthForm
@@ -42,11 +45,11 @@
4245
:errors="errors"
4346
@submit="resetPassword"
4447
>
45-
<div class="mt-1 mb-3">
46-
<p v-if="uid !== ''" class="text-center text-white">
48+
<div class="mt-1 mb-3 text-white">
49+
<p v-if="uid !== ''" class="text-center">
4750
Resetting password for {{ uid }}
4851
</p>
49-
<p class="text-center text-white">Please enter <wbr />a new password.</p>
52+
<p class="text-center">Please enter <wbr />a new password.</p>
5053
</div>
5154
<InputField
5255
v-for="field in fields"
@@ -65,8 +68,8 @@
6568
v-else
6669
class="gap-5 text-2xl font-bold text-white place-items-center"
6770
>
68-
<h1 class="text-3xl">Congratulations!</h1>
69-
<p>
71+
<h1 class="text-3xl text-center">Congratulations!</h1>
72+
<p class="text-center">
7073
Your password has been reset. Now you <wbr />can login with your new
7174
password!
7275
</p>
@@ -92,6 +95,7 @@ export default {
9295
data: () => ({
9396
title: 'Reset Password',
9497
passwordResetSuccess: false,
98+
emailLoading: false,
9599
emailSentSuccess: false,
96100
uid: '',
97101
errors: [],
@@ -129,46 +133,12 @@ export default {
129133
},
130134
131135
async mounted() {
132-
const rawUid = this.$route.query.uid;
133-
const rawToken = this.$route.query.token;
134-
135-
if (!rawUid) {
136-
return;
137-
}
138-
139-
const formattedUid =
140-
rawUid.charAt(rawUid.length - 1) === '/'
141-
? rawUid.substring(0, rawUid.length - 1)
142-
: rawUid;
143-
144-
const formattedToken =
145-
rawUid.charAt(rawUid.length - 1) === '/'
146-
? rawUid.substring(0, rawUid.length - 1)
147-
: rawUid;
148-
149-
const url =
150-
'auth/reset/' + `?token=${this.formattedToken}&uid=${this.formattedUid}/`;
151-
152-
try {
153-
this.uid = atob(formattedUid);
154-
console.log(this.uid);
155-
} catch (err) {
156-
console.log(err);
157-
this.errors = { Errors: ['email UID is invalid'] };
158-
return;
159-
}
160-
161-
await this.$axios
162-
.$get(url)
163-
.then((resp) => (this.emailSentSuccess = true))
164-
.catch((error) => {
165-
this.errors = error.response.data;
166-
console.log(error.response.data);
167-
});
136+
this.resetPassword();
168137
},
169138
170139
methods: {
171140
async sendResetLink(e) {
141+
this.emailLoading = true;
172142
const elements = e.target.elements;
173143
const data = {
174144
email: elements.Email.value,
@@ -177,14 +147,60 @@ export default {
177147
const url = 'auth/reset/email/';
178148
await this.$axios
179149
.$post(url, data)
180-
.then((resp) => (this.passwordResetSuccess = true))
150+
.then((resp) => (this.emailSentSuccess = true))
181151
.catch((error) => {
182152
this.errors = error.response.data;
183-
console.log(error.response.data);
153+
this.emailLoading = false;
184154
});
185155
},
186156
187-
resetPassword() {},
157+
async resetPassword(e = null) {
158+
const rawUid = this.$route.query.uid;
159+
const rawToken = this.$route.query.token;
160+
161+
if (!rawUid) {
162+
return;
163+
}
164+
165+
const formattedUid =
166+
rawUid.charAt(rawUid.length - 1) === '/'
167+
? rawUid.substring(0, rawUid.length - 1)
168+
: rawUid;
169+
170+
const formattedToken =
171+
rawToken.charAt(rawToken.lengthrawToken - 1) === '/'
172+
? rawToken.substring(0, rawToken.length - 1)
173+
: rawToken;
174+
175+
const url =
176+
'auth/reset/' + `?token=${formattedToken}&uid=${formattedUid}/`;
177+
178+
try {
179+
this.uid = atob(formattedUid);
180+
} catch (err) {
181+
this.errors = { Errors: ['email UID is invalid'] };
182+
return;
183+
}
184+
185+
if (e !== null) {
186+
const elements = e.target.elements;
187+
const data = {
188+
password: elements.Password.value,
189+
};
190+
await this.$axios
191+
.$put(url, data)
192+
.then((resp) => (this.passwordResetSuccess = true))
193+
.catch((error) => {
194+
this.errors = error.response.data;
195+
console.log(error.response.data);
196+
});
197+
} else {
198+
await this.$axios.$get(url).catch((error) => {
199+
this.errors = error.response.data;
200+
console.log(error.response.data);
201+
});
202+
}
203+
},
188204
},
189205
};
190206
</script>

client/pages/sign-up.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
v-else
2727
class="gap-5 text-2xl font-bold text-white place-items-center"
2828
>
29-
<h1 class="text-3xl">Congratulations {{ name }}!</h1>
30-
<p>
29+
<h1 class="text-3xl text-center">Congratulations {{ name }}!</h1>
30+
<p class="text-center">
3131
Your new Elucidate account <wbr />
3232
has been created
3333
</p>

server/api/apps/auth/reset_password/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def post(self, request):
123123
"Elucidate Password Reset",
124124
f"Your password reset link can be found at: {reset_url}\n"
125125
+ "It will expire in"
126-
f" {settings.PASSWORD_RESET_TIMEOUT / 60} minutes.",
126+
f" {settings.PASSWORD_RESET_TIMEOUT // 60} minutes.",
127127
settings.EMAIL_HOST_USER,
128128
[email],
129129
fail_silently=False,

0 commit comments

Comments
 (0)