1 module vibeauth.router.registration.responses; 2 3 import std.stdio; 4 import std.datetime; 5 import std..string; 6 import std.uri; 7 import std.file; 8 9 import vibe.http.router; 10 import vibe.data.json; 11 12 import vibeauth.users; 13 import vibeauth.configuration; 14 import vibeauth.challenges.base; 15 import vibeauth.mail.base; 16 import vibeauth.router.accesscontrol; 17 import vibeauth.router.registration.routes; 18 import vibeauth.router.request; 19 import vibeauth.mvc.templatedata; 20 import vibeauth.mvc.view; 21 22 class RegistrationResponses { 23 24 private { 25 IChallenge challenge; 26 const { 27 ServiceConfiguration configuration; 28 } 29 } 30 31 this(IChallenge challenge, const ServiceConfiguration configuration) { 32 this.challenge = challenge; 33 this.configuration = configuration; 34 } 35 36 void registerForm(HTTPServerRequest req, HTTPServerResponse res) { 37 scope view = new RegisterView(configuration); 38 39 Json variables = Json.emptyObject; 40 variables["challenge"] = challenge.getTemplate(configuration.paths.registration.challange); 41 variables["userData"] = (const RequestUserData(req)).toJson; 42 43 if(variables["userData"]["error"].type == Json.Type..string && variables["userData"]["error"] != "") { 44 view.data.addError(variables["userData"]["error"].to!string); 45 } 46 47 view.data.add(variables); 48 49 res.writeBody(view.render, "text/html"); 50 } 51 52 void confirmationForm(HTTPServerRequest, HTTPServerResponse res) { 53 scope view = new ConfirmationView(configuration); 54 55 res.statusCode = 200; 56 res.writeBody(view.render, "text/html"); 57 } 58 59 void success(HTTPServerRequest, HTTPServerResponse res) { 60 scope view = new SuccessView(configuration); 61 62 res.statusCode = 200; 63 res.writeBody(view.render, "text/html"); 64 } 65 } 66 67 alias RegisterView = BasicView!( 68 "templates.registration.formTemplate", 69 "templates.registration.form" 70 ); 71 72 alias ConfirmationView = BasicView!( 73 "templates.registration.confirmationTemplate", 74 "templates.registration.confirmation" 75 ); 76 77 alias SuccessView = BasicView!( 78 "templates.registration.successTemplate", 79 "templates.registration.success" 80 );