-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount_creation.go
More file actions
114 lines (103 loc) · 2.81 KB
/
account_creation.go
File metadata and controls
114 lines (103 loc) · 2.81 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"crypto/sha256"
"fmt"
"maps"
"strings"
"time"
"github.com/google/uuid"
)
type AccountCreateInput struct {
Username Username
Password string
Email string
System System
Provider string
RequestIP string
RequestOrigin string
ExtraSys map[string]any
}
func createAccount(in AccountCreateInput) (User, error) {
usernameLower := in.Username.ToLower()
if usernameLower == "" {
return nil, fmt.Errorf("username is required")
}
if in.Email == "" {
return nil, fmt.Errorf("email is required")
}
if in.System.Name == "" {
return nil, fmt.Errorf("system is required")
}
usersMutex.Lock()
defer usersMutex.Unlock()
for _, user := range users {
if user.GetUsername().ToLower() == usernameLower {
return nil, fmt.Errorf("username already in use")
}
if strings.EqualFold(user.GetEmail(), in.Email) {
return nil, fmt.Errorf("email already in use")
}
}
hash := fmt.Sprintf("%x", sha256.Sum256([]byte(in.RequestIP)))
provider := in.Provider
if provider == "" {
provider = "unknown"
}
origin := in.RequestOrigin
if origin == "" {
origin = "unknown"
}
go sendDiscordWebhook([]map[string]any{
{
"title": "New Account Registered",
"description": fmt.Sprintf("**Username:** %s\n**Email:** %s\n**System:** %s\n**Provider:** %s\n**IP:** %s\n**Host:** %s",
in.Username, in.Email, in.System.Name, provider, hash, origin),
"color": 0x57cdac,
"timestamp": time.Now().Format(time.RFC3339),
},
})
newUser := User{
"username": in.Username,
"pfp": "https://avatars.rotur.dev/" + usernameLower,
"password": in.Password,
"email": in.Email,
"key": generateAccountToken(),
"system": in.System.Name,
"max_size": 5000000,
"sys.last_login": time.Now().UnixMilli(),
"sys.total_logins": 0,
"sys.friends": []string{},
"sys.requests": []string{},
"sys.links": []map[string]any{},
"sys.currency": float64(0),
"sys.transactions": []any{},
"sys.items": []any{},
"sys.badges": []string{},
"sys.purchases": []any{},
"private": false,
"sys.id": uuid.New().String(),
"theme": map[string]any{
"primary": "#222",
"secondary": "#555",
"tertiary": "#777",
"text": "#fff",
"background": "#050505",
"accent": "#57cdac",
},
"onboot": []string{
"Origin/(A) System/System Apps/originWM.osl",
"Origin/(A) System/System Apps/Desktop.osl",
"Origin/(A) System/Docks/Dock.osl",
"Origin/(A) System/System Apps/Quick_Settings.osl",
},
"created": time.Now().UnixMilli(),
"wallpaper": in.System.Wallpaper,
"sys.tos_accepted": false,
}
if in.ExtraSys != nil {
maps.Copy(newUser, in.ExtraSys)
}
users = append(users, newUser)
go saveUsers()
return newUser, nil
}