0.1.11 96c369e

tokeninit.go RawHistoryFolder

1package server
2
3import (
4	"crypto/rand"
5	"encoding/hex"
6	"fmt"
7)
8
9// HandleNewInitialization checks if there is ANY user in the database.
10func HandleNewTokenInitialization(a *App) (string, error) {
11	// Check if there is any user in the database
12	query := "SELECT COUNT(*) FROM user"
13	var count int
14	err := a.DB.QueryRow(query).Scan(&count)
15	if err != nil {
16		return "", fmt.Errorf("failed to check for admin user: %v", err)
17	}
18
19	// If count is greater than 0, it means there is at least one user in the database
20	if count > 0 {
21		return "", fmt.Errorf("user already present, skipping token initialization")
22	}
23
24	// If we reach here, it means admin does not exist, so we generate a token
25	token, err := generateRandomToken(16) // 16 bytes
26	if err != nil {
27		return "", fmt.Errorf("failed to generate token: %v", err)
28	}
29
30	// url = config.Http.SubDomain + config.Http.TopDomain + config.Http.Port + config.Admin.Path
31
32	fmt.Printf("Login with the new token: %s\n", token)
33
34	// Store the token in the config file
35	a.Config.General.Token = token
36	err = a.Config.SaveConfig()
37	if err != nil {
38		return "", fmt.Errorf("failed to save config: %v", err)
39	}
40	return token, nil
41}
42
43// generateRandomToken generates a random token of the given byte length
44func generateRandomToken(length int) (string, error) {
45	bytes := make([]byte, length)
46	if _, err := rand.Read(bytes); err != nil {
47		return "", err
48	}
49	return hex.EncodeToString(bytes), nil
50}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close