-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathconnect.vue
More file actions
163 lines (139 loc) · 3.81 KB
/
Copy pathconnect.vue
File metadata and controls
163 lines (139 loc) · 3.81 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
<div class="connect">
<div class="window">
<div class="loader" v-if="connecting">
<img src="../assets/images/logo.svg" alt="loading" aria-hidden="true" class="kernel-logo" />
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
.connect {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba($color: $background-floating, $alpha: 0.8);
display: flex;
justify-content: center;
align-items: center;
.window {
.logo {
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
cursor: pointer;
img {
height: 90px;
margin-right: 10px;
}
span {
font-size: 30px;
line-height: 56px;
b {
font-weight: 900;
}
}
}
.loader {
width: 90px;
height: 90px;
position: relative;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
.kernel-logo {
width: 100%;
height: 100%;
animation: kernel-logo-pulse 1.5s ease-in-out infinite;
}
}
}
}
@keyframes kernel-logo-pulse {
0%,
100% {
transform: scale(0.85);
opacity: 0.7;
}
50% {
transform: scale(1);
opacity: 1;
}
}
</style>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component({ name: 'neko-connect' })
export default class extends Vue {
private autoPassword: string | null = new URL(location.href).searchParams.get('pwd')
private displayname: string = ''
private password: string = ''
mounted() {
// auto-password fill
let password = this.$accessor.password
if (this.autoPassword !== null) {
this.removeUrlParam('pwd')
password = this.autoPassword
}
// auto-user fill
let displayname = this.$accessor.displayname
const usr = new URL(location.href).searchParams.get('usr')
if (usr) {
this.removeUrlParam('usr')
displayname = this.$accessor.displayname || usr
}
// KERNEL: auto-login, but respect caller-supplied credentials first.
// This keeps the legacy fallback for existing deployments while allowing
// embeds and links that provide explicit credentials to work as intended.
this.$accessor.login({
displayname: displayname || 'kernel',
password: password || 'admin',
})
this.autoPassword = null
}
get connecting() {
return this.$accessor.connecting
}
removeUrlParam(param: string) {
let url = document.location.href
let urlparts = url.split('?')
if (urlparts.length >= 2) {
let urlBase = urlparts.shift()
let queryString = urlparts.join('?')
let prefix = encodeURIComponent(param) + '='
let pars = queryString.split(/[&;]/g)
for (let i = pars.length; i-- > 0; ) {
if (pars[i].lastIndexOf(prefix, 0) !== -1) {
pars.splice(i, 1)
}
}
url = urlBase + (pars.length > 0 ? '?' + pars.join('&') : '')
window.history.pushState('', document.title, url)
}
}
login() {
let password = this.password
if (this.autoPassword !== null) {
password = this.autoPassword
}
if (this.displayname == '') {
this.$swal({
title: this.$t('connect.error') as string,
text: this.$t('connect.empty_displayname') as string,
icon: 'error',
})
return
}
this.$accessor.login({ displayname: this.displayname, password })
this.autoPassword = null
}
about() {
this.$accessor.client.toggleAbout()
}
}
</script>