aboutsummaryrefslogtreecommitdiff
path: root/views/layouts.templ
blob: 3db6f1b93d3565c35ce1be1026705f50c8adb853 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package views

import (
	"context"
	"gitrepo.ru/neonxp/gorum/contextlib"
	"gitrepo.ru/neonxp/gorum/models"
)

templ Layout() {
	<!DOCTYPE html>
	<html lang="ru">
		<head>
			<meta charset="utf-8"/>
			<meta name="viewport" content="width=device-width, initial-scale=1"/>
			<meta name="color-scheme" content="light dark"/>
			<link rel="stylesheet" href={ "/assets/css/pico." + ctx.Value(contextlib.ThemeKey).(string) + ".min.css" }/>
			<link rel="stylesheet" href="/assets/css/style.css" />
			<title>Gorum</title>
		</head>
		<body>
			<nav class="container-fluid">
				<ul>
					<li>
						<strong>Gorum BBS</strong>
					</li>
					<li>
						<a href="/">Список тем</a>
					</li>
				</ul>
				<ul>
					if isAuthorized(ctx) {
						// <li><a href="/topic/new">Новая тема</a></li>
						<li>{ getUser(ctx).Username }</li>
						<li><form action="/logout" method="POST"><input type="submit" value="Выход"/></form></li>
					} else {
						<li><a href="/login">Вход</a></li>
						<li><a href="/register">Регистрация</a></li>
					}
				</ul>
			</nav>
			<main class="container">
				{ children... }
			</main>
			<footer class="container-fluid">
				<small>Работает на <a href="https://gorum.tech/">Gorum</a>.</small>
			</footer>
		</body>
	</html>
}

func isAuthorized(ctx context.Context) bool {
	_, authorized := ctx.Value(contextlib.UserKey).(models.User)
	return authorized
}
func getUser(ctx context.Context) models.User {
	return ctx.Value(contextlib.UserKey).(models.User)
}