|
|
@ -25,6 +25,7 @@ import {matrix} from '@/main.js';
|
|
|
|
import ThrobberOverlay from '@/components/throbberOverlay';
|
|
|
|
import ThrobberOverlay from '@/components/throbberOverlay';
|
|
|
|
import {isValidUserId} from '@/lib/matrixUtils';
|
|
|
|
import {isValidUserId} from '@/lib/matrixUtils';
|
|
|
|
import {DataStore} from '@/lib/DataStore';
|
|
|
|
import {DataStore} from '@/lib/DataStore';
|
|
|
|
|
|
|
|
const store = new DataStore();
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
name: 'login.vue',
|
|
|
|
name: 'login.vue',
|
|
|
@ -34,25 +35,14 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
login(){
|
|
|
|
login(){
|
|
|
|
if (matrix.client !== undefined) {
|
|
|
|
// eslint-disable-next-line no-cond-assign
|
|
|
|
this.loginError = 'you are already logged in';
|
|
|
|
if (this.loginError = this.getInputErrors()) return false;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} if (this.user === '') {
|
|
|
|
|
|
|
|
this.loginError = 'username is empty';
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} if (this.password === '') {
|
|
|
|
|
|
|
|
this.loginError = 'password is empty';
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} if (!isValidUserId(this.user)) {
|
|
|
|
|
|
|
|
this.loginError = 'username is in wrong style';
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = 'logging in';
|
|
|
|
this.loading = 'logging in';
|
|
|
|
matrix.login(this.user, this.password, this.homeServer, (error) => {
|
|
|
|
matrix.login(this.user, this.password, this.homeServer, (error) => {
|
|
|
|
this.loginError = `login failed: ${error}`;
|
|
|
|
this.loginError = `login failed: ${error}`;
|
|
|
|
this.loading = false;
|
|
|
|
this.loading = false;
|
|
|
|
}, token => {
|
|
|
|
}, token => {
|
|
|
|
this.store.setObj({
|
|
|
|
this.store.set('login', {
|
|
|
|
baseUrl: this.homeServer,
|
|
|
|
baseUrl: this.homeServer,
|
|
|
|
userId: this.user,
|
|
|
|
userId: this.user,
|
|
|
|
accessToken: token
|
|
|
|
accessToken: token
|
|
|
@ -64,14 +54,17 @@ export default {
|
|
|
|
async logout(){
|
|
|
|
async logout(){
|
|
|
|
this.loading = 'logging out';
|
|
|
|
this.loading = 'logging out';
|
|
|
|
await matrix.logout();
|
|
|
|
await matrix.logout();
|
|
|
|
this.store.setObj({
|
|
|
|
this.store.set('login', {});
|
|
|
|
baseUrl: undefined,
|
|
|
|
|
|
|
|
userId: undefined,
|
|
|
|
|
|
|
|
accessToken: undefined
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
this.loading = false;
|
|
|
|
this.$forceUpdate();
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
getInputErrors(){
|
|
|
|
|
|
|
|
if (matrix.client !== undefined) return 'you are already logged in';
|
|
|
|
|
|
|
|
if (this.user === '') return 'username is empty';
|
|
|
|
|
|
|
|
if (this.password === '') return 'password is empty';
|
|
|
|
|
|
|
|
if (!isValidUserId(this.user)) return 'username is in wrong style';
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
showLogin(){
|
|
|
|
showLogin(){
|
|
|
|
return matrix.client === undefined;
|
|
|
|
return matrix.client === undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,7 +75,7 @@ export default {
|
|
|
|
password: '',
|
|
|
|
password: '',
|
|
|
|
homeServer: 'https://adb.sh',
|
|
|
|
homeServer: 'https://adb.sh',
|
|
|
|
loginError: '',
|
|
|
|
loginError: '',
|
|
|
|
store: new DataStore(),
|
|
|
|
store,
|
|
|
|
loading: false
|
|
|
|
loading: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|