-
Notifications
You must be signed in to change notification settings - Fork 4
/
profile.go
44 lines (36 loc) · 912 Bytes
/
profile.go
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
// Content managed by Project Forge, see [projectforge.md] for details.
package user
import (
"fmt"
)
type Profile struct {
Name string `json:"name"`
Mode string `json:"mode,omitempty"`
Theme string `json:"theme,omitempty"`
}
var DefaultProfile = &Profile{Name: "Guest"}
func (p *Profile) String() string {
return p.Name
}
func (p *Profile) Clone() *Profile {
return &Profile{Name: p.Name, Mode: p.Mode, Theme: p.Theme}
}
func (p *Profile) ModeClass() string {
if p.Mode == "" {
return ""
}
return "mode-" + p.Mode
}
func (p *Profile) AuthString(a Accounts) string {
msg := fmt.Sprintf("signed in as %s", p.String())
if len(a) == 0 {
if p.Name == DefaultProfile.Name {
return "click to sign in"
}
return msg
}
return fmt.Sprintf("%s using [%s]", msg, a.String())
}
func (p *Profile) Equals(x *Profile) bool {
return p.Name == x.Name && p.Mode == x.Mode && p.Theme == x.Theme
}