1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.controllers.attributes;
7
8 import diamond.core.apptype;
9
10 static if (isWeb)
11 {
12 import diamond.http.method;
13
14 /// Attribute for default http actions.
15 struct HttpDefault {}
16
17 /// Attribute for mandatory http actions.
18 struct HttpMandatory {}
19
20 /// Attribute for http actions.
21 struct HttpAction
22 {
23 /// The http method of the action.
24 HttpMethod method;
25
26 /// The name of the action. Equivalent to /route/{action}
27 string action;
28 }
29
30 /// Attribute for a no-action handler.
31 struct HttpNoAction {}
32
33 /// Attribute for authentication.
34 struct HttpAuthentication
35 {
36 /// The class to use for authentcation. It must implement IControllerAuth.
37 string authenticationClass;
38 }
39
40 /// Attribute for restricting controller actions to the restricted ips.
41 struct HttpRestricted {}
42
43 /// Attribute for disabling authentication.
44 struct HttpDisableAuth { }
45
46 /// Attribute for version-control.
47 struct HttpVersion
48 {
49 /// The version name.
50 string versionName;
51
52 /// The controller to use for the version.
53 string versionControllerClass;
54 }
55
56 static if (isWebApi)
57 {
58 /// Attribute for declaring routes.
59 struct HttpRoutes
60 {
61 /// The routes.
62 string[] routes;
63
64 /**
65 * Creates a new http routes attribute.
66 * Params:
67 * route = The route.
68 */
69 this(string route)
70 {
71 routes = [route];
72 }
73
74 /**
75 * Creates a new http routes attribute.
76 * Params:
77 * routes = The routes.
78 */
79 this(string[] routes)
80 {
81 this.routes = routes;
82 }
83
84 /// Dsiabling the regular struct constructor.
85 @disable this();
86 }
87 }
88
89 /// Attribute for retrieving controller data from the form body.
90 struct HttpForm { }
91
92 /// Attribute for retrieving controller data from the query string.
93 struct HttpQuery { }
94
95 /// Attribute for sanitizing html tags from inputs by replacing them with their > and <
96 struct HttpSanitize { }
97 }