parent
4f7b1fc4d2
commit
3dc1fa3567
3 changed files with 68 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div class="d-flex justify-center login-root">
|
||||
<div color="rgba(255,255,255,0.1)">
|
||||
<div v-if="!waiting">
|
||||
<h4>Join room</h4>
|
||||
<div>You have been invited to the room {{ roomId }}</div>
|
||||
|
||||
|
|
@ -24,10 +24,31 @@ export default {
|
|||
guestUser: new User("https://neo.keanu.im", "", "", true),
|
||||
loading: false,
|
||||
loadingMessage: null,
|
||||
waiting: false
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.roomId = this.$route.hash;
|
||||
if (this.currentUser) {
|
||||
this.waiting = true;
|
||||
const self = this;
|
||||
this.$matrix.getMatrixClient(this.currentUser)
|
||||
.then(() => {
|
||||
// Already joined?
|
||||
const room = self.$matrix.getRoom(self.roomId);
|
||||
if (room && room.hasMembershipState(self.currentUser.user_id, "join")) {
|
||||
// Yes, go to room
|
||||
self.$matrix.setCurrentRoom(room);
|
||||
self.$router.replace({ name: "Chat" });
|
||||
return;
|
||||
}
|
||||
|
||||
this.waiting = false;
|
||||
})
|
||||
.catch(ignoredErr => {
|
||||
this.waiting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
currentUser() {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ class Util {
|
|||
|
||||
if (url == null) {
|
||||
reject("No url found!");
|
||||
return;
|
||||
}
|
||||
axios.get(url, { responseType: 'arraybuffer' })
|
||||
.then(response => {
|
||||
|
|
@ -288,6 +289,16 @@ class Util {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random 12 char password
|
||||
*/
|
||||
randomPass() {
|
||||
return this.randomString(
|
||||
12,
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#_-*+"
|
||||
);
|
||||
}
|
||||
|
||||
// From here: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
|
||||
randomString(length, characters) {
|
||||
var result = "";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
global.Olm = require("olm");
|
||||
import sdk from "matrix-js-sdk";
|
||||
//import util from "../plugins/utils";
|
||||
import util from "../plugins/utils";
|
||||
|
||||
const LocalStorageCryptoStore = require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store")
|
||||
.LocalStorageCryptoStore;
|
||||
|
|
@ -60,7 +60,6 @@ export default {
|
|||
var promiseLogin;
|
||||
|
||||
if (user.is_guest) {
|
||||
//const randomUsername = util.randomUser();
|
||||
promiseLogin = tempMatrixClient
|
||||
.registerGuest({}, undefined)
|
||||
.then((response) => {
|
||||
|
|
@ -95,6 +94,29 @@ export default {
|
|||
this.$store.commit("setCurrentRoomId", null);
|
||||
},
|
||||
|
||||
/**
|
||||
* Upgrade a guest account into a "normal" account. For now, use random user and pass...
|
||||
*/
|
||||
upgradeGuestAccount() {
|
||||
if (!this.matrixClient || !this.currentUser || !this.currentUser.is_guest) {
|
||||
return Promise.reject("Invalid params");
|
||||
}
|
||||
const randomUsername = util.randomUser();
|
||||
const randomPassword = util.randomPass();
|
||||
const data = {
|
||||
username:randomUsername,
|
||||
password:randomPassword,
|
||||
guest_access_token:this.currentUser.access_token
|
||||
};
|
||||
return this.matrixClient.registerRequest(data, undefined, undefined)
|
||||
.then((response) => {
|
||||
console.log("Response", response);
|
||||
response.is_guest = false;
|
||||
localStorage.setItem('user', JSON.stringify(response));
|
||||
return response;
|
||||
});
|
||||
},
|
||||
|
||||
initClient() {
|
||||
this.reloadRooms();
|
||||
this.matrixClientReady = true;
|
||||
|
|
@ -102,12 +124,15 @@ export default {
|
|||
},
|
||||
|
||||
async getMatrixClient(user) {
|
||||
if (user === undefined) {
|
||||
user = this.$store.state.auth.user;
|
||||
}
|
||||
if (this.matrixClientReady) {
|
||||
return new Promise((resolve,ignoredreject) => {
|
||||
return new Promise((resolve, ignoredreject) => {
|
||||
resolve(user);
|
||||
})
|
||||
} else if (this.matrixClient) {
|
||||
return new Promise((resolve,ignoredreject) => {
|
||||
return new Promise((resolve, ignoredreject) => {
|
||||
this.matrixClient.once('Matrix.initialized', (ignoredclient) => {
|
||||
resolve(user);
|
||||
});
|
||||
|
|
@ -234,7 +259,12 @@ export default {
|
|||
},
|
||||
|
||||
getRoom(roomId) {
|
||||
var room = this.rooms.find(room => room.roomId == roomId);
|
||||
var room = this.rooms.find(room => {
|
||||
if (roomId.startsWith("#")) {
|
||||
return room.getCanonicalAlias() == roomId;
|
||||
}
|
||||
return room.roomId == roomId;
|
||||
});
|
||||
if (!room && this.matrixClient) {
|
||||
room = this.matrixClient.getRoom(roomId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue