diff --git a/.travis.yml b/.travis.yml index 5134844..b6727a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,11 @@ language: d d: + - dmd-2.080.0 - dmd-2.078.1 - dmd-2.077.1 - ldc-1.7.0 + - ldc-1.9.0 os: - linux env: diff --git a/dub.json b/dub.json index 8d4902e..e52cf87 100644 --- a/dub.json +++ b/dub.json @@ -6,10 +6,11 @@ ], "dependencies": { "dauth": "~>0.6.3", - "mysql-native": "~>1.1.4", - "vibe-d": "~>0.8.2", - "vibe-d:tls": "~>0.8.2", - "poodinis": "~>8.0.1" + "mysql-native": "~>2.2.2", + "vibe-d": "~>0.8.3", + "vibe-d:tls": "~>0.8.3", + "diet-ng": "~>1.4.5", + "poodinis": "~>8.0.2" }, "subConfigurations": { "vibe-d:tls": "openssl-1.1" @@ -19,6 +20,9 @@ "license": "MIT", "targetType": "executable", "targetPath": "generated", + "versions": [ + "DietUseCache" + ], "configurations": [ { "name": "executable" @@ -31,9 +35,8 @@ "excludedSourceFiles": ["source/fsicalmanagement/app.d"], "sourcePaths": ["test"], "dependencies": { - "unit-threaded": "~>0.7.38" - }, - "versions": ["unitUnthreaded"] + "unit-threaded": "~>0.7.45" + } } ] } diff --git a/dub.selections.json b/dub.selections.json index 066a25a..5041350 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -4,17 +4,18 @@ "botan": "1.12.9", "botan-math": "1.0.3", "dauth": "0.6.3", - "diet-ng": "1.4.4", - "eventcore": "0.8.27", + "diet-ng": "1.4.5", + "eventcore": "0.8.34", "libasync": "0.8.3", "libevent": "2.0.2+2.0.16", "memutils": "0.4.10", - "mysql-native": "1.1.4", + "mysql-native": "2.2.2", "openssl": "1.1.6+1.0.1g", - "poodinis": "8.0.1", - "taggedalgebraic": "0.10.9", - "unit-threaded": "0.7.38", - "vibe-core": "1.3.0", - "vibe-d": "0.8.2" + "poodinis": "8.0.2", + "stdx-allocator": "2.77.1", + "taggedalgebraic": "0.10.11", + "unit-threaded": "0.7.45", + "vibe-core": "1.4.0", + "vibe-d": "0.8.3" } } diff --git a/source/fsicalmanagement/authenticator.d b/source/fsicalmanagement/authenticator.d index 19d31f0..58a5572 100644 --- a/source/fsicalmanagement/authenticator.d +++ b/source/fsicalmanagement/authenticator.d @@ -66,7 +66,7 @@ public: InputRange!AuthInfo getAllUsers() @safe { import std.algorithm : map; - import std.range : inputRangeObject; + import std.range.interfaces : inputRangeObject; return users.find().map!(deserializeBson!AuthInfo).inputRangeObject; } @@ -87,7 +87,7 @@ enum Privilege class MySQLAuthenticator : Authenticator { private: - import mysql : MySQLPool, Row, prepare; + import mysql : MySQLPool, Row, prepare, exec, query; @Autowire MySQLPool pool; @Autowire PasswordHasher passwordHasher; @@ -105,7 +105,7 @@ public: "SELECT id, username, passwordHash, privilege FROM " ~ usersTableName ~ " WHERE username = ?"); prepared.setArg(0, username); - auto result = prepared.query(); + auto result = cn.query(prepared); if (!result.empty) { auto authInfo = toAuthInfo(result.front); @@ -123,21 +123,24 @@ public: scope (exit) cn.close; auto prepared = cn.prepare( - "INSERT INTO " ~ usersTableName ~ " (username, passwordHash, privilege) VALUES(?, ?, ?)"); + "INSERT INTO " ~ usersTableName + ~ " (username, passwordHash, privilege) VALUES(?, ?, ?)"); prepared.setArgs(authInfo.username, authInfo.passwordHash, authInfo.privilege.to!uint); - prepared.exec(); + cn.exec(prepared); } InputRange!AuthInfo getAllUsers() { import std.algorithm : map; - import std.range : inputRangeObject; + import std.array : array; + import std.range.interfaces : inputRangeObject; auto cn = pool.lockConnection(); scope (exit) cn.close; - auto prepared = cn.prepare("SELECT id, username, passwordHash, privilege FROM " ~ usersTableName ~ ""); - return prepared.querySet.map!(r => toAuthInfo(r)).inputRangeObject; + auto prepared = cn.prepare( + "SELECT id, username, passwordHash, privilege FROM " ~ usersTableName); + return cn.query(prepared).array.map!(r => toAuthInfo(r)).inputRangeObject; } void removeUser(string id) @@ -147,7 +150,7 @@ public: cn.close; auto prepared = cn.prepare("DELETE FROM " ~ usersTableName ~ " WHERE id = ?"); prepared.setArg(0, id.to!uint); - prepared.exec(); + cn.exec(prepared); } private: diff --git a/source/fsicalmanagement/event.d b/source/fsicalmanagement/event.d index 9bd63a2..0600af9 100644 --- a/source/fsicalmanagement/event.d +++ b/source/fsicalmanagement/event.d @@ -70,7 +70,7 @@ private: class MySQLEventStore : EventStore { private: - import mysql : MySQLPool, prepare, Row; + import mysql : MySQLPool, prepare, Row, query, exec; @Value("mysql.table.events") string eventsTableName; @@ -81,19 +81,22 @@ public: scope (exit) cn.close; auto prepared = cn.prepare( - "SELECT id begin end name description type shout FROM " ~ eventsTableName ~ " WHERE id = ?"); + "SELECT id begin end name description type shout FROM " + ~ eventsTableName ~ " WHERE id = ?"); prepared.setArg(0, id.to!uint); - return toEvent(prepared.query.front); + return cn.query(prepared).front.toEvent; } InputRange!Event getAllEvents() { + import std.array : array; + auto cn = pool.lockConnection(); scope (exit) cn.close; auto prepared = cn.prepare( - "SELECT id, begin, end, name, description, type, shout FROM " ~ eventsTableName ~ ""); - return prepared.querySet.map!(r => toEvent(r)).inputRangeObject; + "SELECT id, begin, end, name, description, type, shout FROM " ~ eventsTableName); + return cn.query(prepared).array.map!(r => toEvent(r)).inputRangeObject; } void addEvent(Event event) @@ -101,12 +104,11 @@ public: auto cn = pool.lockConnection(); scope (exit) cn.close; - auto prepared = cn.prepare( - "INSERT INTO " ~ eventsTableName ~ " (begin, end, name, description, type, shout)" - ~ " VALUES(?, ?, ?, ?, ?, ?)"); + auto prepared = cn.prepare("INSERT INTO " ~ eventsTableName + ~ " (begin, end, name, description, type, shout)" ~ " VALUES(?, ?, ?, ?, ?, ?)"); prepared.setArgs(event.begin, event.end, event.name, event.description, event.type.to!uint, event.shout); - prepared.exec(); + cn.exec(prepared); } /* InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe @@ -123,25 +125,27 @@ public: cn.close; auto prepared = cn.prepare("DELETE FROM " ~ eventsTableName ~ " WHERE id = ?"); prepared.setArg(0, id.to!uint); - prepared.exec(); + cn.exec(prepared); } private: @Autowire MySQLPool pool; +} - Event toEvent(Row r) - { - Event event; - event.id = r[0].get!uint.to!string; - event.begin = r[1].get!Date; - if (r[2].hasValue) - event.end = r[2].get!Date; - event.name = r[3].get!string; - event.description = r[4].get!string; - event.type = r[5].get!uint.to!EventType; - event.shout = r[6].get!byte.to!bool; - return event; - } +import mysql : Row; + +Event toEvent(Row r) +{ + Event event; + event.id = r[0].get!uint.to!string; + event.begin = r[1].get!Date; + if (r[2].type != typeid(typeof(null))) + event.end = r[2].get!Date; + event.name = r[3].get!string; + event.description = r[4].get!string; + event.type = r[5].get!uint.to!EventType; + event.shout = r[6].get!byte.to!bool; + return event; } enum EventType @@ -155,7 +159,8 @@ enum EventType struct Event { - import std.typecons: Nullable; + import std.typecons : Nullable; + @serializationName("_id") string id; @serializationName("date") Date begin; @serializationName("end_date") Nullable!Date end; diff --git a/source/fsicalmanagement/fsicalmanagement.d b/source/fsicalmanagement/fsicalmanagement.d index ec97cc5..e30ed0f 100644 --- a/source/fsicalmanagement/fsicalmanagement.d +++ b/source/fsicalmanagement/fsicalmanagement.d @@ -19,6 +19,7 @@ import vibe.web.web; @requiresAuth class FsicalManagement { import vibe.http.server : HTTPServerRequest; + @noRoute AuthInfo authenticate(scope HTTPServerRequest, scope HTTPServerResponse) @safe { if (authInfo.value.isNone) diff --git a/views/showevents.dt b/views/showevents.dt index 59e2b5c..de8d62b 100644 --- a/views/showevents.dt +++ b/views/showevents.dt @@ -1,30 +1,25 @@ extends layout.dt block content h1 Events - - foreach (event; events) - table + table + tr + th begin + th end + th _id + th name + th desc + th etype + th shout + - foreach (event; events) tr - td begin td #{event.begin} - tr - td end td #{event.end} - tr - td _id td #{event.id} - tr - td name td #{event.name} - tr - td desc td.pre #{event.description} - tr - td etype td #{event.type} - tr - td shout td #{event.shout} - form(action="/removeevent", method="post") - input#id(value="#{event.id}", name="id", type="hidden") - input#submitButton(type="submit", value="Entfernen") - hr + td + form(action="/removeevent", method="post") + input#id(value="#{event.id}", name="id", type="hidden") + input#submitButton(type="submit", value="Entfernen") diff --git a/views/showusers.dt b/views/showusers.dt index 739d133..0f34d75 100644 --- a/views/showusers.dt +++ b/views/showusers.dt @@ -1,20 +1,19 @@ extends layout.dt block content h1 Users - - foreach (user; users) - table + table + tr + th id + th username + th privilege + - foreach (user; users) tr - td id td #{user.id} - tr - td username td #{user.username} - tr - td privilege td #{user.privilege} - form(action="/removeuser", method="post") - input#id(value="#{user.id}", name="id", type="hidden") - input#submitButton(type="submit", value="Entfernen") - hr + td + form(action="/removeuser", method="post") + input#id(value="#{user.id}", name="id", type="hidden") + input#submitButton(type="submit", value="Entfernen") - if (_error) p.error= _error