Compare commits
2 Commits
d4e437624a
...
feec2a0c52
Author | SHA1 | Date | |
---|---|---|---|
feec2a0c52 | |||
afa55c2112 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/dist
|
/dist
|
||||||
|
/uploads
|
@ -2,6 +2,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
@ -19,6 +21,7 @@ type Account struct {
|
|||||||
|
|
||||||
Name string `json:"name" gorm:"uniqueIndex"`
|
Name string `json:"name" gorm:"uniqueIndex"`
|
||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
State AccountState `json:"state"`
|
State AccountState `json:"state"`
|
||||||
Profile AccountProfile `json:"profile"`
|
Profile AccountProfile `json:"profile"`
|
||||||
Sessions []AuthSession `json:"sessions"`
|
Sessions []AuthSession `json:"sessions"`
|
||||||
@ -39,6 +42,11 @@ func (v Account) GetPrimaryEmail() AccountContact {
|
|||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Account) GetAvatarPath() string {
|
||||||
|
basepath := viper.GetString("content")
|
||||||
|
return filepath.Join(basepath, v.Avatar)
|
||||||
|
}
|
||||||
|
|
||||||
type AccountContactType = int8
|
type AccountContactType = int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -38,6 +38,10 @@ func getUserinfo(c *fiber.Ctx) error {
|
|||||||
resp["email"] = data.GetPrimaryEmail().Content
|
resp["email"] = data.GetPrimaryEmail().Content
|
||||||
resp["preferred_username"] = data.Nick
|
resp["preferred_username"] = data.Nick
|
||||||
|
|
||||||
|
if len(data.Avatar) > 0 {
|
||||||
|
resp["picture"] = fmt.Sprintf("https://%s/api/avatar/%s", viper.GetString("domain"), data.Avatar)
|
||||||
|
}
|
||||||
|
|
||||||
return c.JSON(resp)
|
return c.JSON(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
pkg/server/avatar_api.go
Normal file
35
pkg/server/avatar_api.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.smartsheep.studio/hydrogen/passport/pkg/database"
|
||||||
|
"code.smartsheep.studio/hydrogen/passport/pkg/models"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getAvatar(c *fiber.Ctx) error {
|
||||||
|
id := c.Params("avatarId")
|
||||||
|
basepath := viper.GetString("content")
|
||||||
|
|
||||||
|
return c.SendFile(filepath.Join(basepath, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
func setAvatar(c *fiber.Ctx) error {
|
||||||
|
user := c.Locals("principal").(models.Account)
|
||||||
|
file, err := c.FormFile("avatar")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Avatar = uuid.NewString()
|
||||||
|
|
||||||
|
if err := c.SaveFile(file, user.GetAvatarPath()); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
database.C.Save(&user)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
@ -57,6 +57,9 @@ func NewServer() {
|
|||||||
|
|
||||||
api := A.Group("/api").Name("API")
|
api := A.Group("/api").Name("API")
|
||||||
{
|
{
|
||||||
|
api.Get("/avatar/:avatarId", getAvatar)
|
||||||
|
api.Put("/avatar", auth, setAvatar)
|
||||||
|
|
||||||
api.Get("/users/me", auth, getUserinfo)
|
api.Get("/users/me", auth, getUserinfo)
|
||||||
api.Put("/users/me", auth, editUserinfo)
|
api.Put("/users/me", auth, editUserinfo)
|
||||||
api.Get("/users/me/events", auth, getEvents)
|
api.Get("/users/me/events", auth, getEvents)
|
||||||
|
@ -19,6 +19,7 @@ render(() => (
|
|||||||
<UserinfoProvider>
|
<UserinfoProvider>
|
||||||
<Router root={RootLayout}>
|
<Router root={RootLayout}>
|
||||||
<Route path="/" component={lazy(() => import("./pages/dashboard.tsx"))} />
|
<Route path="/" component={lazy(() => import("./pages/dashboard.tsx"))} />
|
||||||
|
<Route path="/security" component={lazy(() => import("./pages/security.tsx"))} />
|
||||||
<Route path="/personalise" component={lazy(() => import("./pages/personalise.tsx"))} />
|
<Route path="/personalise" component={lazy(() => import("./pages/personalise.tsx"))} />
|
||||||
<Route path="/auth/login" component={lazy(() => import("./pages/auth/login.tsx"))} />
|
<Route path="/auth/login" component={lazy(() => import("./pages/auth/login.tsx"))} />
|
||||||
<Route path="/auth/register" component={lazy(() => import("./pages/auth/register.tsx"))} />
|
<Route path="/auth/register" component={lazy(() => import("./pages/auth/register.tsx"))} />
|
||||||
|
@ -11,6 +11,7 @@ interface MenuItem {
|
|||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
const nav: MenuItem[] = [
|
const nav: MenuItem[] = [
|
||||||
{ label: "Dashboard", href: "/" },
|
{ label: "Dashboard", href: "/" },
|
||||||
|
{ label: "Security", href: "/security" },
|
||||||
{ label: "Personalise", href: "/personalise" }
|
{ label: "Personalise", href: "/personalise" }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { getAtk, readProfiles, useUserinfo } from "../stores/userinfo.tsx";
|
import { useUserinfo } from "../stores/userinfo.tsx";
|
||||||
import { createSignal, For, Show } from "solid-js";
|
import { Show } from "solid-js";
|
||||||
|
|
||||||
export default function DashboardPage() {
|
export default function DashboardPage() {
|
||||||
const userinfo = useUserinfo();
|
const userinfo = useUserinfo();
|
||||||
@ -16,46 +16,10 @@ export default function DashboardPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [events, setEvents] = createSignal<any[]>([]);
|
|
||||||
const [eventCount, setEventCount] = createSignal(0);
|
|
||||||
|
|
||||||
const [error, setError] = createSignal<string | null>(null);
|
|
||||||
const [submitting, setSubmitting] = createSignal(false);
|
|
||||||
|
|
||||||
async function readEvents() {
|
|
||||||
const res = await fetch("/api/users/me/events?take=10", {
|
|
||||||
headers: { Authorization: `Bearer ${getAtk()}` }
|
|
||||||
});
|
|
||||||
if (res.status !== 200) {
|
|
||||||
setError(await res.text());
|
|
||||||
} else {
|
|
||||||
const data = await res.json();
|
|
||||||
setEvents(data["data"]);
|
|
||||||
setEventCount(data["count"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function killSession(item: any) {
|
|
||||||
setSubmitting(true);
|
|
||||||
const res = await fetch(`/api/users/me/sessions/${item.id}`, {
|
|
||||||
method: "DELETE",
|
|
||||||
headers: { Authorization: `Bearer ${getAtk()}` }
|
|
||||||
});
|
|
||||||
if (res.status !== 200) {
|
|
||||||
setError(await res.text());
|
|
||||||
} else {
|
|
||||||
await readProfiles();
|
|
||||||
setError(null);
|
|
||||||
}
|
|
||||||
setSubmitting(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
readEvents();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="max-w-[720px] mx-auto px-5 pt-12">
|
<div class="max-w-[720px] mx-auto px-5 pt-12">
|
||||||
<div id="greeting" class="px-5">
|
<div id="greeting" class="px-5">
|
||||||
<h1 class="text-2xl font-bold">Welcome, {userinfo?.displayName}</h1>
|
<h1 class="text-2xl font-bold">{userinfo?.displayName}</h1>
|
||||||
<p>{getGreeting()}</p>
|
<p>{getGreeting()}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -73,176 +37,20 @@ export default function DashboardPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={error()}>
|
|
||||||
<div role="alert" class="alert alert-error mt-5">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
|
||||||
viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
<span class="capitalize">{error()}</span>
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="overview" class="mt-5">
|
<div class="card shadow-xl mt-5">
|
||||||
<div class="stats shadow w-full">
|
<div class="card-body">
|
||||||
<div class="stat">
|
<h2 class="card-title">Recommendations</h2>
|
||||||
<div class="stat-figure text-secondary">
|
<ol>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
<li>1. Turn on the notification of us.</li>
|
||||||
class="inline-block w-8 h-8 stroke-current">
|
<li>2. Download passport mobile application.</li>
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
<li>3. Add more factor to keep your account in safe.</li>
|
||||||
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
<li>4. Subscribe to Project Hydrogen to get following updates.</li>
|
||||||
</svg>
|
</ol>
|
||||||
</div>
|
|
||||||
<div class="stat-title">Challenges</div>
|
|
||||||
<div class="stat-value">{userinfo?.meta?.challenges?.length}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="stat">
|
|
||||||
<div class="stat-figure text-secondary">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
|
||||||
class="inline-block w-8 h-8 stroke-current">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"></path>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class="stat-title">Sessions</div>
|
|
||||||
<div class="stat-value">{userinfo?.meta?.sessions?.length}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="stat">
|
|
||||||
<div class="stat-figure text-secondary">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
|
||||||
class="inline-block w-8 h-8 stroke-current">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"></path>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class="stat-title">Events</div>
|
|
||||||
<div class="stat-value">{eventCount()}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="data-area" class="mt-5 shadow">
|
|
||||||
<div class="join join-vertical w-full">
|
|
||||||
|
|
||||||
<details class="collapse collapse-plus join-item border-b border-base-200">
|
|
||||||
<summary class="collapse-title text-lg font-medium">
|
|
||||||
Challenges
|
|
||||||
</summary>
|
|
||||||
<div class="collapse-content mx-[-16px]">
|
|
||||||
<div class="overflow-x-auto">
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th>State</th>
|
|
||||||
<th>IP Address</th>
|
|
||||||
<th>User Agent</th>
|
|
||||||
<th>Date</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<For each={userinfo?.meta?.challenges ?? []}>
|
|
||||||
{item => <tr>
|
|
||||||
<th>{item.id}</th>
|
|
||||||
<td>{item.state}</td>
|
|
||||||
<td>{item.ip_address}</td>
|
|
||||||
<td>
|
|
||||||
<span class="tooltip" data-tip={item.user_agent}>
|
|
||||||
{item.user_agent.substring(0, 10) + "..."}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>{new Date(item.created_at).toLocaleString()}</td>
|
|
||||||
</tr>}
|
|
||||||
</For>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details class="collapse collapse-plus join-item border-b border-base-200">
|
|
||||||
<summary class="collapse-title text-lg font-medium">
|
|
||||||
Sessions
|
|
||||||
</summary>
|
|
||||||
<div class="collapse-content mx-[-16px]">
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th>Third Client</th>
|
|
||||||
<th>Audiences</th>
|
|
||||||
<th>Date</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<For each={userinfo?.meta?.sessions ?? []}>
|
|
||||||
{item => <tr>
|
|
||||||
<th>{item.id}</th>
|
|
||||||
<td>{item.client_id ? "Linked" : "Non-linked"}</td>
|
|
||||||
<td>{item.audiences?.join(", ")}</td>
|
|
||||||
<td>{new Date(item.created_at).toLocaleString()}</td>
|
|
||||||
<td class="py-0">
|
|
||||||
<button class="btn btn-sm btn-square btn-error" disabled={submitting()}
|
|
||||||
onClick={() => killSession(item)}>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="h-5 w-5">
|
|
||||||
<path
|
|
||||||
d="M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208s208-93.31 208-208S370.69 48 256 48zm80 224H176a16 16 0 0 1 0-32h160a16 16 0 0 1 0 32z"
|
|
||||||
fill="currentColor"></path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>}
|
|
||||||
</For>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details class="collapse collapse-plus join-item">
|
|
||||||
<summary class="collapse-title text-lg font-medium">
|
|
||||||
Events
|
|
||||||
</summary>
|
|
||||||
<div class="collapse-content mx-[-16px]">
|
|
||||||
<div class="overflow-x-auto">
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th>Type</th>
|
|
||||||
<th>Target</th>
|
|
||||||
<th>IP Address</th>
|
|
||||||
<th>User Agent</th>
|
|
||||||
<th>Date</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<For each={events()}>
|
|
||||||
{item => <tr>
|
|
||||||
<th>{item.id}</th>
|
|
||||||
<td>{item.type}</td>
|
|
||||||
<td>{item.target}</td>
|
|
||||||
<td>{item.ip_address}</td>
|
|
||||||
<td>
|
|
||||||
<span class="tooltip" data-tip={item.user_agent}>
|
|
||||||
{item.user_agent.substring(0, 10) + "..."}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>{new Date(item.created_at).toLocaleString()}</td>
|
|
||||||
</tr>}
|
|
||||||
</For>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</details>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ export default function PersonalPage() {
|
|||||||
const [success, setSuccess] = createSignal<null | string>(null);
|
const [success, setSuccess] = createSignal<null | string>(null);
|
||||||
const [loading, setLoading] = createSignal(false);
|
const [loading, setLoading] = createSignal(false);
|
||||||
|
|
||||||
async function update(evt: SubmitEvent) {
|
async function updateBasis(evt: SubmitEvent) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
const data = Object.fromEntries(new FormData(evt.target as HTMLFormElement));
|
const data = Object.fromEntries(new FormData(evt.target as HTMLFormElement));
|
||||||
@ -33,43 +33,62 @@ export default function PersonalPage() {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateAvatar(evt: SubmitEvent) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
const data = new FormData(evt.target as HTMLFormElement);
|
||||||
|
const res = await fetch("/api/avatar", {
|
||||||
|
method: "PUT",
|
||||||
|
headers: { "Authorization": `Bearer ${getAtk()}` },
|
||||||
|
body: data
|
||||||
|
});
|
||||||
|
if (res.status !== 200) {
|
||||||
|
setSuccess(null);
|
||||||
|
setError(await res.text());
|
||||||
|
} else {
|
||||||
|
await readProfiles();
|
||||||
|
setSuccess("Your avatar has been update.");
|
||||||
|
setError(null);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="max-w-[720px] mx-auto px-5 pt-12">
|
<div class="max-w-[720px] mx-auto px-5 pt-12">
|
||||||
<div class="px-5">
|
<div class="px-5">
|
||||||
<h1 class="text-2xl font-bold">{userinfo?.displayName}</h1>
|
<h1 class="text-2xl font-bold">Personalize</h1>
|
||||||
<p>Joined at {new Date(userinfo?.meta?.created_at).toLocaleString()}</p>
|
<p>Customize your account and let us provide a better service to you.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow mt-5">
|
<div id="alerts">
|
||||||
<div class="card-body">
|
<Show when={error()}>
|
||||||
|
<div role="alert" class="alert alert-error mt-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||||
|
viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span class="capitalize">{error()}</span>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<Show when={error()}>
|
<Show when={success()}>
|
||||||
<div id="alerts">
|
<div role="alert" class="alert alert-success mt-3">
|
||||||
<div role="alert" class="alert alert-error">
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
viewBox="0 0 24 24">
|
||||||
viewBox="0 0 24 24">
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
</svg>
|
||||||
</svg>
|
<span class="capitalize">{success()}</span>
|
||||||
<span class="capitalize">{error()}</span>
|
</div>
|
||||||
</div>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
|
||||||
|
|
||||||
<Show when={success()}>
|
<div class="card shadow-xl mt-5">
|
||||||
<div id="alerts">
|
|
||||||
<div role="alert" class="alert alert-success">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
|
||||||
viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
<span class="capitalize">{success()}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Show>
|
|
||||||
|
|
||||||
<form class="grid grid-cols-1 gap-2" onSubmit={update}>
|
<div class="card-body border-b border-base-200">
|
||||||
|
<form class="grid grid-cols-1 gap-2" onSubmit={updateBasis}>
|
||||||
<label class="form-control w-full">
|
<label class="form-control w-full">
|
||||||
<div class="label">
|
<div class="label">
|
||||||
<span class="label-text">Username</span>
|
<span class="label-text">Username</span>
|
||||||
@ -107,7 +126,30 @@ export default function PersonalPage() {
|
|||||||
placeholder="Type here" class="input input-bordered w-full" />
|
placeholder="Type here" class="input input-bordered w-full" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary btn-block mt-5" disabled={loading()}>
|
|
||||||
|
<div>
|
||||||
|
<button type="submit" class="btn btn-primary mt-5" disabled={loading()}>
|
||||||
|
<Show when={loading()} fallback={"Save changes"}>
|
||||||
|
<span class="loading loading-spinner"></span>
|
||||||
|
</Show>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
<form onSubmit={updateAvatar}>
|
||||||
|
<label class="form-control w-full">
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text">Pick an avatar</span>
|
||||||
|
</div>
|
||||||
|
<input type="file" name="avatar" accept="image/*" class="file-input file-input-bordered w-full" />
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text-alt">Will took some time to apply to entire site</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary mt-5" disabled={loading()}>
|
||||||
<Show when={loading()} fallback={"Save changes"}>
|
<Show when={loading()} fallback={"Save changes"}>
|
||||||
<span class="loading loading-spinner"></span>
|
<span class="loading loading-spinner"></span>
|
||||||
</Show>
|
</Show>
|
||||||
|
223
pkg/view/src/pages/security.tsx
Normal file
223
pkg/view/src/pages/security.tsx
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
import { getAtk, readProfiles, useUserinfo } from "../stores/userinfo.tsx";
|
||||||
|
import { createSignal, For, Show } from "solid-js";
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
const userinfo = useUserinfo();
|
||||||
|
|
||||||
|
const [events, setEvents] = createSignal<any[]>([]);
|
||||||
|
const [eventCount, setEventCount] = createSignal(0);
|
||||||
|
|
||||||
|
const [error, setError] = createSignal<string | null>(null);
|
||||||
|
const [submitting, setSubmitting] = createSignal(false);
|
||||||
|
|
||||||
|
async function readEvents() {
|
||||||
|
const res = await fetch("/api/users/me/events?take=10", {
|
||||||
|
headers: { Authorization: `Bearer ${getAtk()}` }
|
||||||
|
});
|
||||||
|
if (res.status !== 200) {
|
||||||
|
setError(await res.text());
|
||||||
|
} else {
|
||||||
|
const data = await res.json();
|
||||||
|
setEvents(data["data"]);
|
||||||
|
setEventCount(data["count"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function killSession(item: any) {
|
||||||
|
setSubmitting(true);
|
||||||
|
const res = await fetch(`/api/users/me/sessions/${item.id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: { Authorization: `Bearer ${getAtk()}` }
|
||||||
|
});
|
||||||
|
if (res.status !== 200) {
|
||||||
|
setError(await res.text());
|
||||||
|
} else {
|
||||||
|
await readProfiles();
|
||||||
|
setError(null);
|
||||||
|
}
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
readEvents();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="max-w-[720px] mx-auto px-5 pt-12">
|
||||||
|
<div id="greeting" class="px-5">
|
||||||
|
<h1 class="text-2xl font-bold">Security</h1>
|
||||||
|
<p>Here is your account status of security.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="alerts">
|
||||||
|
<Show when={error()}>
|
||||||
|
<div role="alert" class="alert alert-error mt-5">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||||
|
viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span class="capitalize">{error()}</span>
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="overview" class="mt-5">
|
||||||
|
<div class="stats shadow w-full">
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-figure text-secondary">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
class="inline-block w-8 h-8 stroke-current">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="stat-title">Challenges</div>
|
||||||
|
<div class="stat-value">{userinfo?.meta?.challenges?.length}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-figure text-secondary">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
class="inline-block w-8 h-8 stroke-current">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="stat-title">Sessions</div>
|
||||||
|
<div class="stat-value">{userinfo?.meta?.sessions?.length}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-figure text-secondary">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||||
|
class="inline-block w-8 h-8 stroke-current">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="stat-title">Events</div>
|
||||||
|
<div class="stat-value">{eventCount()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="data-area" class="mt-5 shadow">
|
||||||
|
<div class="join join-vertical w-full">
|
||||||
|
|
||||||
|
<details class="collapse collapse-plus join-item border-b border-base-200">
|
||||||
|
<summary class="collapse-title text-lg font-medium">
|
||||||
|
Challenges
|
||||||
|
</summary>
|
||||||
|
<div class="collapse-content mx-[-16px]">
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>State</th>
|
||||||
|
<th>IP Address</th>
|
||||||
|
<th>User Agent</th>
|
||||||
|
<th>Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<For each={userinfo?.meta?.challenges ?? []}>
|
||||||
|
{item => <tr>
|
||||||
|
<th>{item.id}</th>
|
||||||
|
<td>{item.state}</td>
|
||||||
|
<td>{item.ip_address}</td>
|
||||||
|
<td>
|
||||||
|
<span class="tooltip" data-tip={item.user_agent}>
|
||||||
|
{item.user_agent.substring(0, 10) + "..."}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>{new Date(item.created_at).toLocaleString()}</td>
|
||||||
|
</tr>}
|
||||||
|
</For>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details class="collapse collapse-plus join-item border-b border-base-200">
|
||||||
|
<summary class="collapse-title text-lg font-medium">
|
||||||
|
Sessions
|
||||||
|
</summary>
|
||||||
|
<div class="collapse-content mx-[-16px]">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Third Client</th>
|
||||||
|
<th>Audiences</th>
|
||||||
|
<th>Date</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<For each={userinfo?.meta?.sessions ?? []}>
|
||||||
|
{item => <tr>
|
||||||
|
<th>{item.id}</th>
|
||||||
|
<td>{item.client_id ? "Linked" : "Non-linked"}</td>
|
||||||
|
<td>{item.audiences?.join(", ")}</td>
|
||||||
|
<td>{new Date(item.created_at).toLocaleString()}</td>
|
||||||
|
<td class="py-0">
|
||||||
|
<button class="btn btn-sm btn-square btn-error" disabled={submitting()}
|
||||||
|
onClick={() => killSession(item)}>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="h-5 w-5">
|
||||||
|
<path
|
||||||
|
d="M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208s208-93.31 208-208S370.69 48 256 48zm80 224H176a16 16 0 0 1 0-32h160a16 16 0 0 1 0 32z"
|
||||||
|
fill="currentColor"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>}
|
||||||
|
</For>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details class="collapse collapse-plus join-item">
|
||||||
|
<summary class="collapse-title text-lg font-medium">
|
||||||
|
Events
|
||||||
|
</summary>
|
||||||
|
<div class="collapse-content mx-[-16px]">
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Target</th>
|
||||||
|
<th>IP Address</th>
|
||||||
|
<th>User Agent</th>
|
||||||
|
<th>Date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<For each={events()}>
|
||||||
|
{item => <tr>
|
||||||
|
<th>{item.id}</th>
|
||||||
|
<td>{item.type}</td>
|
||||||
|
<td>{item.target}</td>
|
||||||
|
<td>{item.ip_address}</td>
|
||||||
|
<td>
|
||||||
|
<span class="tooltip" data-tip={item.user_agent}>
|
||||||
|
{item.user_agent.substring(0, 10) + "..."}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>{new Date(item.created_at).toLocaleString()}</td>
|
||||||
|
</tr>}
|
||||||
|
</For>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@ -7,6 +7,8 @@ bind = "0.0.0.0:8444"
|
|||||||
domain = "id.smartsheep.studio"
|
domain = "id.smartsheep.studio"
|
||||||
secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
|
secret = "LtTjzAGFLshwXhN4ZD4nG5KlMv1MWcsvfv03TSZYnT1VhiAnLIZFTnHUwR0XhGgi"
|
||||||
|
|
||||||
|
content = "uploads"
|
||||||
|
|
||||||
use_registration_magic_token = true
|
use_registration_magic_token = true
|
||||||
|
|
||||||
[mailer]
|
[mailer]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user