20
+    </div>
21
+</div>
22
+{% endblock %}

+ 22 - 0
app/sysadmin/templates/auth/register.html

@@ -0,0 +1,22 @@
1
+{% extends "base.html" %}
2
+{% load tailwind_filters %}
3
+{% block title %}Register{% endblock %}
4
+
5
+{% block content %}
6
+<div class="flex items-center justify-center  bg-gray-100">
7
+    <div class="w-full max-w-md p-8 bg-white rounded-lg shadow-md">
8
+        <h2 class="text-2xl font-bold text-center text-gray-700">Register</h2>
9
+        <form method="post" class="space-y-4 mt-6">
10
+            {% csrf_token %}
11
+            {{ form|crispy }}
12
+            <button type="submit" class="w-full bg-green-500 text-white py-2 rounded hover:bg-green-600">
13
+                Register
14
+            </button>
15
+        </form>
16
+        <p class="mt-4 text-center text-gray-600">
17
+            Already have an account? 
18
+            <a href="{% url 'sysadmin:login' %}" class="text-blue-500 hover:underline">Login</a>
19
+        </p>
20
+    </div>
21
+</div>
22
+{% endblock %}

+ 3 - 0
app/sysadmin/tests.py

@@ -0,0 +1,3 @@
1
+from django.test import TestCase
2
+
3
+# Create your tests here.

+ 10 - 0
app/sysadmin/urls.py

@@ -0,0 +1,10 @@
1
+from django.urls import path
2
+from . import views
3
+
4
+app_name = "sysadmin"  # Use this namespace for reverse URL lookups
5
+
6
+urlpatterns = [
7
+    path('login/', views.login_view, name='login'),
8
+    path('register/', views.register_view, name='register'),
9
+    path('logout/', views.logout_view, name='logout'),
10
+]

+ 32 - 0
app/sysadmin/views.py

@@ -0,0 +1,32 @@
1
+# views.py
2
+from django.contrib.auth import authenticate, login, logout
3
+from django.shortcuts import render, redirect
4
+from .forms import CustomLoginForm, CustomUserCreationForm
5
+
6
+def login_view(request):
7
+    if request.method == "POST":
8
+        form = CustomLoginForm(data=request.POST)
9
+        if form.is_valid():
10
+            user = form.get_user()
11
+            login(request, user)
12
+            return redirect('dashboard:index')  # Redirect to your dashboard
13
+    else:
14
+        form = CustomLoginForm()
15
+
16
+    return render(request, 'auth/login.html', {'form': form, 'hide_sidebar': True})
17
+
18
+def register_view(request):
19
+    if request.method == "POST":
20
+        form = CustomUserCreationForm(request.POST)
21
+        if form.is_valid():
22
+            user = form.save()
23
+            login(request, user)  # Log the user in after creation
24
+            return redirect('dashboard:index')  # Redirect to your dashboard
25
+    else:
26
+        form = CustomUserCreationForm()
27
+
28
+    return render(request, 'auth/register.html', {'form': form, 'hide_sidebar': True})
29
+
30
+def logout_view(request):
31
+    logout(request)  # Logs out the user
32
+    return redirect('sysadmin:login')  # Redirect to the login page after logout

+ 13 - 1
app/templates/base.html

@@ -34,7 +34,17 @@
34 34
                         <span class="self-center text-xl font-semibold dark:text-white">My App</span>
35 35
                     </a>
36 36
                 </div>
37
-                <div class="flex items-center">
37
+                <div class="flex items-center space-x-4">
38
+
39
+                {% if user.is_authenticated %}
40
+                    <!-- Logged-in User -->
41
+                    <span class="text-gray-600 dark:text-gray-300">Hello, {{ user.username }}</span>
42
+                    <a href="{% url 'sysadmin:logout' %}" class="text-blue-500 hover:underline">Logout</a>
43
+                {% else %}
44
+                    <!-- Guest User -->
45
+                    <a href="{% url 'sysadmin:login' %}" class="text-blue-500 hover:underline">Login</a>
46
+                    <a href="{% url 'sysadmin:register' %}" class="text-blue-500 hover:underline">Register</a>
47
+                {% endif %}
38 48
                     <div class="ml-3">
39 49
                         <button type="button" class="flex text-sm bg-gray-800 rounded-full focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600">
40 50
                             <span class="sr-only">Open user menu</span>
@@ -47,6 +57,7 @@
47 57
     </nav>
48 58
 
49 59
     <!-- Sidebar -->
60
+    {% if not hide_sidebar %}
50 61
     <aside id="logo-sidebar" class="fixed top-0 left-0 z-40 w-64 h-screen pt-20 transition-transform -translate-x-full bg-white border-r border-gray-200 sm:translate-x-0 dark:bg-gray-800 dark:border-gray-700">
51 62
         <div class="h-full px-3 pb-4 overflow-y-auto">
52 63
             <ul class="space-y-2">
@@ -56,6 +67,7 @@
56 67
             </ul>
57 68
         </div>
58 69
     </aside>
70
+    {% endif %}
59 71
 
60 72
     <!-- Main Content -->
61 73
     <div class="p-4 sm:ml-64">

+ 2 - 2
requirements.txt

@@ -33,11 +33,11 @@ django-crispy-forms  # Styling for forms
33 33
 crispy-bootstrap5  # For Bootstrap 5 support (optional)
34 34
 
35 35
 # If using TailwindCSS instead of Bootstrap
36
-django-tailwind  # For TailwindCSS integration
36
+# django-tailwind  # For TailwindCSS integration
37 37
 
38 38
 # Cache optimization (optional)
39 39
 django-cacheops  # Caching ORM QuerySets
40
-
40
+crispy-tailwind
41 41
 pandas
42 42
 numpy
43 43
 scipy

tmt/tiger_frontend - Gogs: Simplico Git Service

Bez popisu

golf 77628cf8bf first comm %!s(int64=2) %!d(string=před) roky
..
dist 77628cf8bf first comm %!s(int64=2) %!d(string=před) roky
LICENSE 77628cf8bf first comm %!s(int64=2) %!d(string=před) roky
README.md 77628cf8bf first comm %!s(int64=2) %!d(string=před) roky
package.json 77628cf8bf first comm %!s(int64=2) %!d(string=před) roky

README.md

ts-interface-checker

Build Status npm version

Runtime library to validate data against TypeScript interfaces.

This package is the runtime support for validators created by ts-interface-builder. It allows validating data, such as parsed JSON objects received over the network, or parsed JSON or YAML files, to check if they satisfy a TypeScript interface, and to produce informative error messages if they do not.

Installation

npm install --save-dev ts-interface-builder
npm install --save ts-interface-checker

Usage

Suppose you have a TypeScript file defining an interface:

// foo.ts
interface Square {
  size: number;
  color?: string;
}

The first step is to generate some code for runtime checks:

`npm bin`/ts-interface-builder foo.ts

It produces a file like this:

// foo-ti.js
import * as t from "ts-interface-checker";

export const Square = t.iface([], {
  "size": "number",
  "color": t.opt("string"),
});
...

Now at runtime, to check if a value satisfies the Square interface:

import fooTI from "./foo-ti";
import {createCheckers} from "ts-interface-checker";

const {Square} = createCheckers(fooTI);

Square.check({size: 1});                  // OK
Square.check({size: 1, color: "green"});  // OK
Square.check({color: "green"});           // Fails with "value.size is missing"
Square.check({size: 4, color: 5});        // Fails with "value.color is not a string"

Note that ts-interface-builder is only needed for the build-time step, and ts-interface-checker is needed at runtime. That's why the recommendation is to npm-install the former using --save-dev flag and the latter using --save.

Checking method calls

If you have an interface with methods, you can validate method call arguments and return values:

// greet.ts
interface Greeter {
  greet(name: string): string;
}

After generating the runtime code, you can now check calls like:

import greetTI from "./greet-ti";
import {createCheckers} from "ts-interface-checker";

const {Greeter} = createCheckers(greetTI);

Greeter.methodArgs("greet").check(["Bob"]);     // OK
Greeter.methodArgs("greet").check([17]);        // Fails with "value.name is not a string"
Greeter.methodArgs("greet").check([]);          // Fails with "value.name is missing"

Greeter.methodResult("greet").check("hello");   // OK
Greeter.methodResult("greet").check(null);      // Fails with "value is not a string"

Type suites

If one type refers to a type defined in another file, you need to tell the interface checker about all type names when you call createCheckers(). E.g. given

// color.ts
export type Color = RGB | string;
export type RGB = [number, number, number];
// shape.ts
import {Color} from "./color";
export interface Square {
  size: number;
  color?: Color;
}

the produced files color-ti.ts and shape-ti.ts do not automatically refer to each other, but expect you to relate them in createCheckers() call:

import color from "./color-ti";
import shape from "./shape-ti";
import {createCheckers} from "ts-interface-checker";

const {Square} = createCheckers(shape, color);    // Pass in all required type suites.

Square.check({size: 1, color: [255,255,255]});

Strict checking

You may check that data contains no extra properties. Note that it is not generally recommended as it this prevents backward compatibility: if you add new properties to an interface, then older code with strict checks will not accept them.

Following on the example above:

Square.strictCheck({size: 1, color: [255,255,255], bg: "blue"});    // Fails with value.bg is extraneous
Square.strictCheck({size: 1, color: [255,255,255,0.5]});            // Fails with ...value.color[3] is extraneous

Type guards

Standard Checker objects do the type checking logic, but are unable to make the TypeScript compiler aware that an object of unknown type implements a certain interface.

Basic code:

const unk: unknown = {size: 1, color: "green"};
// Type is unknown, so TypeScript will not let you access the members.
console.log(unk.size); // Error: "Object is of type 'unknown'"

With a Checker available:

import fooTI from "./foo-ti";
import {createCheckers} from "ts-interface-checker";

const {Square} = createCheckers(fooTI);

const unk: unknown = {size: 1, color: "green"};

if (Square.test(unk)) {
  // unk does implement Square, but TypeScript is not aware of it.
  console.log(unk.size); // Error: "Object is of type 'unknown'"
}

To enable type guard functionality on the existing test, and strictTest functions, Checker objects should be cast to CheckerT<> using the appropriate type.

Using CheckerT<>:

import {Square} from "./foo";
import fooTI from "./foo-ti";
import {createCheckers, CheckerT} from "ts-interface-checker";

const {Square} = createCheckers(fooTI) as {Square: CheckerT<Square>};

const unk: unknown = {size: 1, color: "green"};

if (Square.test(unk)) {
  // TypeScript is now aware that unk implements Square, and allows member access.
  console.log(unk.size);
}

Type assertions

CheckerT<> will eventually support type assertions using the check and strictCheck functions, however, this feature is not yet fully working in TypeScript.