mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 15:15:37 +01:00
Add login page
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
venv
|
venv
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
|||||||
8
poetry.lock
generated
8
poetry.lock
generated
@@ -1059,13 +1059,13 @@ files = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pydantic"
|
name = "pydantic"
|
||||||
version = "2.10.4"
|
version = "2.10.5"
|
||||||
description = "Data validation using Python type hints"
|
description = "Data validation using Python type hints"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
files = [
|
files = [
|
||||||
{file = "pydantic-2.10.4-py3-none-any.whl", hash = "sha256:597e135ea68be3a37552fb524bc7d0d66dcf93d395acd93a00682f1efcb8ee3d"},
|
{file = "pydantic-2.10.5-py3-none-any.whl", hash = "sha256:4dd4e322dbe55472cb7ca7e73f4b63574eecccf2835ffa2af9021ce113c83c53"},
|
||||||
{file = "pydantic-2.10.4.tar.gz", hash = "sha256:82f12e9723da6de4fe2ba888b5971157b3be7ad914267dea8f05f82b28254f06"},
|
{file = "pydantic-2.10.5.tar.gz", hash = "sha256:278b38dbbaec562011d659ee05f63346951b3a248a6f3642e1bc68894ea2b4ff"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
@@ -1987,4 +1987,4 @@ type = ["pytest-mypy"]
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "54b7af11ca7015e9a96234a672549033d77151acbed7c12675b097ed498a681b"
|
content-hash = "bd44ab97afc7310e67c61b6a658180ed4592e01a06f95d645fb42c8e9a60b759"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ packages = [{include = "discord_bot"}]
|
|||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
discord-py = "^2.4.0"
|
discord-py = "^2.4.0"
|
||||||
twitchapi = "^4.4.0"
|
twitchapi = "^4.4.0"
|
||||||
pydantic = "^2.10.4"
|
pydantic = "^2.10.5"
|
||||||
pydantic-settings = "^2.7.1"
|
pydantic-settings = "^2.7.1"
|
||||||
httpx = "^0.28.1"
|
httpx = "^0.28.1"
|
||||||
icalendar = "^6.1.0"
|
icalendar = "^6.1.0"
|
||||||
|
|||||||
16
src/modules/web_app/frontend/index.css
Normal file
16
src/modules/web_app/frontend/index.css
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
.authorize__container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.authorize__twitch_btn {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #6441a5;
|
||||||
|
color: #fff;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
20
src/modules/web_app/frontend/index.html
Normal file
20
src/modules/web_app/frontend/index.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Web App</title>
|
||||||
|
<link rel="stylesheet" href="./index.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="importmap">
|
||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.prod.js",
|
||||||
|
"vue-router": "https://unpkg.com/vue-router@4.5.0/dist/vue-router.esm-browser.prod.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="app"></div>
|
||||||
|
|
||||||
|
<script type="module" src="/index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
97
src/modules/web_app/frontend/index.js
Normal file
97
src/modules/web_app/frontend/index.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { createApp, ref, onMounted } from 'vue';
|
||||||
|
import { createRouter, createWebHistory, RouterView } from 'vue-router';
|
||||||
|
|
||||||
|
|
||||||
|
const Authorize = {
|
||||||
|
setup() {
|
||||||
|
const loginLink = ref(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetch('/api/auth/get_authorization_url/twitch/')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
loginLink.value = data.authorization_url;
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
loginLink
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<div class="authorize__container">
|
||||||
|
<a v-if="loginLink" :href="loginLink" class="authorize__twitch_btn">Login with Twitch</a>
|
||||||
|
<div v-else>Loading...</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Settings = {
|
||||||
|
template: `
|
||||||
|
<div>Settings</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Main = {
|
||||||
|
components: {
|
||||||
|
Authorize,
|
||||||
|
Settings
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const authorized = localStorage.getItem('token') !== null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
authorized
|
||||||
|
};
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<div>
|
||||||
|
<Settings v-if="authorized" />
|
||||||
|
<Authorize v-else />
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const AuthCallbackTwitch = {
|
||||||
|
setup() {
|
||||||
|
onMounted(() => {
|
||||||
|
fetch('/api/auth/callback/twitch/' + urlParams.search)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
localStorage.setItem('token', data.token);
|
||||||
|
|
||||||
|
this.$router.push('/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<div>AuthCallbackTwitch</div>
|
||||||
|
`
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes: [
|
||||||
|
{ path: '', component: Main },
|
||||||
|
{ path: '/auth/callback/twitch/', component: AuthCallbackTwitch },
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const App = {
|
||||||
|
components: {
|
||||||
|
RouterView,
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<RouterView />
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
createApp(App)
|
||||||
|
.use(router)
|
||||||
|
.mount('#app');
|
||||||
@@ -9,7 +9,7 @@ from modules.web_app.auth.authx import auth
|
|||||||
from repositories.users import UserRepository
|
from repositories.users import UserRepository
|
||||||
|
|
||||||
|
|
||||||
auth_router = APIRouter(prefix="/auth", tags=["auth"])
|
auth_router = APIRouter(prefix="/api/auth", tags=["auth"])
|
||||||
|
|
||||||
|
|
||||||
@auth_router.get("/get_authorization_url/{provider}/")
|
@auth_router.get("/get_authorization_url/{provider}/")
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from repositories.users import UserRepository
|
|||||||
from domain.auth import OAuthProvider
|
from domain.auth import OAuthProvider
|
||||||
|
|
||||||
|
|
||||||
streamer_router = APIRouter(prefix="/streamers")
|
streamer_router = APIRouter(prefix="/api/streamers")
|
||||||
|
|
||||||
|
|
||||||
@streamer_router.get("/")
|
@streamer_router.get("/")
|
||||||
|
|||||||
Reference in New Issue
Block a user