This repository was archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthView.vue
More file actions
105 lines (102 loc) · 3.2 KB
/
AuthView.vue
File metadata and controls
105 lines (102 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
<div
class="container"
@submit.prevent="auth"
>
<h1>Вход в приложение</h1>
<p>
Добро пожаловать! Тут находится наша нулевая итерация по прикручиванию авторизации в приложение. Ниже вы
можете войти в систему.
</p>
<form action="">
<div class="mb-3 row">
<label
for="staticEmail"
class="col-sm-2 col-form-label"
>
Email
</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="staticEmail"
placeholder="email@example.com"
v-model="email"
/>
</div>
</div>
<div class="mb-3 row">
<label
for="inputPassword"
class="col-sm-2 col-form-label"
>
Password
</label>
<div class="col-sm-10">
<input
type="password"
class="form-control"
id="inputPassword"
v-model="password"
/>
</div>
</div>
<div class="row p-4">
<button
type="submit"
class="btn btn-success my-2"
>
Войти
</button>
<RouterLink
to="/devtools"
class="btn btn-secondary my-2"
>
Вернуться назад
</RouterLink>
</div>
</form>
</div>
</template>
<script>
export default {
data: () => ({
email: '',
password: '',
}),
mounted() {
let changeHeaderLayoutEvent = new CustomEvent('change-header-layout', {
detail: {
layoutName: 'back',
text: 'О пользователе',
},
});
document.dispatchEvent(changeHeaderLayoutEvent);
},
methods: {
auth() {
if (this.email === '' || this.password === '') {
alert('Пустой логин или пароль');
return;
}
fetch(`${process.env.VUE_APP_API_AUTH}/email/login`, {
method: 'POST',
cache: 'no-cache',
redirect: 'follow',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: this.email,
password: this.password,
}),
})
.then(response => response.json())
.then(json => {
localStorage.setItem('auth-token', json.token);
alert(JSON.stringify(json));
});
},
},
};
</script>
<style></style>