-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.go
More file actions
76 lines (56 loc) · 3.04 KB
/
user.go
File metadata and controls
76 lines (56 loc) · 3.04 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
package faroe
import "errors"
type UserStruct struct {
// A unique ID.
Id string
// A unique email address.
EmailAddress string
PasswordHash []byte
PasswordSalt []byte
PasswordHashAlgorithmId string
Disabled bool
// An empty string if not defined.
DisplayName string
EmailAddressCounter int32
PasswordHashCounter int32
DisabledCounter int32
SessionsCounter int32
}
type UserStoreInterface interface {
// Creates a new user. The email address should be stored as-is, with the casing preserved.
// The email address counter, password hash counter, disabled counter, and sessions counter should be set to 0.
// Returns the created user if successful.
// Returns [ErrUserStoreUserEmailAddressAlreadyUsed] if the email address is already tied to another user.
// An error is returned for any other failure.
CreateUser(emailAddress string, passwordHash []byte, passwordHashAlgorithmId string, passwordSalt []byte) (UserStruct, error)
// Gets a user.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist.
// An error is returned for any other failure.
GetUser(userId string) (UserStruct, error)
// Gets a user by email address.
// The email address must match exactly, including letter casing.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist.
// An error is returned for any other failure.
GetUserByEmailAddress(emailAddress string) (UserStruct, error)
// Updates a user's email address and increment a user's email address counter if the email address counter matches.
// The new email address should be stored as-is, with the casing preserved.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist or the user's email address counter doesn't match.
// Returns [ErrUserStoreUserEmailAddressAlreadyUsed] if the email address is already tied to another user.
// An error is returned for any other failure.
UpdateUserEmailAddress(userId string, emailAddress string, userEmailAddressCounter int32) error
// Updates a user's password hash, password hash algorithm ID, and password salt,
// as well as increment a user's email address counter, if the user password hash counter matches.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist or the user's password hash counter doesn't match.
// An error is returned for any other failure.
UpdateUserPasswordHash(userId string, passwordHash []byte, passwordHashAlgorithmId string, passwordSalt []byte, userPasswordHashCounter int32) error
// Increments a user's sessions counter if the user's sessions counter matches.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist or the user's sessions counter doesn't match.
// An error is returned for any other failure.
IncrementUserSessionsCounter(userId string, userSessionsCounter int32) error
// Deletes a user.
// Returns [ErrUserStoreUserNotFound] if a user doesn't exist.
// An error is returned for any other failure.
DeleteUser(userId string) error
}
var ErrUserStoreUserNotFound = errors.New("user not found")
var ErrUserStoreUserEmailAddressAlreadyUsed = errors.New("user email address already used")