D Web Development by Kai Nacke

D Web Development by Kai Nacke

Author:Kai Nacke [Nacke, Kai]
Language: eng
Format: epub, pdf
Publisher: Packt Publishing
Published: 2016-01-29T23:00:00+00:00


Every method that requires an authenticated user can now be annotated with @before!ensureAuth("_authUser"). This is a lot to type. Therefore, you define a shortcut:private enum auth = before!ensureAuth("_authUser");

The methods can now be annotated with @auth. Do not forget to add a string _authUser parameter, too:void index(string _error = null) { render!("index.dt", _error); } @errorDisplay!index void postLogin(string username, string password) { import std.uuid : randomUUID; enforce(username == "yourid" && password == "secret", "Invalid username / password"); UserData d; d.loggedIn = true; d.name = username; d.uuid = randomUUID.toString; user = d; redirect("/listnotes"); } @auth void getListnotes(string _authUser) { auto allnotes = noteStore.getNotes(user.uuid); render!("listnotes.dt", allnotes); } @method(HTTPMethod.GET) void logout() { user = UserData.init; terminateSession(); redirect("/"); } @auth void getNoteEntry(string _authUser, ValidationErrorData _error = ValidationErrorData.init) { render!("create.dt", _error); } @auth @errorDisplay!getNoteEntry void createNewNote(string _authUser, ValidTopic form_topic, string form_content) { Note note; note.topic = form_topic; note.content = form_content; auto allnotes = noteStore.getNotes(user.uuid); allnotes ~= note; noteStore.setNotes(user.uuid, allnotes); redirect("/listnotes"); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.