Compare commits

..

No commits in common. "e48c5162117b2ad193a63526189e64e4391b464b" and "292b123f5a1226c6039fb8204d91c3acf559b05e" have entirely different histories.

7 changed files with 24 additions and 44 deletions

View File

@ -8,6 +8,8 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@modular-matrix/parse-mxc": "^1.0.1",
"@vue-polkadot/vue-identicon": "^0.0.8",
"core-js": "^3.6.5",
"jdenticon": "^3.1.0",
"matrix-js-sdk": "^9.1.0",

View File

@ -36,7 +36,7 @@
<fileUpload class="leftBtn" :on-change="setAttachment"/>
</div>
<v-emoji-picker
v-show="showEmojiPicker"
v-if="showEmojiPicker"
class="emojiPicker"
@select="onSelectEmoji"
:dark="true"
@ -79,7 +79,7 @@ export default {
},
async sendEvent(event){
if (!event.content.body.trim()) return;
this.setReplyTo(this.replyTo);
if (this.replyTo) this.setReplyTo(this.replyTo);
matrix.sendEvent(new Proxy(this.event, this.eventProxyHandler), this.roomId);
event.content.body = '';
this.resetAttachment();
@ -139,7 +139,7 @@ export default {
};
},
resetAttachment(){
if (!this.attachment) return this.attachment = undefined;
if (!this.attachment) return;
window.URL.revokeObjectURL(this.attachment.file);
this.event.content = {
body: this.attachment?this.event.content.body.replace(this.attachment.filename, ''):'',

View File

@ -1,22 +0,0 @@
import {cookieHandler} from '@/lib/cookieHandler';
export class DataStore{
constructor(){
this.cookie = new cookieHandler();
this.cookie.setExpire(15);
this.store = localStorage;
}
set(key, value){
this.cookie.set(key, value);
this.cookie.store();
this.store.setItem(key, value);
}
get(key){
return this.store.getItem(key) || this.cookie.get(key);
}
setObj(obj){
this.cookie.setCookies(obj);
this.cookie.store();
Object.keys(obj).forEach(key => this.store.setItem(key, obj[key]));
}
}

View File

@ -8,17 +8,11 @@ export class cookieHandler {
getCookies(){
return this.cookies;
}
setCookies(cookies){
setCookie(cookies){
Object.keys(cookies).forEach(key => {
this.cookies[key] = cookies[key];
})
}
set(key, value){
this.cookies[key] = value;
}
get(key){
return this.cookies[key];
}
parseCookie(string){
let cookies = {};
string.replace(/ /g, '').split(';').forEach(cookie => {
@ -30,12 +24,14 @@ export class cookieHandler {
reload(){
if (document.cookie) this.cookies = this.parseCookie(document.cookie);
console.log('cookie loaded')
console.log(this.cookies);
}
store(){
Object.keys(this.cookies).forEach(key => {
document.cookie = `${key}=${this.cookies[key]}; expires=${this.expires}; SameSite=${this.SameSite}; Secure;`;
});
console.log('cookie stored');
console.log(this.cookies);
}
toString(cookies = this.cookies){
let string = '';

View File

@ -48,8 +48,7 @@ export class MatrixHandler {
baseUrl,
accessToken,
userId,
store: new matrix.MemoryStore(window.localStorage),
sessionStore: new matrix.WebStorageSessionStore(window.localStorage)
store: new matrix.MemoryStore(window.localStorage)
});
this.user = userId;
this.baseUrl = baseUrl;

View File

@ -2,18 +2,17 @@ import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import {router} from '@/router'
import {MatrixHandler} from './lib/MatrixHandler.js'
import {DataStore} from '@/lib/DataStore';
import {MatrixHandler} from './lib/matrixHandler.js'
import {cookieHandler} from './lib/cookieHandler.js';
Vue.config.productionTip = false;
Vue.use(VueRouter);
export let matrix = new MatrixHandler();
let store = new DataStore();
if (store.get('baseUrl') && store.get('accessToken') && store.get('userId')) {
matrix.tokenLogin(store.get('baseUrl'), store.get('accessToken'), store.get('userId'));
let cookie = new cookieHandler().getCookies();
if (cookie && cookie.baseUrl && cookie.accessToken && cookie.userId) {
matrix.tokenLogin(cookie.baseUrl, cookie.accessToken, cookie.userId);
}
new Vue({

View File

@ -22,9 +22,9 @@
<script>
import textbtn from '@/components/textbtn';
import {matrix} from '@/main.js';
import {cookieHandler} from '@/lib/cookieHandler';
import ThrobberOverlay from '@/components/throbberOverlay';
import {isValidUserId} from '@/lib/matrixUtils';
import {DataStore} from '@/lib/DataStore';
export default {
name: 'login.vue',
@ -52,11 +52,14 @@ export default {
this.loginError = `login failed: ${error}`;
this.loading = false;
}, token => {
this.store.setObj({
this.loading = 'store token';
this.cookie.setCookie({
baseUrl: this.homeServer,
userId: this.user,
accessToken: token
});
this.cookie.setExpire(15);
this.cookie.store();
this.loading = false;
this.$router.push('/rooms/');
});
@ -64,11 +67,14 @@ export default {
async logout(){
this.loading = 'logging out';
await matrix.logout();
this.store.setObj({
this.loading = 'remove token';
this.cookie.setCookie({
baseUrl: undefined,
userId: undefined,
accessToken: undefined
});
this.cookie.setExpire(0);
this.cookie.store();
this.loading = false;
this.$forceUpdate();
},
@ -82,7 +88,7 @@ export default {
password: '',
homeServer: 'https://adb.sh',
loginError: '',
store: new DataStore(),
cookie: new cookieHandler(),
loading: false
}
}