1 /++
2   A module that handles the user management. It binds the routes, renders the templates and 
3   updates the collections.
4 
5   Copyright: © 2018 Szabo Bogdan
6   License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
7   Authors: Szabo Bogdan
8 +/
9 module vibeauth.router.management.routes;
10 
11 import vibe.http.router;
12 import vibe.data.json;
13 
14 import vibeauth.users;  
15 import vibeauth.collection;
16 import vibeauth.configuration;
17 import vibeauth.mail.base;
18 import vibeauth.router.management.responses;
19 import vibeauth.mvc.view;
20 import vibeauth.mvc.controller;
21 
22 import std..string;
23 import std.algorithm;
24 import std.conv;
25 import std.regex;
26 
27 /// It handles vibe.d requests
28 class UserManagementRoutes {
29   private {
30     UserCollection userCollection;
31     ServiceConfiguration configuration;
32 
33     IMailQueue mailQueue;
34 
35     IController[] controllers;
36   }
37 
38   /// Initalize the object
39   this(UserCollection userCollection, IMailQueue mailQueue, ServiceConfiguration configuration = ServiceConfiguration.init) {
40     this.configuration = configuration;
41     this.userCollection = userCollection;
42     this.mailQueue = mailQueue;
43 
44     controllers = cast(IController[]) [
45       new ListController(userCollection, configuration),
46 
47       new ProfileController(userCollection, configuration),
48       new UpdateProfileController(userCollection, configuration),
49 
50       new AccountController(userCollection, configuration),
51       new UpdateAccountController(userCollection, configuration),
52 
53       new DeleteAccountController(userCollection, configuration),
54 
55       new SecurityController(userCollection, configuration),
56       new RevokeAdminController(userCollection, configuration),
57       new MakeAdminController(userCollection, configuration)
58     ];
59   }
60 
61   /// Generic handler for all user management routes
62   void handler(HTTPServerRequest req, HTTPServerResponse res) {
63     foreach(controller; controllers) {
64       if(controller.canHandle(req)) {
65         controller.handle(req, res);
66         return;
67       }
68     }
69   }
70 }