-
-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathLogin.vue
More file actions
159 lines (151 loc) · 5.31 KB
/
Login.vue
File metadata and controls
159 lines (151 loc) · 5.31 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
<template>
<v-dialog :value="true" persistent max-width="300px">
<v-form @submit.prevent="doLogin">
<v-card>
<v-card-text>
<v-card-title style="justify-content: center;" class="headline text-uppercase">Scrypted
</v-card-title>
<v-card-subtitle v-if="$store.state.hasLogin === false" style="display: flex; justify-content: center;" class="text-uppercase">Create Account
</v-card-subtitle>
<v-card-subtitle v-if="$store.state.loginHostname"
style="text-align: center; font-weight: 300; font-size: .75rem !important; font-family: Quicksand, sans-serif!important;"
class="text-subtitle-2 text-uppercase">Log into: {{ $store.state.loginHostname }}</v-card-subtitle>
<v-container grid-list-md>
<v-layout wrap>
<v-flex xs12>
<v-text-field dense outlined v-model="username" label="User Name"></v-text-field>
<v-text-field dense outlined v-model="password" type="password" label="Password">
</v-text-field>
<v-checkbox dense v-if="$store.state.hasLogin === true" v-model="changePassword"
label="Change Password"></v-checkbox>
<v-text-field dense outlined v-model="newPassword" v-if="changePassword" type="password"
label="New Password"></v-text-field>
<v-text-field dense outlined v-model="confirmPassword"
v-if="changePassword || $store.state.hasLogin === false" type="password" label="Confirm Password"
:rules="[
(
changePassword
? confirmPassword !== newPassword
: confirmPassword !== password
)
? 'Passwords do not match.'
: true,
]"></v-text-field>
</v-flex>
</v-layout>
<div v-if="loginResult">{{ loginResult }}</div>
</v-container>
</v-card-text>
<v-card-actions>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon href="https://discord.gg/DcFzmBHYGq">
<v-icon small>fab fa-discord</v-icon>
</v-btn>
</template>
<span>Discord</span>
</v-tooltip>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon href="https://www.reddit.com/r/Scrypted/">
<v-icon small>fab fa-reddit</v-icon>
</v-btn>
</template>
<span>Reddit</span>
</v-tooltip>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon href="https://github.com/koush/scrypted">
<v-icon small>fab fa-github</v-icon>
</v-btn>
</template>
<span>Github</span>
</v-tooltip>
<v-spacer></v-spacer>
<v-btn type="submit" text @click.prevent="doLogin">Log In</v-btn>
</v-card-actions>
</v-card>
</v-form>
</v-dialog>
</template>
<script>
import store from "./store";
import "./client";
import { loginScrypted } from './client';
export default {
name: "Login",
methods: {
async doLogin() {
const body = {
username: this.username,
password: this.password,
};
if (this.changePassword || this.$store.state.hasLogin === false) {
if (
this.$store.state.hasLogin === false &&
this.password !== this.confirmPassword
) {
this.loginResult = "Passwords do not match.";
return;
} else if (
this.changePassword &&
this.newPassword !== this.confirmPassword
) {
this.loginResult = "Passwords do not match.";
return;
}
body.change_password = this.confirmPassword;
}
this.loginResult = "";
try {
const response = await loginScrypted(this.username, this.password, this.confirmPassword || undefined);
if (response.error) {
this.loginResult = response.error;
return;
}
try {
const redirect_uri = new URL(window.location).searchParams.get('redirect_uri');
if (redirect_uri) {
window.location = redirect_uri;
return;
}
}
catch (e) {
}
window.location.reload();
}
catch (e) {
this.loginResult = e.toString();
// cert may need to be reaccepted? Server is down? Go to the
// server root to force the network error to bypass the PWA cache.
if (
e.toString().includes("Network Error") &&
window.location.href.startsWith("https:")
) {
window.location = "/";
}
}
},
},
store,
data() {
const self = this;
return {
changePassword: false,
username: null,
password: null,
confirmPassword: null,
newPassword: null,
loginResult: undefined,
passwordRules: [
() => {
if (self.password != self.confirmPassword && self.changePassword) {
return "Passwords do not match.";
}
return true;
},
],
};
},
};
</script>