switched to vibe.d 0.8.1-rc2 and added @safe and friends where possible

This commit is contained in:
Johannes Loher 2017-08-12 22:46:51 +02:00
parent 3d59043261
commit e510c2bacf
5 changed files with 22 additions and 21 deletions

View file

@ -4,13 +4,14 @@
"Johannes Loher"
],
"dependencies": {
"vibe-d": "~>0.8.0",
"vibe-d": "0.8.1-rc.2",
"poodinis": "~>8.0.0"
},
"description": "A simple webapplication to edit and view calendar entries",
"copyright": "Copyright © 2017, Johannes Loher",
"license": "MIT",
"versions": [
"VibeDefaultMain"
"VibeDefaultMain",
"VibeUseOpenSSL11"
]
}

View file

@ -7,7 +7,7 @@ import vibe.db.mongo.client : MongoClient;
interface Authenticator
{
bool checkUser(string username, string password);
bool checkUser(string username, string password) @safe;
}
class MongoDBAuthenticator : Authenticator
@ -22,7 +22,7 @@ private:
string usersCollectionName;
public:
bool checkUser(string username, string password)
bool checkUser(string username, string password) @safe
{
auto users = mongoClient.getCollection(databaseName ~ "." ~ usersCollectionName);
auto result = users.findOne(["username" : username, "password" : password]);

View file

@ -26,7 +26,7 @@ import vibe.web.web : errorDisplay, noRoute, redirect, render, SessionVar,
{
if (!req.session || !req.session.isKeySet("auth"))
{
() @trusted{ redirect("/login"); }();
redirect("/login");
return AuthInfo.init;
}
return req.session.get!AuthInfo("auth");
@ -44,7 +44,7 @@ public:
render!("login.dt", _error);
}
@noAuth @errorDisplay!getLogin void postLogin(string username, string password)
@noAuth @errorDisplay!getLogin void postLogin(string username, string password) @safe
{
enforce(authenticator.checkUser(username, password), "Benutzername oder Passwort ungültig");
immutable AuthInfo authInfo = {username};
@ -52,7 +52,7 @@ public:
redirect("/");
}
@anyAuth void getLogout()
@anyAuth void getLogout() @safe
{
terminateSession();
redirect("/");
@ -64,7 +64,7 @@ public:
}
@anyAuth @errorDisplay!getCreate void postCreate(Date begin,
Nullable!Date end, string description, string name, EventType type, bool shout)
Nullable!Date end, string description, string name, EventType type, bool shout) @safe
{
import std.array : replace, split;
@ -79,7 +79,7 @@ public:
redirect("/");
}
@anyAuth void postRemove(BsonObjectID id)
@anyAuth void postRemove(BsonObjectID id) @safe
{
eventStore.removeEvent(id);
redirect("/");

View file

@ -8,7 +8,7 @@ private:
string[string] config;
public:
this()
this() const @safe pure nothrow
{
// dfmt off
config = ["Database name" : "CalendarWebapp",
@ -17,7 +17,7 @@ public:
// dfmt on
}
string get(string key)
string get(string key) const @safe pure nothrow
{
return config[key];
}

View file

@ -13,29 +13,29 @@ import vibe.db.mongo.client : MongoClient;
interface EventStore
{
Event getEvent(BsonObjectID id);
InputRange!Event getAllEvents();
void addEvent(Event);
InputRange!Event getEventsBeginningBetween(Date begin, Date end);
void removeEvent(BsonObjectID id);
Event getEvent(BsonObjectID id) @safe;
InputRange!Event getAllEvents() @safe;
void addEvent(Event) @safe;
InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe;
void removeEvent(BsonObjectID id) @safe;
}
class MongoDBEventStore : EventStore
{
public:
Event getEvent(BsonObjectID id)
Event getEvent(BsonObjectID id) @safe
{
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
.findOne(["_id" : id]).deserializeBson!Event;
}
InputRange!Event getAllEvents()
InputRange!Event getAllEvents() @safe
{
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
.find().map!(deserializeBson!Event).inputRangeObject;
}
void addEvent(Event event)
void addEvent(Event event) @safe
{
if (!event.id.valid)
event.id = BsonObjectID.generate;
@ -44,7 +44,7 @@ public:
.insert(event.serializeToBson);
}
InputRange!Event getEventsBeginningBetween(Date begin, Date end)
InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe
{
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
.find(["$and" : [["date" : ["$gte" : begin.serializeToBson]], ["date"
@ -52,7 +52,7 @@ public:
.inputRangeObject;
}
void removeEvent(BsonObjectID id)
void removeEvent(BsonObjectID id) @safe
{
mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName).remove(["_id" : id]);
}