add admin login
This commit is contained in:
@ -31,10 +31,11 @@
|
||||
</span>
|
||||
</label>
|
||||
{/if}
|
||||
<div class="flex items-center">
|
||||
<div class="flex items-center" class:sm:max-w-[16rem]={type !== 'checkbox'}>
|
||||
<input
|
||||
class:checkbox={type === 'checkbox'}
|
||||
class:input,input-bordered,w-[100%],sm:max-w-[16rem]={type !== 'checkbox'}
|
||||
class:input,input-bordered={type !== 'checkbox'}
|
||||
class:w-[100%]={initialType !== 'password' && initialType !== 'checkbox'}
|
||||
class:pr-11={initialType === 'password'}
|
||||
{id}
|
||||
{name}
|
||||
|
58
src/lib/components/Toast/ErrorToast.svelte
Normal file
58
src/lib/components/Toast/ErrorToast.svelte
Normal file
@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { IconOutline } from 'svelte-heros-v2';
|
||||
import { fly } from 'svelte/transition';
|
||||
import { onDestroy } from 'svelte';
|
||||
|
||||
export let timeout = 2000;
|
||||
export let show = false;
|
||||
|
||||
export function reset() {
|
||||
progressValue = 1;
|
||||
}
|
||||
|
||||
let progressValue = 100;
|
||||
let intervalClear: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
function startTimout() {
|
||||
intervalClear = setInterval(() => {
|
||||
if (++progressValue > 100) {
|
||||
clearInterval(intervalClear);
|
||||
show = false;
|
||||
progressValue = 100;
|
||||
}
|
||||
}, timeout / 100);
|
||||
}
|
||||
|
||||
$: if (show) {
|
||||
progressValue = 0;
|
||||
startTimout();
|
||||
}
|
||||
|
||||
onDestroy(() => clearInterval(intervalClear));
|
||||
</script>
|
||||
|
||||
{#if show && progressValue !== 0}
|
||||
<div
|
||||
in:fly={{ x: 0, duration: 200 }}
|
||||
out:fly={{ x: 400, duration: 400 }}
|
||||
class="toast"
|
||||
on:mouseenter={() => {
|
||||
clearInterval(intervalClear);
|
||||
progressValue = 1;
|
||||
}}
|
||||
on:mouseleave={startTimout}
|
||||
role="alert"
|
||||
>
|
||||
<div class="alert alert-error border-none relative text-gray-900 overflow-hidden">
|
||||
<div class="flex gap-2 z-10">
|
||||
<IconOutline name="exclamation-circle-outline" />
|
||||
<span>Nutzername oder Passwort falsch</span>
|
||||
</div>
|
||||
<progress
|
||||
class="progress progress-error absolute bottom-0 h-[3px] w-full bg-[rgba(0,0,0,0.6)]"
|
||||
value={progressValue}
|
||||
max="100"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
@ -1 +0,0 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
@ -1,37 +1,53 @@
|
||||
import { DataTypes, Sequelize } from 'sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { building, dev } from '$app/environment';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { BeforeCreate, BeforeUpdate, Column, Model, Sequelize, Table } from 'sequelize-typescript';
|
||||
|
||||
@Table({ modelName: 'user' })
|
||||
export class User extends Model {
|
||||
@Column({ type: DataTypes.STRING, allowNull: false })
|
||||
declare firstname: string;
|
||||
@Column({ type: DataTypes.STRING, allowNull: false })
|
||||
declare lastname: string;
|
||||
@Column({ type: DataTypes.DATE, allowNull: false })
|
||||
declare birthday: Date;
|
||||
@Column({ type: DataTypes.STRING })
|
||||
declare telephone: string;
|
||||
@Column({ type: DataTypes.STRING, allowNull: false })
|
||||
declare username: string;
|
||||
@Column({ type: DataTypes.ENUM('java', 'bedrock', 'cracked'), allowNull: false })
|
||||
declare playertype: 'java' | 'bedrock' | 'cracked';
|
||||
@Column({ type: DataTypes.STRING })
|
||||
declare password: string;
|
||||
@Column({ type: DataTypes.UUIDV4 })
|
||||
declare uuid: string;
|
||||
}
|
||||
|
||||
@Table({ modelName: 'admin' })
|
||||
export class Admin extends Model {
|
||||
@Column({ type: DataTypes.STRING, allowNull: false })
|
||||
declare username: string;
|
||||
@Column({ type: DataTypes.STRING, allowNull: false })
|
||||
declare password: string;
|
||||
@Column({ type: DataTypes.BIGINT, allowNull: false })
|
||||
declare permissions: number;
|
||||
|
||||
@BeforeCreate
|
||||
@BeforeUpdate
|
||||
static hashPassword(instance: Admin) {
|
||||
if (instance.password != null) {
|
||||
instance.username = bcrypt.hashSync(instance.password, 10);
|
||||
}
|
||||
}
|
||||
|
||||
validatePassword(password: string): boolean {
|
||||
return bcrypt.compareSync(password, this.password);
|
||||
}
|
||||
}
|
||||
|
||||
export const sequelize = new Sequelize(building ? 'sqlite::memory:' : env.DATABASE_URI, {
|
||||
// only log sql queries in dev mode
|
||||
logging: dev ? console.log : false
|
||||
});
|
||||
|
||||
export const User = sequelize.define('user', {
|
||||
firstname: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
lastname: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
birthday: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
telephone: DataTypes.STRING,
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
playertype: {
|
||||
type: DataTypes.ENUM('java', 'bedrock', 'cracked'),
|
||||
allowNull: false
|
||||
},
|
||||
password: DataTypes.TEXT,
|
||||
uuid: {
|
||||
type: DataTypes.UUIDV4,
|
||||
allowNull: false
|
||||
}
|
||||
logging: dev ? console.log : false,
|
||||
models: [User, Admin]
|
||||
});
|
||||
|
11
src/lib/server/session.ts
Normal file
11
src/lib/server/session.ts
Normal file
@ -0,0 +1,11 @@
|
||||
const sessions: string[] = [];
|
||||
|
||||
export function addSession(): string {
|
||||
const session = 'AAA';
|
||||
sessions.push(session);
|
||||
return session;
|
||||
}
|
||||
|
||||
export function hasSession(session: string): boolean {
|
||||
return sessions.find((v) => v == session) != undefined;
|
||||
}
|
Reference in New Issue
Block a user