Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Login #23

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/cloudworkMicromata.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions frontend/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
2 changes: 1 addition & 1 deletion frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="/" class="text-blue-700 mx-4 hover:text-blue-500">Home</a>
<a href="/" class="text-blue-700 mx-4 hover:text-blue-500">News</a>
<a href="/" class="text-blue-700 mx-4 hover:text-blue-500">PlaceHolder</a>
<a href="/login" class="text-blue-700 mx-4 hover:text-blue-500 ml-auto">Login</a>
<a href="/login" class="text-blue-700 mx-4 hover:text-blue-500 ml-auto">Sign</a>
<div class="relative ml-3 pr-5">
<div>
<button
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/routes/login/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type {Actions} from "./$types";
import {env} from "$env/dynamic/public";
import { goto } from '$app/navigation';

export const actions:Actions = {
default: async ({request, fetch, cookies}) => {

const data = await request.formData();
const username = data.get('username');
const password = data.get('password');

const response = await fetch(env.PUBLIC_BACKEND_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});

if (!response.ok) {
throw new Error('An error occurred during the API call.');
}
const responseData = await response.json();
const authToken = responseData.token;

// Setze das Cookie mit einer Gültigkeitsdauer von 30 Tagen
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + 30);

cookies.set('authToken', authToken, { expires: expirationDate });

goto('/');

}
}
13 changes: 7 additions & 6 deletions frontend/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
<form method="post" class="w-full max-w-md bg-white shadow-md rounded-md p-6">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
Benutzername
Username
<input name="username" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="text">
</label>
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="text">
</div>

<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
Passwort
Password
<input name="password" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="password">
</label>
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="password">
</div>

<button class="w-full bg-indigo-500 text-white py-2 rounded-md hover:bg-indigo-600 focus:outline-none" type="submit">
Einloggen
Sign In
</button>
<div class="pt-3">
<a>Don't have an Account? Create one</a> <a href="../register" class="text-blue-700 underline">here</a>
<a>Don't have an Account? Create one</a>
<a href="../register" class="text-blue-700 underline">here</a>
</div>

</form>
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/routes/register/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {Actions} from "./$types";
import {env} from "$env/dynamic/public";

export const actions:Actions = {
default: async ({request, fetch}) => {

const data = await request.formData();
const username = data.get('username');
const email = data.get('email')
const password = data.get('password');
const passwordConfirm = data.get('passwordConfirm');
}
}
40 changes: 40 additions & 0 deletions frontend/src/routes/register/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="flex items-center pb-80 justify-center h-screen">
<form method="post" class="w-full max-w-md bg-white shadow-md rounded-md p-6">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
Username
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="text">
</label>
</div>

<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
E-Mail
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="password">
</label>
</div>

<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
Password
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="password">
</label>
</div>

<div class="mb-4">
<label class="block text-gray-700 text-sm font-semibold mb-2">
Repeat Password
<input class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:border-indigo-500" type="password">
</label>
</div>

<button class="w-full bg-indigo-500 text-white py-2 rounded-md hover:bg-indigo-600 focus:outline-none" type="submit">
Sign Up
</button>
<div class="pt-3">
<a>Already have an Accounr? Click</a>
<a href="../login" class="text-blue-700 underline">here</a>
</div>

</form>
</div>
9 changes: 9 additions & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{html,js,svelte,ts}'],
theme: {
extend: {},
},
plugins: [],
}

Loading