Added fetch api for login
This commit is contained in:
parent
509f940afd
commit
632ca94975
File diff suppressed because one or more lines are too long
53
src/app.js
53
src/app.js
@ -19,6 +19,7 @@ import router from '@/router'
|
||||
import store from '@/store'
|
||||
|
||||
import { socket } from '@/utils/socket'
|
||||
import { get } from '@/utils/api'
|
||||
import { toast } from '@/utils/toasts'
|
||||
import { isValidURL } from '@/utils/utils'
|
||||
import { sendAddToQueue } from '@/utils/downloads'
|
||||
@ -86,26 +87,7 @@ socket.on('message', function(msg) {
|
||||
console.log(msg)
|
||||
})
|
||||
|
||||
socket.on('logging_in', function() {
|
||||
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
|
||||
})
|
||||
|
||||
socket.on('init_autologin', function() {
|
||||
let arl = localStorage.getItem('arl')
|
||||
let accountNum = localStorage.getItem('accountNum')
|
||||
|
||||
if (arl) {
|
||||
arl = arl.trim()
|
||||
|
||||
if (accountNum != 0) {
|
||||
socket.emit('login', arl, true, accountNum)
|
||||
} else {
|
||||
socket.emit('login', arl)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
socket.on('logged_in', function(data) {
|
||||
function loggedIn(data){
|
||||
const { status, user } = data
|
||||
|
||||
switch (status) {
|
||||
@ -138,6 +120,36 @@ socket.on('logged_in', function(data) {
|
||||
// $('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
||||
// document.getElementById('home_not_logged_in').classList.remove('hide')
|
||||
}
|
||||
}
|
||||
|
||||
fetch('connect').then(response => response.json()).then(data => {
|
||||
store.dispatch('setAppInfo', data.update )
|
||||
if (data.autologin) {
|
||||
console.log("Autologin")
|
||||
let arl = localStorage.getItem('arl')
|
||||
let accountNum = localStorage.getItem('accountNum')
|
||||
|
||||
if (arl) {
|
||||
arl = arl.trim()
|
||||
let result
|
||||
|
||||
if (accountNum != 0) {
|
||||
result = get('login', {arl: arl, force:true, child:accountNum || 0})
|
||||
} else {
|
||||
result = get('login', {arl})
|
||||
}
|
||||
result.then(loggedIn)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
socket.on('logging_in', function() {
|
||||
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
|
||||
})
|
||||
|
||||
socket.on('logged_in', function(data) {
|
||||
|
||||
})
|
||||
|
||||
socket.on('logged_out', function() {
|
||||
@ -145,6 +157,7 @@ socket.on('logged_out', function() {
|
||||
|
||||
store.dispatch('logout')
|
||||
})
|
||||
*/
|
||||
|
||||
socket.on('restoringQueue', function() {
|
||||
toast(i18n.t('toasts.restoringQueue'), 'loading', false, 'restoring_queue')
|
||||
|
@ -92,7 +92,6 @@ import { orderBy } from 'lodash-es'
|
||||
|
||||
import { BaseTabs, BaseTab } from '@components/globals/BaseTabs'
|
||||
|
||||
import { socket } from '@/utils/socket'
|
||||
import { sendAddToQueue } from '@/utils/downloads'
|
||||
import { checkNewRelease } from '@/utils/dates'
|
||||
import { formatArtistData, getArtistData } from '@/data/artist'
|
||||
|
@ -3,7 +3,7 @@ import VueRouter from 'vue-router'
|
||||
import { socket } from '@/utils/socket'
|
||||
|
||||
// Pages
|
||||
import About from '@components/pages/About.vue'
|
||||
//import About from '@components/pages/About.vue'
|
||||
import InfoArl from '@components/pages/InfoArl.vue'
|
||||
import InfoSpotifyFeatures from '@components/pages/InfoSpotifyFeatures.vue'
|
||||
import Artist from '@components/pages/Artist.vue'
|
||||
@ -81,11 +81,11 @@ const routes = [
|
||||
name: 'Link Analyzer',
|
||||
component: LinkAnalyzer
|
||||
},
|
||||
{
|
||||
/*{
|
||||
path: '/about',
|
||||
name: 'About',
|
||||
component: About
|
||||
},
|
||||
},*/
|
||||
{
|
||||
path: '/info-arl',
|
||||
name: 'ARL',
|
||||
@ -165,4 +165,3 @@ router.beforeEach((to, from, next) => {
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
|
10
src/utils/api.js
Normal file
10
src/utils/api.js
Normal file
@ -0,0 +1,10 @@
|
||||
export const get = function(key, data){
|
||||
let url = `/api/${key}`
|
||||
if (data){
|
||||
let query = Object.keys(data)
|
||||
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
|
||||
.join('&')
|
||||
url += '?'+query
|
||||
}
|
||||
return fetch(url).then(response => response.json())
|
||||
}
|
@ -3,19 +3,15 @@ import store from '@/store'
|
||||
class CustomSocket extends WebSocket {
|
||||
constructor(args) {
|
||||
super(args)
|
||||
console.log(args)
|
||||
}
|
||||
|
||||
emit(key, data) {
|
||||
console.log("emit:", key, data)
|
||||
console.log(this.readyState)
|
||||
if (this.readyState != WebSocket.OPEN) return false
|
||||
this.send(JSON.stringify({key:key, data:data}))
|
||||
}
|
||||
|
||||
on(key, callback) {
|
||||
this.addEventListener('message', function(event){
|
||||
console.log(event.data)
|
||||
let data = JSON.parse(event.data)
|
||||
if (data.key == key) callback(data.data)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user