Skip to content

Commit

Permalink
feat: vk login
Browse files Browse the repository at this point in the history
  • Loading branch information
Viiprogrammer committed May 29, 2024
1 parent eb0f9b1 commit deadf7a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from 'electron'
import {app, BrowserWindow, ipcMain} from 'electron'
import proxy from 'node-global-proxy';
let proxyServer

Expand Down Expand Up @@ -52,6 +52,7 @@ import { broadcastTorrentEvents } from '@main/handlers/torrents/torrentsHandler'
import Tray from './utils/tray'
import Menu from './utils/menu'
import { openWindowInterceptor } from '@main/utils/windows/openWindowInterceptor'
import {showAppError} from "@main/handlers/notifications/notificationsHandler";

const { discordActivity } = require('./utils/discord')
const {
Expand Down Expand Up @@ -94,6 +95,33 @@ app.on('window-all-closed', () => {
})

app.on('web-contents-created', (event, webContents) => {
webContents.on('did-finish-load', async () => {
if (webContents.getURL().startsWith('https://id.vk.com/')) {
webContents.on('will-redirect', async (event, url) => {
if (!url.startsWith('https://www.anilibria.tv/')) {
return true
}

const cookies = await webContents.session.cookies.get({ url: 'https://www.anilibria.tv' })

const { value: sessionId } = cookies.find(cookie => cookie.name === 'PHPSESSID') || {}

if (sessionId) {
Main.getWindow().webContents.send('VK_CODE', sessionId)
}

BrowserWindow.fromWebContents(webContents).hide()

webContents.on('did-finish-load', async () => {
await webContents.session.clearStorageData()
webContents.destroy()
})

return true
});
}
})

webContents.setWindowOpenHandler(openWindowInterceptor)
webContents.setUserAgent(`${meta.name}/${version}`)
webContents.on('will-attach-webview', (event, webPreferences, params) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/windows/openWindowInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { shell } from 'electron'

function openWindowInterceptor (details) {
if (!details.url.startsWith('resource://')) {
if (!details.url.startsWith('https://oauth.vk.com/authorize')) {
if (!details.url.startsWith('https://oauth.vk.com/authorize') && !details.url.startsWith('https://id.vk.com/auth')) {
shell.openExternal(details.url)
return { action: 'deny' }
}
Expand Down
49 changes: 47 additions & 2 deletions src/renderer/views/account/login/AccountLoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<v-btn v-bind="{loading}" text @click="toBack">Назад</v-btn>
</v-layout>

<v-divider class="my-6" />

<v-layout justify-center>
<v-btn :color="'blue darken-1'" @click="authorizeWithVK">Вход через VK</v-btn>
</v-layout>

</v-card>
</v-col>

Expand All @@ -52,7 +58,7 @@
// Images
import LibriaTyan03 from '@assets/images/libria-tyan/LibriaTyan03.svg'
import { ipcRenderer } from "electron";
// Utils
import { required } from 'vuelidate/lib/validators'
import { BackViewMixin } from '@mixins/views'
Expand All @@ -76,9 +82,48 @@ export default {
login: { required },
password: { required },
},
mounted () {
ipcRenderer.on('VK_CODE', async (event, session) => {
try {
this.loading = true
await this.$store.dispatchPromise('app/account/setSession', session)
// Get profile data
await this.$store.dispatchPromise('app/account/getProfile')
await this.toBack()
// Get user favorites
this.$store.dispatchPromise('favorites/getFavorites')
this.loading = false
} catch (e) {
console.error(e)
if (e.response.status === 401) {
this.$toasted.error('Пользователь не зарегистрирован')
}
this.loading = false
}
})
},
beforeDestroy() {
ipcRenderer.removeAllListeners('VK_CODE')
},
methods: {
authorizeWithVK () {
window.open(
'https://id.vk.com/auth?return_auth_hash=677a695397f7de30e9&redirect_uri=https%3A%2F%2Fwww.anilibria.tv%2Fpublic%2Fvk.php&redirect_uri_hash=12e7b3a47bed04dc26&force_hash=&app_id=5315207&response_type=code&code_challenge=&code_challenge_method=&scope=0&state='
,'targetWindow',
`toolbar=no,
location=no,
status=no,
menubar=no,
scrollbars=yes,
resizable=yes,
width=SomeSize,
height=SomeSize`
)
},
/**
* Authorize
*
Expand Down

0 comments on commit deadf7a

Please sign in to comment.