Skip to content

Commit c3f74f2

Browse files
dxvladislavvolkovdxvladislavvolkov
authored andcommitted
Implement auth
1 parent e8b53b2 commit c3f74f2

File tree

10 files changed

+654
-96
lines changed

10 files changed

+654
-96
lines changed

src/auth.js

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,106 @@
1-
let authenticated = true;
1+
const defaultPath = '/';
2+
const defaultUser = {
3+
email: 'sandra@example.com',
4+
avatarUrl: 'https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/images/employees/06.png'
5+
};
6+
27
export default {
3-
authenticated() {
4-
return authenticated;
8+
_user: defaultUser,
9+
loggedIn() {
10+
return !!this._user;
11+
},
12+
_lastAuthenticatedPath: defaultPath,
13+
lastAuthenticatedPath(value) {
14+
this._lastAuthenticatedPath = value;
15+
},
16+
17+
async logIn(email, password) {
18+
try {
19+
// Send request
20+
console.log(email, password);
21+
this._user = { ...defaultUser, email };
22+
23+
return {
24+
isOk: true,
25+
data: this._user
26+
};
27+
}
28+
catch {
29+
return {
30+
isOk: false,
31+
message: "Authentication failed"
32+
};
33+
}
34+
},
35+
36+
async logOut() {
37+
this._user = null;
38+
},
39+
40+
async getUser() {
41+
try {
42+
// Send request
43+
44+
return {
45+
isOk: true,
46+
data: this._user
47+
};
48+
}
49+
catch {
50+
return {
51+
isOk: false
52+
};
53+
}
54+
},
55+
56+
async resetPassword(email) {
57+
try {
58+
// Send request
59+
console.log(email);
60+
61+
return {
62+
isOk: true
63+
};
64+
}
65+
catch {
66+
return {
67+
isOk: false,
68+
message: "Failed to reset password"
69+
};
70+
}
571
},
6-
logIn() {
7-
authenticated = true;
72+
73+
async changePassword(email, recoveryCode) {
74+
try {
75+
// Send request
76+
console.log(email, recoveryCode);
77+
78+
return {
79+
isOk: true
80+
};
81+
}
82+
catch {
83+
return {
84+
isOk: false,
85+
message: "Failed to change password"
86+
}
87+
}
888
},
9-
logOut() {
10-
authenticated = false;
89+
90+
async createAccount(email, password) {
91+
try {
92+
// Send request
93+
console.log(email, password);
94+
95+
return {
96+
isOk: true
97+
};
98+
}
99+
catch {
100+
return {
101+
isOk: false,
102+
message: "Failed to create account"
103+
};
104+
}
11105
}
12106
};

src/components/header-toolbar.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
height="100%"
4141
styling-mode="text"
4242
>
43-
<user-panel :menu-items="userMenuItems" menu-mode="context" />
43+
<user-panel :user="user" :menu-items="userMenuItems" menu-mode="context" />
4444
</dx-button>
4545
</div>
4646
</dx-item>
4747
<!-- eslint-disable vue/no-unused-vars -->
4848
<user-panel
49+
:user="user"
4950
:menu-items="userMenuItems"
5051
menu-mode="list"
5152
slot-scope="_"
@@ -68,10 +69,15 @@ export default {
6869
menuToggleEnabled: Boolean,
6970
title: String,
7071
toggleMenuFunc: Function,
71-
logOutFunc: Function
72+
logOutFunc: Function,
73+
},
74+
/* eslint-disable no-debugger */
75+
created() {
76+
auth.getUser().then((e) => this.user = e.data);
7277
},
7378
data() {
7479
return {
80+
user: { },
7581
userMenuItems: [
7682
{
7783
text: "Profile",

src/components/user-panel.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="image-container">
55
<div class="user-image" />
66
</div>
7-
<div class="user-name">sandra@example.com</div>
7+
<div class="user-name">{{user.email}}</div>
88
</div>
99

1010
<dx-context-menu
@@ -33,7 +33,8 @@ import DxList from "devextreme-vue/list";
3333
export default {
3434
props: {
3535
menuMode: String,
36-
menuItems: Array
36+
menuItems: Array,
37+
user: Object
3738
},
3839
components: {
3940
DxContextMenu,

src/layouts/single-card.vue

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<dx-scroll-view height="100%" width="100%" class="with-footer single-card">
3-
<div class="dx-card"><slot /></div>
3+
<div class="dx-card content">
4+
<div class="header">
5+
<div class="title">{{title}}</div>
6+
<div class="description">{{description}}</div>
7+
</div>
8+
<slot />
9+
</div>
410
</dx-scroll-view>
511
</template>
612

@@ -10,17 +16,26 @@ import DxScrollView from "devextreme-vue/scroll-view";
1016
export default {
1117
components: {
1218
DxScrollView
19+
},
20+
props: {
21+
title: String,
22+
description: String
1323
}
1424
};
1525
</script>
1626

1727
<style lang="scss">
28+
@import "../themes/generated/variables.base.scss";
29+
1830
.single-card {
31+
width: 100%;
32+
height: 100%;
1933
2034
.dx-card {
2135
width: 330px;
2236
margin: auto auto;
2337
padding: 40px;
38+
flex-grow: 0;
2439
2540
.screen-x-small & {
2641
width: 100%;
@@ -31,6 +46,22 @@ export default {
3146
border: 0;
3247
flex-grow: 1;
3348
}
49+
50+
.header {
51+
margin-bottom: 30px;
52+
53+
.title {
54+
color: $base-text-color;
55+
line-height: 28px;
56+
font-weight: 500;
57+
font-size: 24px;
58+
}
59+
60+
.description {
61+
color: rgba($base-text-color, alpha($base-text-color) * 0.7);
62+
line-height: 18px;
63+
}
64+
}
3465
}
3566
}
3667

src/router.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,59 @@ const router = new Router({
4646
meta: { requiresAuth: false },
4747
components: {
4848
layout: simpleLayout,
49-
// route level code-splitting
50-
// this generates a separate chunk (login.[hash].js) for this route
51-
// which is lazy-loaded when the route is visited.
5249
content: () =>
5350
import(/* webpackChunkName: "login" */ "./views/login-form")
51+
},
52+
props: {
53+
layout: {
54+
title: "Sign In"
55+
}
56+
}
57+
},
58+
{
59+
path: "/reset-password",
60+
name: "reset-password",
61+
meta: { requiresAuth: false },
62+
components: {
63+
layout: simpleLayout,
64+
content: () =>
65+
import(/* webpackChunkName: "login" */ "./views/reset-password-form")
66+
},
67+
props: {
68+
layout: {
69+
title: "Reset Password",
70+
description: "Please enter the email address that you used to register, and we will send you a link to reset your password via Email."
71+
}
72+
}
73+
},
74+
{
75+
path: "/create-account",
76+
name: "create-account",
77+
meta: { requiresAuth: false },
78+
components: {
79+
layout: simpleLayout,
80+
content: () =>
81+
import(/* webpackChunkName: "login" */ "./views/create-account-form")
82+
},
83+
props: {
84+
layout: {
85+
title: "Sign Up"
86+
}
87+
}
88+
},
89+
{
90+
path: "/change-password/:recoveryCode",
91+
name: "change-password",
92+
meta: { requiresAuth: false },
93+
components: {
94+
layout: simpleLayout,
95+
content: () =>
96+
import(/* webpackChunkName: "login" */ "./views/change-password-form")
97+
},
98+
props: {
99+
layout: {
100+
title: "Change Password"
101+
}
54102
}
55103
},
56104
{
@@ -70,12 +118,12 @@ const router = new Router({
70118

71119
router.beforeEach((to, from, next) => {
72120

73-
if (to.name === "login-form" && auth.authenticated()) {
121+
if (to.name === "login-form" && auth.loggedIn()) {
74122
next({ name: "home" });
75123
}
76124

77125
if (to.matched.some(record => record.meta.requiresAuth)) {
78-
if (!auth.authenticated()) {
126+
if (!auth.loggedIn()) {
79127
next({
80128
name: "login-form",
81129
query: { redirect: to.fullPath }

0 commit comments

Comments
 (0)