Compare commits
No commits in common. "6a658ef747f14f0a9c134908aa9184eaeb0d03d8" and "f6346f8165924fe8fa154bbf84a1b046a30afbb3" have entirely different histories.
6a658ef747
...
f6346f8165
10 changed files with 43 additions and 175 deletions
14
blog/src/components/BackNav.astro
Normal file
14
blog/src/components/BackNav.astro
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
---
|
||||||
|
|
||||||
|
<a href={Astro.request.headers.get('referer') || '/'}>
|
||||||
|
<button class="rounded">zurück</button>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
button {
|
||||||
|
padding: 12px 24px;
|
||||||
|
margin: 8px 0 16px 0px;
|
||||||
|
border-style: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -1,56 +1,44 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
import { api, AUTH_TOKEN_KEY, USER_KEY, type User } from '../lib/api';
|
import type { JSX } from 'preact';
|
||||||
import { saveUser } from './Util';
|
import { api, AUTH_TOKEN_KEY } from '../lib/api';
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm() {
|
||||||
const [userCode, setUserCode] = useState('');
|
const [userCode, setUserCode] = useState('');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async (e: JSX.TargetedEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setLoading(true);
|
||||||
setError('');
|
setError('');
|
||||||
let hasError = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const jwt = await api.login(userCode);
|
const jwt = await api.login(userCode)
|
||||||
localStorage.setItem(AUTH_TOKEN_KEY, jwt);
|
localStorage.setItem(AUTH_TOKEN_KEY, jwt)
|
||||||
|
// window.location.href = '/';
|
||||||
const user = await api.getUserInfo()
|
|
||||||
saveUser(user)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
setError(err instanceof Error ? err.message : 'Login failed');
|
||||||
if (errorMessage.includes('Network')) {
|
|
||||||
setError("Backend nicht erreichbar")
|
|
||||||
} else if (errorMessage.includes('401')) {
|
|
||||||
setError("Das war leider nicht richtig")
|
|
||||||
} else if (errorMessage.includes('422')) {
|
|
||||||
setError("Musst schon was eingeben!")
|
|
||||||
} else if (errorMessage.includes('429')) {
|
|
||||||
setError("Timeout! Warte mal ein bisschen")
|
|
||||||
}
|
|
||||||
hasError = true
|
|
||||||
} finally {
|
} finally {
|
||||||
if (!hasError) navigation.back()
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('submit-login', handleLogin);
|
|
||||||
return () => window.removeEventListener('submit-login', handleLogin);
|
|
||||||
}, [userCode]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form onSubmit={(e) => { e.preventDefault(); handleLogin(); }}>
|
<h2>Login</h2>
|
||||||
<label>Code: </label>
|
<form onSubmit={handleLogin}>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={userCode}
|
value={userCode}
|
||||||
onChange={(e) => setUserCode(e.currentTarget.value)}
|
onChange={(e) => setUserCode(e.currentTarget.value)}
|
||||||
|
placeholder="Enter your code"
|
||||||
required
|
required
|
||||||
class="user-input"
|
|
||||||
/>
|
/>
|
||||||
|
<button type="submit" disabled={loading}>
|
||||||
|
{loading ? 'Logging in...' : 'Login'}
|
||||||
|
</button>
|
||||||
{error && <p style={{ color: 'red' }}>{error}</p>}
|
{error && <p style={{ color: 'red' }}>{error}</p>}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
export default function NavBack() {
|
|
||||||
|
|
||||||
function take_me_to_the_moon() {
|
|
||||||
navigation.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button class="back-btn" onClick={take_me_to_the_moon}>Zurück</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
import { getUser } from "./Util"
|
export default function LoginForm() {
|
||||||
|
|
||||||
export default function UserAction() {
|
|
||||||
let text = "⚓︎ Login"
|
let text = "⚓︎ Login"
|
||||||
let link = "/login"
|
let link = "/login"
|
||||||
|
|
||||||
const user = getUser()
|
const username = localStorage.getItem("username")
|
||||||
|
|
||||||
if (user) {
|
if (username) {
|
||||||
text = `⚓︎ ${user.name}`
|
text = `⚓︎ ${username}`
|
||||||
link = "/user"
|
link = "/user"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import { USER_KEY, type User } from "../lib/api"
|
|
||||||
|
|
||||||
export function saveUser(user: User) {
|
|
||||||
localStorage.setItem(USER_KEY, JSON.stringify(user))
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getUser(): User | null {
|
|
||||||
const user_string = localStorage.getItem(USER_KEY)
|
|
||||||
if (user_string) return JSON.parse(user_string) as User
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
---
|
---
|
||||||
import { Image } from "astro:assets";
|
import { Image } from "astro:assets";
|
||||||
|
import BackNav from "../components/BackNav.astro";
|
||||||
import { findImageByPath } from "../lib/findImage";
|
import { findImageByPath } from "../lib/findImage";
|
||||||
import Main from "./Main.astro";
|
import Main from "./Main.astro";
|
||||||
import { formatLocalizedDateString } from "../lib/formatDate";
|
import { formatLocalizedDateString } from "../lib/formatDate";
|
||||||
import type { PostData } from "../content.config";
|
import type { PostData } from "../content.config";
|
||||||
import NavBack from "../islands/NavBack";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
postData: PostData;
|
postData: PostData;
|
||||||
|
|
@ -30,7 +30,7 @@ const localeDate = formatLocalizedDateString(postData.date);
|
||||||
<span>{localeDate}</span>
|
<span>{localeDate}</span>
|
||||||
</div>
|
</div>
|
||||||
<slot />
|
<slot />
|
||||||
<NavBack client:only />
|
<BackNav />
|
||||||
<p class="disclaimer">
|
<p class="disclaimer">
|
||||||
Disclaimer: Dieser Artikel ist ausschließlich privat und wird nicht durch
|
Disclaimer: Dieser Artikel ist ausschließlich privat und wird nicht durch
|
||||||
Produktplatzierung, Affiliate-Links oder ähnliches Unterstützt. Links
|
Produktplatzierung, Affiliate-Links oder ähnliches Unterstützt. Links
|
||||||
|
|
@ -106,7 +106,6 @@ const localeDate = formatLocalizedDateString(postData.date);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@media only screen and (max-width: 800px) {
|
@media only screen and (max-width: 800px) {
|
||||||
.markdown-content {
|
.markdown-content {
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import "../styles/global.css";
|
||||||
<style>
|
<style>
|
||||||
main {
|
main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
width: 100%;
|
margin: 32px auto;
|
||||||
margin: 0;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ export interface User {
|
||||||
|
|
||||||
const API_BASE = import.meta.env.PUBLIC_API_URL;
|
const API_BASE = import.meta.env.PUBLIC_API_URL;
|
||||||
export const AUTH_TOKEN_KEY = 'authToken'
|
export const AUTH_TOKEN_KEY = 'authToken'
|
||||||
export const USER_KEY = 'user'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BlauwasserAPI {
|
class BlauwasserAPI {
|
||||||
private async fetchAPI<T>(
|
private async fetchAPI<T>(
|
||||||
|
|
|
||||||
|
|
@ -1,81 +1,8 @@
|
||||||
---
|
---
|
||||||
import LoginForm from "../islands/LoginForm";
|
|
||||||
import NavBack from "../islands/NavBack";
|
|
||||||
import Main from "../layouts/Main.astro";
|
import Main from "../layouts/Main.astro";
|
||||||
---
|
---
|
||||||
|
|
||||||
<Main>
|
<Main>
|
||||||
<div id="background">
|
|
||||||
<div id="content">
|
|
||||||
<img src="../..//blog_img/england/titelbild_england.webp" />
|
|
||||||
<div id="form">
|
|
||||||
<h1>Login</h1>
|
|
||||||
<span>Gib deinen persönlichen Code ein</span>
|
|
||||||
<p>
|
|
||||||
Meld dich an, um deine Daten zu bearbeiten. Gib dafür den
|
|
||||||
Code ein, denn du nach dem registrieren via E-Mail erhalten
|
|
||||||
hast.
|
|
||||||
</p>
|
|
||||||
<LoginForm client:load />
|
|
||||||
|
|
||||||
<div id="buttons">
|
|
||||||
<NavBack client:load />
|
</Main>
|
||||||
<button
|
|
||||||
onclick="window.dispatchEvent(new Event('submit-login'))"
|
|
||||||
class="submit-btn"
|
|
||||||
>
|
|
||||||
⚓︎ Anmelden
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Main>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
#background {
|
|
||||||
background-image: linear-gradient(
|
|
||||||
to bottom,
|
|
||||||
var(--primary-dark),
|
|
||||||
var(--primary-color)
|
|
||||||
);
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
padding: 0 20%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#content {
|
|
||||||
background-color: white;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
height: 300px;
|
|
||||||
object-fit: cover;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#form {
|
|
||||||
padding: 32px 64px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#buttons {
|
|
||||||
display: flex;
|
|
||||||
width: 100%;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: end;
|
|
||||||
padding-top: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
padding-bottom: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
:root {
|
:root {
|
||||||
--primary-color: #3c6a7b;
|
--primary-color: #416A79;
|
||||||
--primary-dark: #1d3238;
|
|
||||||
--primary-text: #454545;
|
--primary-text: #454545;
|
||||||
--accent-color: #ffff00;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
|
|
@ -50,37 +48,6 @@ body {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-btn {
|
|
||||||
border: none;
|
|
||||||
background-color: transparent;
|
|
||||||
font-weight: bolder;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 1rem;
|
|
||||||
padding: 12px 12px 12px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.submit-btn {
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
background-color: var(--primary-color);
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 12px;
|
|
||||||
font-weight: bolder;
|
|
||||||
font-size: 1rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.submit-btn:hover {
|
|
||||||
background-color: var(--primary-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-input {
|
|
||||||
border: none;
|
|
||||||
background-color: #e9e9e9;
|
|
||||||
padding: 4px;
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.headline {
|
.headline {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue