Skip to content

Commit 71e1018

Browse files
author
oguzhan.onder
committed
added forgot password
1 parent 13c13ad commit 71e1018

File tree

8 files changed

+214
-36
lines changed

8 files changed

+214
-36
lines changed

src/components/ChangePassword.vue

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<template>
2+
<div class="d-flex align-items-center min-vh-100">
3+
<CContainer fluid>
4+
<CRow class="justify-content-center">
5+
<CCol md="6">
6+
<CCard class="mx-4 mb-0">
7+
<CCardBody class="p-4">
8+
<CForm>
9+
<h1>Change Password</h1>
10+
<p class="text-muted">{{message}}</p>
11+
<div v-if="this.key === 'valid'">
12+
<CInput
13+
v-model="passwordDto.password"
14+
placeholder="Password"
15+
type="password"
16+
autocomplete="new-password"
17+
>
18+
<template #prepend-content>
19+
<CIcon name="cil-lock-locked"/>
20+
</template>
21+
</CInput>
22+
<CInput
23+
v-model="passwordDto.matchingPassword"
24+
placeholder="Repeat password"
25+
type="password"
26+
autocomplete="new-password"
27+
class="mb-4"
28+
>
29+
<template #prepend-content>
30+
<CIcon name="cil-lock-locked"/>
31+
</template>
32+
</CInput>
33+
<CButton color="success" @click="changePassword" block>Change Password</CButton>
34+
</div>
35+
<CButton color="primary" @click="goToLoginPage" block>Go to Login Page</CButton>
36+
</CForm>
37+
</CCardBody>
38+
</CCard>
39+
</CCol>
40+
</CRow>
41+
</CContainer>
42+
</div>
43+
44+
</template>
45+
46+
<script>
47+
import * as util from '../util/util';
48+
49+
export default {
50+
name: "ChangePassword",
51+
data() {
52+
return {
53+
passwordDto: {
54+
password: null,
55+
matchingPassword: null
56+
},
57+
message: null,
58+
key: null,
59+
id: null
60+
}
61+
},
62+
methods: {
63+
changePassword() {
64+
this.$store.dispatch("changePassword", [this.id ,this.passwordDto]);
65+
},
66+
goToLoginPage() {
67+
util.common.routePush("login");
68+
}
69+
},
70+
created() {
71+
let split = this.$route.path.split("/");
72+
let param1 = split[split.length - 2];
73+
let param2 = split[split.length - 1];
74+
if (param1 !== undefined && param1.length > 0 && param2 !== undefined && param2.length > 0) {
75+
this.$store.dispatch("changePasswordTokenControl", {param1, param2})
76+
.then(res => {
77+
if (res) {
78+
this.message = res.body.message;
79+
this.key = res.body.key;
80+
this.id = res.body.data;
81+
}
82+
})
83+
}
84+
85+
}
86+
}
87+
</script>
88+
89+
<style scoped>
90+
91+
</style>

src/components/ForgotPassword.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
methods: {
4646
sendEmail() {
47-
47+
this.$store.dispatch("userForgotPassword",this.email);
4848
},
4949
goToLogin() {
5050
util.common.routePush("login");

src/components/Register.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</template>
5555
</CInput>
5656
<CButton color="success" @click="createUser" block>Create Account</CButton>
57-
<CButton color="info" @click="goToLoginPage" block>Go to Login Page</CButton>
57+
<CButton color="primary" @click="goToLoginPage" block>Go to Login Page</CButton>
5858
</CForm>
5959
</CCardBody>
6060
</CCard>
@@ -87,6 +87,7 @@
8787
util.common.routePush("login");
8888
},
8989
createUser() {
90+
this.user.roleCode = "USER";
9091
this.$store.dispatch("userRegister", this.user);
9192
}
9293
}

src/components/UserConfirmation.vue

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44
<CRow class="justify-content-center">
55
<CJumbotron>
66
<h1 class="display-4">
7+
User Confirmation Info
8+
</h1>
9+
<h1 class="display-6">
710
<CAlert>
811
{{message}}
912
</CAlert>
1013
</h1>
11-
<CAlert
12-
:show.sync="currentAlertCounter"
13-
>
14-
You will be redirected to Login page in {{currentAlertCounter}} seconds.
15-
<CProgress
16-
:max="10"
17-
:value="currentAlertCounter"
18-
height="3px"
19-
color="primary"
20-
animate
21-
/>
22-
</CAlert>
14+
<div v-if="this.key === 'valid'">
15+
<CAlert
16+
:show.sync="currentAlertCounter"
17+
>
18+
You will be redirected to Login page in {{currentAlertCounter}} seconds.
19+
<CProgress
20+
:max="10"
21+
:value="currentAlertCounter"
22+
height="3px"
23+
color="primary"
24+
animate
25+
/>
26+
</CAlert>
27+
<p>If you don't want to wait please click</p>
28+
</div>
2329

24-
<p>If you don't want to wait please click</p>
2530
<CButton @click="goToLogin" color="primary">Go to Login Page</CButton>
31+
<CButton v-if = "this.key !== 'valid'" @click="reSend" color="primary">Resend Confirmation Code</CButton>
32+
2633
</CJumbotron>
2734
</CRow>
2835
</CContainer>
@@ -37,12 +44,17 @@
3744
data() {
3845
return {
3946
message: "",
40-
currentAlertCounter: 0
47+
currentAlertCounter: 0,
48+
key: "",
49+
id : ""
4150
}
4251
},
4352
methods: {
4453
goToLogin() {
4554
util.common.routePush("login");
55+
},
56+
reSend(){
57+
this.$store.dispatch("reSendConfirmation", this.id)
4658
}
4759
},
4860
watch: {
@@ -54,12 +66,15 @@
5466
},
5567
created() {
5668
let split = this.$route.path.split("/");
57-
let param = split[split.length - 1];
58-
if (param !== undefined && param.length > 0) {
59-
this.$store.dispatch("registerConfirm", param)
69+
let param1 = split[split.length - 2];
70+
let param2 = split[split.length - 1];
71+
if (param1 !== undefined && param1.length > 0 && param2 !== undefined && param2.length > 0) {
72+
this.$store.dispatch("registerConfirm", {param1, param2})
6073
.then(res => {
6174
if (res) {
62-
this.message = res.bodyText;
75+
this.message = res.body.message;
76+
this.key = res.body.key;
77+
this.id = res.body.data;
6378
this.currentAlertCounter = 10;
6479
}
6580
})

src/store/actions.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const getTradeResult = ({commit}) => {
2424
})
2525
};
2626

27-
export const registerConfirm = (vueContext, param) => {
28-
return util.service.get("user/registrationConfirm/" + param)
27+
export const registerConfirm = (vueContext, {param1, param2}) => {
28+
return util.service.get("user/registrationConfirm/" + param1 + "/" + param2)
2929
.then(response => {
3030
if (response) {
3131
util.common.control(response);
@@ -36,6 +36,47 @@ export const registerConfirm = (vueContext, param) => {
3636
})
3737
};
3838

39+
export const changePasswordTokenControl = (vueContext, {param1, param2}) => {
40+
return util.service.get("user/changePassword/" + param1 + "/" + param2)
41+
.then(response => {
42+
if (response) {
43+
util.common.control(response);
44+
return response;
45+
}
46+
}).catch(error => {
47+
util.common.control(error)
48+
})
49+
};
50+
51+
export const changePassword = (vueContext, [id,param]) => {
52+
param.password = util.randomCode(param.password);
53+
param.matchingPassword = util.randomCode(param.matchingPassword);
54+
util.service.put("user/changePassword/" + id, param)
55+
.then(response => {
56+
if (response) {
57+
let toast = util.common.successToast(response.bodyText);
58+
util.common.control(response);
59+
util.common.routePush("login");
60+
}
61+
}).catch(error => {
62+
util.common.control(error)
63+
})
64+
util.common.setNull(param);
65+
};
66+
67+
export const reSendConfirmation = (vueContext, param) => {
68+
util.service.put("user/reSendConfirmation", param)
69+
.then(response => {
70+
if (response) {
71+
let toast = util.common.successToast(response.bodyText);
72+
util.common.control(response);
73+
util.common.routePush("login");
74+
}
75+
}).catch(error => {
76+
util.common.control(error)
77+
})
78+
};
79+
3980
export const getUserAndMenus = (vueContext) => {
4081
return util.service.get("user/menus")
4182
.then(response => {
@@ -88,7 +129,7 @@ export const userRegister = (vueContext, registerData) => {
88129
util.service.post("user/registration", registerData)
89130
.then(response => {
90131
if (response) {
91-
let toast = util.common.successToast("Lütfen mailinizi kontrol edin...");
132+
let toast = util.common.successToast(response.bodyText);
92133
util.common.control(response, toast);
93134
util.common.routePush("login");
94135
return response;
@@ -100,6 +141,22 @@ export const userRegister = (vueContext, registerData) => {
100141
util.common.setNull(registerData);
101142
};
102143

144+
export const userForgotPassword = (vueContext, email) => {
145+
util.service.put("user/forgotPassword", email)
146+
.then(response => {
147+
if (response) {
148+
let toast = util.common.successToast(response.bodyText);
149+
util.common.control(response, toast);
150+
util.common.routePush("login");
151+
}
152+
153+
}).catch(error => {
154+
util.common.control(error);
155+
});
156+
util.common.setNull(email);
157+
};
158+
159+
103160
export const setTimeOutTimerExpiry = (vueContext, expiry) => {
104161
setTimeout(() => {
105162
vueContext.dispatch("logout");

src/store/modules/product.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const actions = {
5252
};
5353
dispatch("setTradeResult", tradeResult);
5454
}
55-
let toast = util.common.successToast("İşlem Başarılı Şekilde Gerçekleşti...");
55+
let toast = util.common.successToast("Saved successfully.");
5656
util.common.control(response, toast);
5757

5858
}).catch(error => {

src/util/router.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const UserConfirmation = () => System.import('../components/UserConfirmation');
4343
const Login = () => System.import('../components/Login');
4444
const Register = () => System.import('../components/Register');
4545
const ForgotPassword = () => System.import('../components/ForgotPassword');
46+
const ChangePassword = () => System.import('../components/ChangePassword');
4647

4748
Vue.use(VueRouter);
4849

@@ -106,11 +107,22 @@ const routes = [
106107
component: UserConfirmation,
107108
children: [
108109
{
109-
path: ":param",
110+
path: ":param1/:param2",
110111
component: UserConfirmation,
111112
}
112113
]
113114
},
115+
{
116+
path: "/user/changePassword",
117+
name: "ChangePassword",
118+
component: ChangePassword,
119+
children: [
120+
{
121+
path: ":param1/:param2",
122+
component: ChangePassword,
123+
}
124+
]
125+
},
114126
{
115127
path: "/login",
116128
name: "Login",

src/util/util.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ export const common = {
5252
case 401 :
5353
this.logoutSuccessfully();
5454
if (result.body !== undefined && result.body.message !== undefined) {
55-
toast = this.prepareToast("Login Hatası", toastType.ERROR, result.body.message, true);
55+
toast = this.prepareToast("Login Error", toastType.ERROR, result.body.message, true);
5656
store.commit("setMyToast", toast);
5757
}
5858
break;
5959
case 403 :
60-
toast = this.prepareToast("Erişim Engeli", toastType.FORBIDDEN, "Bu işlem için yetkiniz bulunmamaktadır.", true);
60+
toast = this.prepareToast("Access Denial", toastType.FORBIDDEN, "You are not authorized for this transaction.", true);
6161
store.commit("setMyToast", toast);
6262
break;
6363
case 404 :
@@ -67,7 +67,7 @@ export const common = {
6767
}
6868
break;
6969
case 500 :
70-
toast = this.prepareToast("Hata", toastType.ERROR, "İşlem Gerçekleştirilemedi. Bir Hata Oluştu", true);
70+
toast = this.prepareToast("Error", toastType.ERROR, "The operation could not be performed. Something went wrong", true);
7171
store.commit("setMyToast", toast);
7272
break;
7373
}
@@ -140,7 +140,7 @@ export const common = {
140140
return toast;
141141
},
142142
successToast(message) {
143-
let toast = common.prepareToast("Bilgi", toastType.SUCCESS, message, true);
143+
let toast = common.prepareToast("Information", toastType.SUCCESS, message, true);
144144
return toast;
145145
},
146146
prepareMenus(values) {
@@ -190,13 +190,15 @@ export const common = {
190190
};
191191
},
192192
setNull(object) {
193-
let entries = Object.entries(object);
194-
entries.forEach(([k, v]) => {
195-
if (v !== null && typeof v === "object") {
196-
this.setNull(object[k])
197-
}
198-
object[k] = null;
199-
});
193+
if(typeof object === "object"){
194+
let entries = Object.entries(object);
195+
entries.forEach(([k, v]) => {
196+
if (v !== null && typeof v === "object") {
197+
this.setNull(object[k])
198+
}
199+
object[k] = null;
200+
});
201+
}
200202
}
201203
};
202204

0 commit comments

Comments
 (0)