Merge branch 'dev'
This commit is contained in:
commit
e48c516211
@ -8,8 +8,6 @@
|
|||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modular-matrix/parse-mxc": "^1.0.1",
|
|
||||||
"@vue-polkadot/vue-identicon": "^0.0.8",
|
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"jdenticon": "^3.1.0",
|
"jdenticon": "^3.1.0",
|
||||||
"matrix-js-sdk": "^9.1.0",
|
"matrix-js-sdk": "^9.1.0",
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<fileUpload class="leftBtn" :on-change="setAttachment"/>
|
<fileUpload class="leftBtn" :on-change="setAttachment"/>
|
||||||
</div>
|
</div>
|
||||||
<v-emoji-picker
|
<v-emoji-picker
|
||||||
v-if="showEmojiPicker"
|
v-show="showEmojiPicker"
|
||||||
class="emojiPicker"
|
class="emojiPicker"
|
||||||
@select="onSelectEmoji"
|
@select="onSelectEmoji"
|
||||||
:dark="true"
|
:dark="true"
|
||||||
@ -79,7 +79,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async sendEvent(event){
|
async sendEvent(event){
|
||||||
if (!event.content.body.trim()) return;
|
if (!event.content.body.trim()) return;
|
||||||
if (this.replyTo) this.setReplyTo(this.replyTo);
|
this.setReplyTo(this.replyTo);
|
||||||
matrix.sendEvent(new Proxy(this.event, this.eventProxyHandler), this.roomId);
|
matrix.sendEvent(new Proxy(this.event, this.eventProxyHandler), this.roomId);
|
||||||
event.content.body = '';
|
event.content.body = '';
|
||||||
this.resetAttachment();
|
this.resetAttachment();
|
||||||
@ -139,7 +139,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
resetAttachment(){
|
resetAttachment(){
|
||||||
if (!this.attachment) return;
|
if (!this.attachment) return this.attachment = undefined;
|
||||||
window.URL.revokeObjectURL(this.attachment.file);
|
window.URL.revokeObjectURL(this.attachment.file);
|
||||||
this.event.content = {
|
this.event.content = {
|
||||||
body: this.attachment?this.event.content.body.replace(this.attachment.filename, ''):'',
|
body: this.attachment?this.event.content.body.replace(this.attachment.filename, ''):'',
|
||||||
|
22
src/lib/DataStore.js
Normal file
22
src/lib/DataStore.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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]));
|
||||||
|
}
|
||||||
|
}
|
@ -48,7 +48,8 @@ export class MatrixHandler {
|
|||||||
baseUrl,
|
baseUrl,
|
||||||
accessToken,
|
accessToken,
|
||||||
userId,
|
userId,
|
||||||
store: new matrix.MemoryStore(window.localStorage)
|
store: new matrix.MemoryStore(window.localStorage),
|
||||||
|
sessionStore: new matrix.WebStorageSessionStore(window.localStorage)
|
||||||
});
|
});
|
||||||
this.user = userId;
|
this.user = userId;
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
@ -8,11 +8,17 @@ export class cookieHandler {
|
|||||||
getCookies(){
|
getCookies(){
|
||||||
return this.cookies;
|
return this.cookies;
|
||||||
}
|
}
|
||||||
setCookie(cookies){
|
setCookies(cookies){
|
||||||
Object.keys(cookies).forEach(key => {
|
Object.keys(cookies).forEach(key => {
|
||||||
this.cookies[key] = cookies[key];
|
this.cookies[key] = cookies[key];
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
set(key, value){
|
||||||
|
this.cookies[key] = value;
|
||||||
|
}
|
||||||
|
get(key){
|
||||||
|
return this.cookies[key];
|
||||||
|
}
|
||||||
parseCookie(string){
|
parseCookie(string){
|
||||||
let cookies = {};
|
let cookies = {};
|
||||||
string.replace(/ /g, '').split(';').forEach(cookie => {
|
string.replace(/ /g, '').split(';').forEach(cookie => {
|
||||||
@ -24,14 +30,12 @@ export class cookieHandler {
|
|||||||
reload(){
|
reload(){
|
||||||
if (document.cookie) this.cookies = this.parseCookie(document.cookie);
|
if (document.cookie) this.cookies = this.parseCookie(document.cookie);
|
||||||
console.log('cookie loaded')
|
console.log('cookie loaded')
|
||||||
console.log(this.cookies);
|
|
||||||
}
|
}
|
||||||
store(){
|
store(){
|
||||||
Object.keys(this.cookies).forEach(key => {
|
Object.keys(this.cookies).forEach(key => {
|
||||||
document.cookie = `${key}=${this.cookies[key]}; expires=${this.expires}; SameSite=${this.SameSite}; Secure;`;
|
document.cookie = `${key}=${this.cookies[key]}; expires=${this.expires}; SameSite=${this.SameSite}; Secure;`;
|
||||||
});
|
});
|
||||||
console.log('cookie stored');
|
console.log('cookie stored');
|
||||||
console.log(this.cookies);
|
|
||||||
}
|
}
|
||||||
toString(cookies = this.cookies){
|
toString(cookies = this.cookies){
|
||||||
let string = '';
|
let string = '';
|
||||||
|
11
src/main.js
11
src/main.js
@ -2,17 +2,18 @@ import Vue from 'vue'
|
|||||||
import VueRouter from 'vue-router'
|
import VueRouter from 'vue-router'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import {router} from '@/router'
|
import {router} from '@/router'
|
||||||
import {MatrixHandler} from './lib/matrixHandler.js'
|
import {MatrixHandler} from './lib/MatrixHandler.js'
|
||||||
import {cookieHandler} from './lib/cookieHandler.js';
|
import {DataStore} from '@/lib/DataStore';
|
||||||
|
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
export let matrix = new MatrixHandler();
|
export let matrix = new MatrixHandler();
|
||||||
|
|
||||||
let cookie = new cookieHandler().getCookies();
|
let store = new DataStore();
|
||||||
if (cookie && cookie.baseUrl && cookie.accessToken && cookie.userId) {
|
|
||||||
matrix.tokenLogin(cookie.baseUrl, cookie.accessToken, cookie.userId);
|
if (store.get('baseUrl') && store.get('accessToken') && store.get('userId')) {
|
||||||
|
matrix.tokenLogin(store.get('baseUrl'), store.get('accessToken'), store.get('userId'));
|
||||||
}
|
}
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
|
@ -22,9 +22,9 @@
|
|||||||
<script>
|
<script>
|
||||||
import textbtn from '@/components/textbtn';
|
import textbtn from '@/components/textbtn';
|
||||||
import {matrix} from '@/main.js';
|
import {matrix} from '@/main.js';
|
||||||
import {cookieHandler} from '@/lib/cookieHandler';
|
|
||||||
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';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'login.vue',
|
name: 'login.vue',
|
||||||
@ -52,14 +52,11 @@ export default {
|
|||||||
this.loginError = `login failed: ${error}`;
|
this.loginError = `login failed: ${error}`;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}, token => {
|
}, token => {
|
||||||
this.loading = 'store token';
|
this.store.setObj({
|
||||||
this.cookie.setCookie({
|
|
||||||
baseUrl: this.homeServer,
|
baseUrl: this.homeServer,
|
||||||
userId: this.user,
|
userId: this.user,
|
||||||
accessToken: token
|
accessToken: token
|
||||||
});
|
});
|
||||||
this.cookie.setExpire(15);
|
|
||||||
this.cookie.store();
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.$router.push('/rooms/');
|
this.$router.push('/rooms/');
|
||||||
});
|
});
|
||||||
@ -67,14 +64,11 @@ export default {
|
|||||||
async logout(){
|
async logout(){
|
||||||
this.loading = 'logging out';
|
this.loading = 'logging out';
|
||||||
await matrix.logout();
|
await matrix.logout();
|
||||||
this.loading = 'remove token';
|
this.store.setObj({
|
||||||
this.cookie.setCookie({
|
|
||||||
baseUrl: undefined,
|
baseUrl: undefined,
|
||||||
userId: undefined,
|
userId: undefined,
|
||||||
accessToken: undefined
|
accessToken: undefined
|
||||||
});
|
});
|
||||||
this.cookie.setExpire(0);
|
|
||||||
this.cookie.store();
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
@ -88,7 +82,7 @@ export default {
|
|||||||
password: '',
|
password: '',
|
||||||
homeServer: 'https://adb.sh',
|
homeServer: 'https://adb.sh',
|
||||||
loginError: '',
|
loginError: '',
|
||||||
cookie: new cookieHandler(),
|
store: new DataStore(),
|
||||||
loading: false
|
loading: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user