1 module diskuto.userstore;
2 
3 import std.typecons : Nullable;
4 import vibe.http.server : HTTPServerRequest;
5 
6 
7 interface DiskutoUserStore {
8 @safe nothrow:
9 	Nullable!StoredUser getLoggedInUser(HTTPServerRequest req);
10 	Nullable!StoredUser getUserForEmail(string email);
11 
12 	/** Returns the role of a particular user for the given topic.
13 
14 		Note that this method must accept unknown user IDs. Typical return
15 		values in this case are `UserRole.user` or `UserRole.banned` (to
16 		enable posting for registered users only).
17 
18 		Params:
19 			user = ID of the user to query
20 			topic = The topic for which to query the role
21 	*/
22 	StoredUser.Role getUserRole(StoredUser.ID user, string topic);
23 }
24 
25 struct StoredUser {
26 	enum Role {
27 		none,      /// not allowed to read or post
28 		reader,    /// can only read posts
29 		commenter, /// can only comment, but not vote
30 		member,    /// can comment and vote (default if no user store is defined)
31 		moderator  /// can also modify foreign comments
32 	}
33 
34 	alias ID = string;
35 
36 	ID id; // store specific ID prefixed with a store identifier (e.g. "userman-mongodb-12315235234")
37 	string name; // Display name
38 	string email; // e-mail address
39 	string website; // website URL
40 }
41 
42 deprecated("Use StoredUser.Role instead.")
43 alias UserRole = StoredUser.Role;