forked from xyproto/simplemaria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
96 lines (87 loc) · 2.69 KB
/
interface.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
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
package db
import "net/http"
// Database interfaces
type IList interface {
Add(value string) error
GetAll() ([]string, error)
GetLast() (string, error)
GetLastN(n int) ([]string, error)
Remove() error
Clear() error
}
type ISet interface {
Add(value string) error
Has(value string) (bool, error)
GetAll() ([]string, error)
Del(value string) error
Remove() error
Clear() error
}
type IHashMap interface {
Set(owner, key, value string) error
Get(owner, key string) (string, error)
Has(owner, key string) (bool, error)
Exists(owner string) (bool, error)
GetAll() ([]string, error)
DelKey(owner, key string) error
Del(key string) error
Remove() error
Clear() error
}
type IKeyValue interface {
Set(key, value string) error
Get(key string) (string, error)
Del(key string) error
Remove() error
Clear() error
}
// Interface for making it possible to depend on different versions of the permission package, or other packages that implement userstates.
type IUserState interface {
UserRights(req *http.Request) bool
HasUser(username string) bool
BooleanField(username, fieldname string) bool
SetBooleanField(username, fieldname string, val bool)
IsConfirmed(username string) bool
IsLoggedIn(username string) bool
AdminRights(req *http.Request) bool
IsAdmin(username string) bool
UsernameCookie(req *http.Request) (string, error)
SetUsernameCookie(w http.ResponseWriter, username string) error
AllUsernames() ([]string, error)
Email(username string) (string, error)
PasswordHash(username string) (string, error)
AllUnconfirmedUsernames() ([]string, error)
ConfirmationCode(username string) (string, error)
AddUnconfirmed(username, confirmationCode string)
RemoveUnconfirmed(username string)
MarkConfirmed(username string)
RemoveUser(username string)
SetAdminStatus(username string)
RemoveAdminStatus(username string)
AddUser(username, password, email string)
SetLoggedIn(username string)
SetLoggedOut(username string)
Login(w http.ResponseWriter, username string)
Logout(username string)
Username(req *http.Request) string
CookieTimeout(username string) int64
SetCookieTimeout(cookieTime int64)
PasswordAlgo() string
SetPasswordAlgo(algorithm string) error
HashPassword(username, password string) string
CorrectPassword(username, password string) bool
AlreadyHasConfirmationCode(confirmationCode string) bool
FindUserByConfirmationCode(confirmationcode string) (string, error)
Confirm(username string)
ConfirmUserByConfirmationCode(confirmationcode string) error
SetMinimumConfirmationCodeLength(length int)
GenerateUniqueConfirmationCode() (string, error)
// Related to the database backend
Users() IHashMap
Host() IHost
}
// A database host
type IHost interface {
Ping() error
Close()
}