switched to vibe.d 0.8.1-rc2 and added @safe and friends where possible
This commit is contained in:
parent
3d59043261
commit
e510c2bacf
5 changed files with 22 additions and 21 deletions
5
dub.json
5
dub.json
|
@ -4,13 +4,14 @@
|
||||||
"Johannes Loher"
|
"Johannes Loher"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vibe-d": "~>0.8.0",
|
"vibe-d": "0.8.1-rc.2",
|
||||||
"poodinis": "~>8.0.0"
|
"poodinis": "~>8.0.0"
|
||||||
},
|
},
|
||||||
"description": "A simple webapplication to edit and view calendar entries",
|
"description": "A simple webapplication to edit and view calendar entries",
|
||||||
"copyright": "Copyright © 2017, Johannes Loher",
|
"copyright": "Copyright © 2017, Johannes Loher",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"versions": [
|
"versions": [
|
||||||
"VibeDefaultMain"
|
"VibeDefaultMain",
|
||||||
|
"VibeUseOpenSSL11"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ import vibe.db.mongo.client : MongoClient;
|
||||||
|
|
||||||
interface Authenticator
|
interface Authenticator
|
||||||
{
|
{
|
||||||
bool checkUser(string username, string password);
|
bool checkUser(string username, string password) @safe;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MongoDBAuthenticator : Authenticator
|
class MongoDBAuthenticator : Authenticator
|
||||||
|
@ -22,7 +22,7 @@ private:
|
||||||
string usersCollectionName;
|
string usersCollectionName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool checkUser(string username, string password)
|
bool checkUser(string username, string password) @safe
|
||||||
{
|
{
|
||||||
auto users = mongoClient.getCollection(databaseName ~ "." ~ usersCollectionName);
|
auto users = mongoClient.getCollection(databaseName ~ "." ~ usersCollectionName);
|
||||||
auto result = users.findOne(["username" : username, "password" : password]);
|
auto result = users.findOne(["username" : username, "password" : password]);
|
||||||
|
|
|
@ -26,7 +26,7 @@ import vibe.web.web : errorDisplay, noRoute, redirect, render, SessionVar,
|
||||||
{
|
{
|
||||||
if (!req.session || !req.session.isKeySet("auth"))
|
if (!req.session || !req.session.isKeySet("auth"))
|
||||||
{
|
{
|
||||||
() @trusted{ redirect("/login"); }();
|
redirect("/login");
|
||||||
return AuthInfo.init;
|
return AuthInfo.init;
|
||||||
}
|
}
|
||||||
return req.session.get!AuthInfo("auth");
|
return req.session.get!AuthInfo("auth");
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
render!("login.dt", _error);
|
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");
|
enforce(authenticator.checkUser(username, password), "Benutzername oder Passwort ungültig");
|
||||||
immutable AuthInfo authInfo = {username};
|
immutable AuthInfo authInfo = {username};
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@anyAuth void getLogout()
|
@anyAuth void getLogout() @safe
|
||||||
{
|
{
|
||||||
terminateSession();
|
terminateSession();
|
||||||
redirect("/");
|
redirect("/");
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
@anyAuth @errorDisplay!getCreate void postCreate(Date begin,
|
@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;
|
import std.array : replace, split;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@anyAuth void postRemove(BsonObjectID id)
|
@anyAuth void postRemove(BsonObjectID id) @safe
|
||||||
{
|
{
|
||||||
eventStore.removeEvent(id);
|
eventStore.removeEvent(id);
|
||||||
redirect("/");
|
redirect("/");
|
||||||
|
|
|
@ -8,7 +8,7 @@ private:
|
||||||
string[string] config;
|
string[string] config;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
this()
|
this() const @safe pure nothrow
|
||||||
{
|
{
|
||||||
// dfmt off
|
// dfmt off
|
||||||
config = ["Database name" : "CalendarWebapp",
|
config = ["Database name" : "CalendarWebapp",
|
||||||
|
@ -17,7 +17,7 @@ public:
|
||||||
// dfmt on
|
// dfmt on
|
||||||
}
|
}
|
||||||
|
|
||||||
string get(string key)
|
string get(string key) const @safe pure nothrow
|
||||||
{
|
{
|
||||||
return config[key];
|
return config[key];
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,29 +13,29 @@ import vibe.db.mongo.client : MongoClient;
|
||||||
|
|
||||||
interface EventStore
|
interface EventStore
|
||||||
{
|
{
|
||||||
Event getEvent(BsonObjectID id);
|
Event getEvent(BsonObjectID id) @safe;
|
||||||
InputRange!Event getAllEvents();
|
InputRange!Event getAllEvents() @safe;
|
||||||
void addEvent(Event);
|
void addEvent(Event) @safe;
|
||||||
InputRange!Event getEventsBeginningBetween(Date begin, Date end);
|
InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe;
|
||||||
void removeEvent(BsonObjectID id);
|
void removeEvent(BsonObjectID id) @safe;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MongoDBEventStore : EventStore
|
class MongoDBEventStore : EventStore
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Event getEvent(BsonObjectID id)
|
Event getEvent(BsonObjectID id) @safe
|
||||||
{
|
{
|
||||||
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
||||||
.findOne(["_id" : id]).deserializeBson!Event;
|
.findOne(["_id" : id]).deserializeBson!Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputRange!Event getAllEvents()
|
InputRange!Event getAllEvents() @safe
|
||||||
{
|
{
|
||||||
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
||||||
.find().map!(deserializeBson!Event).inputRangeObject;
|
.find().map!(deserializeBson!Event).inputRangeObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEvent(Event event)
|
void addEvent(Event event) @safe
|
||||||
{
|
{
|
||||||
if (!event.id.valid)
|
if (!event.id.valid)
|
||||||
event.id = BsonObjectID.generate;
|
event.id = BsonObjectID.generate;
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
.insert(event.serializeToBson);
|
.insert(event.serializeToBson);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputRange!Event getEventsBeginningBetween(Date begin, Date end)
|
InputRange!Event getEventsBeginningBetween(Date begin, Date end) @safe
|
||||||
{
|
{
|
||||||
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
return mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName)
|
||||||
.find(["$and" : [["date" : ["$gte" : begin.serializeToBson]], ["date"
|
.find(["$and" : [["date" : ["$gte" : begin.serializeToBson]], ["date"
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
.inputRangeObject;
|
.inputRangeObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeEvent(BsonObjectID id)
|
void removeEvent(BsonObjectID id) @safe
|
||||||
{
|
{
|
||||||
mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName).remove(["_id" : id]);
|
mongoClient.getCollection(databaseName ~ "." ~ entriesCollectionName).remove(["_id" : id]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue